Skip to content

Commit 768d2c6

Browse files
authored
feat: rn 78 new arch support (#29)
1 parent 4e6e076 commit 768d2c6

3 files changed

Lines changed: 21 additions & 22 deletions

File tree

packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void LayoutAnimationsProxy::parseRemoveMutations(
153153
if (mutation.type == ShadowViewMutation::Remove) {
154154
updateIndexForMutation(mutation);
155155
auto tag = mutation.oldChildShadowView.tag;
156-
auto parentTag = mutation.parentShadowView.tag;
156+
auto parentTag = mutation.parentTag;
157157
auto unflattenedParentTag = parentTag; // temporary
158158

159159
std::shared_ptr<MutationNode> mutationNode;
@@ -287,8 +287,8 @@ void LayoutAnimationsProxy::handleUpdatesAndEnterings(
287287
}
288288
case ShadowViewMutation::Type::Insert: {
289289
updateIndexForMutation(mutation);
290-
if (nodeForTag_.contains(mutation.parentShadowView.tag)) {
291-
nodeForTag_[mutation.parentShadowView.tag]->applyMutationToIndices(
290+
if (nodeForTag_.contains(mutation.parentTag)) {
291+
nodeForTag_[mutation.parentTag]->applyMutationToIndices(
292292
mutation);
293293
}
294294

@@ -297,7 +297,7 @@ void LayoutAnimationsProxy::handleUpdatesAndEnterings(
297297
if (layoutAnimationIt == layoutAnimations_.end()) {
298298
if (oldShadowViewsForReparentings.contains(tag)) {
299299
filteredMutations.push_back(ShadowViewMutation::InsertMutation(
300-
mutation.parentShadowView,
300+
mutation.parentTag,
301301
oldShadowViewsForReparentings[tag],
302302
mutation.index));
303303
} else {
@@ -308,7 +308,7 @@ void LayoutAnimationsProxy::handleUpdatesAndEnterings(
308308

309309
auto oldView = *layoutAnimationIt->second.currentView;
310310
filteredMutations.push_back(ShadowViewMutation::InsertMutation(
311-
mutation.parentShadowView, oldView, mutation.index));
311+
mutation.parentTag, oldView, mutation.index));
312312
continue;
313313
}
314314

@@ -328,7 +328,7 @@ void LayoutAnimationsProxy::handleUpdatesAndEnterings(
328328
cloneViewWithoutOpacity(mutation, propsParserContext);
329329

330330
filteredMutations.push_back(ShadowViewMutation::UpdateMutation(
331-
mutation.newChildShadowView, *newView, mutation.parentShadowView));
331+
mutation.newChildShadowView, *newView, mutation.parentTag));
332332
break;
333333
}
334334

@@ -386,7 +386,7 @@ void LayoutAnimationsProxy::addOngoingAnimations(
386386
updateLayoutMetrics(newView->layoutMetrics, updateValues.frame);
387387

388388
mutations.push_back(ShadowViewMutation::UpdateMutation(
389-
*layoutAnimation.currentView, *newView, *layoutAnimation.parentView));
389+
*layoutAnimation.currentView, *newView, layoutAnimation.parentTag));
390390
layoutAnimation.currentView = newView;
391391
}
392392
updateMap.clear();
@@ -556,11 +556,11 @@ void LayoutAnimationsProxy::updateIndexForMutation(
556556
if (mutation.index == -1) {
557557
return;
558558
}
559-
if (!nodeForTag_.contains(mutation.parentShadowView.tag)) {
559+
if (!nodeForTag_.contains(mutation.parentTag)) {
560560
return;
561561
}
562562

563-
auto parent = nodeForTag_[mutation.parentShadowView.tag];
563+
auto parent = nodeForTag_[mutation.parentTag];
564564

565565
int size = 0, prevIndex = -1, offset = 0;
566566

@@ -577,7 +577,7 @@ void LayoutAnimationsProxy::updateIndexForMutation(
577577
? mutation.newChildShadowView.tag
578578
: mutation.oldChildShadowView.tag;
579579
LOG(INFO) << "update index for " << tag << " in "
580-
<< mutation.parentShadowView.tag << ": " << mutation.index << " -> "
580+
<< mutation.parentTag << ": " << mutation.index << " -> "
581581
<< mutation.index + offset << std::endl;
582582
#endif
583583
mutation.index += offset;
@@ -606,9 +606,8 @@ void LayoutAnimationsProxy::createLayoutAnimation(
606606
? mutation.oldChildShadowView
607607
: mutation.newChildShadowView);
608608
auto currentView = std::make_shared<ShadowView>(oldView);
609-
auto parentView = std::make_shared<ShadowView>(mutation.parentShadowView);
610609
layoutAnimations_.insert_or_assign(
611-
tag, LayoutAnimation{finalView, currentView, parentView, {}, count});
610+
tag, LayoutAnimation{finalView, currentView, mutation.parentTag, {}, count});
612611
}
613612

614613
void LayoutAnimationsProxy::startEnteringAnimation(
@@ -619,19 +618,18 @@ void LayoutAnimationsProxy::startEnteringAnimation(
619618
#endif
620619
auto finalView = std::make_shared<ShadowView>(mutation.newChildShadowView);
621620
auto current = std::make_shared<ShadowView>(mutation.newChildShadowView);
622-
auto parent = std::make_shared<ShadowView>(mutation.parentShadowView);
623621

624622
auto &viewProps =
625623
static_cast<const ViewProps &>(*mutation.newChildShadowView.props);
626624
auto opacity = viewProps.opacity;
627625

628626
uiScheduler_->scheduleOnUI(
629-
[finalView, current, parent, mutation, opacity, this, tag]() {
627+
[finalView, current, mutation, opacity, this, tag]() {
630628
Rect window{};
631629
{
632630
auto lock = std::unique_lock<std::recursive_mutex>(mutex);
633631
layoutAnimations_.insert_or_assign(
634-
tag, LayoutAnimation{finalView, current, parent, opacity});
632+
tag, LayoutAnimation{finalView, current, mutation.parentTag, opacity});
635633
window =
636634
surfaceManager.getWindow(mutation.newChildShadowView.surfaceId);
637635
}
@@ -784,13 +782,13 @@ void LayoutAnimationsProxy::maybeRestoreOpacity(
784782
void LayoutAnimationsProxy::maybeUpdateWindowDimensions(
785783
facebook::react::ShadowViewMutation &mutation,
786784
SurfaceId surfaceId) const {
787-
// This is a hacky way to obtain the window dimensions.
788-
// We can identify the root, by checking if its tag is equal to the surfaceId
789-
if (mutation.parentShadowView.tag == surfaceId) {
785+
if (mutation.type == ShadowViewMutation::Update &&
786+
!std::strcmp(
787+
mutation.oldChildShadowView.componentName, RootComponentName)) {
790788
surfaceManager.updateWindow(
791789
surfaceId,
792-
mutation.parentShadowView.layoutMetrics.frame.size.width,
793-
mutation.parentShadowView.layoutMetrics.frame.size.height);
790+
mutation.newChildShadowView.layoutMetrics.frame.size.width,
791+
mutation.newChildShadowView.layoutMetrics.frame.size.height);
794792
}
795793
}
796794

packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class NativeReanimatedModule;
2424
using namespace facebook;
2525

2626
struct LayoutAnimation {
27-
std::shared_ptr<ShadowView> finalView, currentView, parentView;
27+
std::shared_ptr<ShadowView> finalView, currentView;
28+
Tag parentTag;
2829
std::optional<double> opacity;
2930
int count = 1;
3031
LayoutAnimation &operator=(const LayoutAnimation &other) = default;

packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Rect SurfaceManager::getWindow(SurfaceId surfaceId) {
3131
}
3232

3333
void Node::applyMutationToIndices(ShadowViewMutation mutation) {
34-
if (tag != mutation.parentShadowView.tag) {
34+
if (tag != mutation.parentTag) {
3535
return;
3636
}
3737

0 commit comments

Comments
 (0)