Skip to content

Commit d17ecca

Browse files
zeyapmeta-codesync[bot]
authored andcommitted
Measure node instance during applyViewTransitionName (#56153)
Summary: Pull Request resolved: #56153 ## Changelog: [General] [Changed] - Measure node instance during applyViewTransitionName measureInstance config function in react reconciler is not specifically for notifying runtime to measure old/new instance. this change generally will not affect current behavior because `applyViewTransitionName` is invoked right after `measureInstance` on the same instance. Reviewed By: christophpurrer Differential Revision: D97192977 fbshipit-source-id: 711cbb153e9e58e372b7e1a1dde3cd5f6da7bd27
1 parent a357676 commit d17ecca

4 files changed

Lines changed: 10 additions & 30 deletions

File tree

packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -940,11 +940,6 @@ jsi::Value UIManagerBinding::get(
940940
result.setProperty(runtime, "width", domRect.width);
941941
result.setProperty(runtime, "height", domRect.height);
942942

943-
auto* viewTransitionDelegate = uiManager->getViewTransitionDelegate();
944-
if (viewTransitionDelegate != nullptr) {
945-
viewTransitionDelegate->captureLayoutMetricsFromRoot(*shadowNode);
946-
}
947-
948943
return result;
949944
});
950945
}

packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerViewTransitionDelegate.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ class UIManagerViewTransitionDelegate {
2727

2828
virtual void restoreViewTransitionName(const ShadowNode &shadowNode) {}
2929

30-
virtual void captureLayoutMetricsFromRoot(const ShadowNode &shadowNode) {}
31-
3230
virtual void startViewTransition(
3331
std::function<void()> mutationCallback,
3432
std::function<void()> onReadyCallback,

packages/react-native/ReactCommon/react/renderer/viewtransition/ViewTransitionModule.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,11 @@ void ViewTransitionModule::applyViewTransitionName(
2525
auto tag = shadowNode.getTag();
2626
auto surfaceId = shadowNode.getSurfaceId();
2727

28-
// Look up the captured layout metrics for this shadowNode
29-
auto metricsIt = capturedLayoutMetricsFromRoot_.find(tag);
30-
if (metricsIt == capturedLayoutMetricsFromRoot_.end()) {
31-
// No measurement captured yet, nothing to do
28+
auto layoutMetrics = captureLayoutMetricsFromRoot(shadowNode);
29+
if (layoutMetrics == EmptyLayoutMetrics) {
3230
return;
3331
}
3432

35-
const auto& layoutMetrics = metricsIt->second;
36-
3733
// Convert LayoutMetrics to AnimationKeyFrameViewLayoutMetrics
3834
AnimationKeyFrameViewLayoutMetrics keyframeMetrics{
3935
.originFromRoot = layoutMetrics.frame.origin,
@@ -54,8 +50,6 @@ void ViewTransitionModule::applyViewTransitionName(
5450
.layoutMetrics = keyframeMetrics, .tag = tag, .surfaceId = surfaceId};
5551
newLayout_[name] = newView;
5652
}
57-
58-
capturedLayoutMetricsFromRoot_.erase(tag);
5953
}
6054

6155
void ViewTransitionModule::cancelViewTransitionName(
@@ -73,10 +67,10 @@ void ViewTransitionModule::restoreViewTransitionName(
7367
cancelledNameRegistry_.erase(shadowNode.getTag());
7468
}
7569

76-
void ViewTransitionModule::captureLayoutMetricsFromRoot(
70+
LayoutMetrics ViewTransitionModule::captureLayoutMetricsFromRoot(
7771
const ShadowNode& shadowNode) {
7872
if (uiManager_ == nullptr) {
79-
return;
73+
return EmptyLayoutMetrics;
8074
}
8175

8276
// Get the current revision (root node) for this surface
@@ -85,22 +79,18 @@ void ViewTransitionModule::captureLayoutMetricsFromRoot(
8579
shadowNode.getSurfaceId());
8680

8781
if (currentRevision == nullptr) {
88-
return;
82+
return EmptyLayoutMetrics;
8983
}
9084

9185
// Cast root to LayoutableShadowNode
9286
auto layoutableRoot =
9387
dynamic_cast<const LayoutableShadowNode*>(currentRevision.get());
9488
if (layoutableRoot == nullptr) {
95-
return;
89+
return EmptyLayoutMetrics;
9690
}
9791

98-
// Compute layout metrics from root
99-
auto layoutMetrics = LayoutableShadowNode::computeLayoutMetricsFromRoot(
92+
return LayoutableShadowNode::computeLayoutMetricsFromRoot(
10093
shadowNode.getFamily(), *layoutableRoot, {});
101-
102-
// Store the layout metrics keyed by tag
103-
capturedLayoutMetricsFromRoot_[shadowNode.getTag()] = layoutMetrics;
10494
}
10595

10696
void ViewTransitionModule::startViewTransition(
@@ -110,7 +100,7 @@ void ViewTransitionModule::startViewTransition(
110100
// Mark transition as started
111101
transitionStarted_ = true;
112102

113-
// Call mutation callback (including commitRoot, measureInstance,
103+
// Call mutation callback (including commitRoot, measureInstance
114104
// applyViewTransitionName for old & new)
115105
if (mutationCallback) {
116106
mutationCallback();

packages/react-native/ReactCommon/react/renderer/viewtransition/ViewTransitionModule.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class ViewTransitionModule : public UIManagerViewTransitionDelegate {
3636
// restore cancellation
3737
void restoreViewTransitionName(const ShadowNode &shadowNode) override;
3838

39-
void captureLayoutMetricsFromRoot(const ShadowNode &shadowNode) override;
40-
4139
void startViewTransition(
4240
std::function<void()> mutationCallback,
4341
std::function<void()> onReadyCallback,
@@ -65,9 +63,6 @@ class ViewTransitionModule : public UIManagerViewTransitionDelegate {
6563
// registry of layout of old/new views
6664
std::unordered_map<std::string, AnimationKeyFrameView> oldLayout_{};
6765
std::unordered_map<std::string, AnimationKeyFrameView> newLayout_{};
68-
// temporary registry of measured layout metrics keyed by tag
69-
std::unordered_map<Tag, LayoutMetrics> capturedLayoutMetricsFromRoot_{};
70-
7166
// tag -> names registry, populated during applyViewTransitionName
7267
// Note that tag and name are not 1:1 mapping
7368
// - In some nested composition 2 names are mappped to the same tag
@@ -77,6 +72,8 @@ class ViewTransitionModule : public UIManagerViewTransitionDelegate {
7772
// used for cancel/restore viewTransitionName
7873
std::unordered_map<Tag, std::unordered_set<std::string>> cancelledNameRegistry_{};
7974

75+
LayoutMetrics captureLayoutMetricsFromRoot(const ShadowNode &shadowNode);
76+
8077
UIManager *uiManager_{nullptr};
8178

8279
bool transitionStarted_{false};

0 commit comments

Comments
 (0)