Skip to content

Commit 1e4ebf2

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Disable calculation of TransformedFrames in Layoutable ShadowNodex
Summary: Calculation of TransformedFrames was a method introduced by D37994809 (64528e5) to fix rendering of inverted flat lists. We found that this operation is crashing in fb4a causing the UBN T127619309 This diff creates a feature flag to disable the calculation of TransformedFrames in Layoutable ShadowNodes. **The goal of this diff is to revert the behavior introduced by D37994809 (64528e5faa445907b8287b412c344f30c20fca61)** The featureFlag is disabled in fb4a and enabled in react AR (because ReactAr apps relies on the calculation of TransformedFrames and these apps are not affected) The root cause of the bug will be fixed by D38280674 (which still requires more testing and investigation) changelog: [internal] internal Reviewed By: JoshuaGross Differential Revision: D38286857 fbshipit-source-id: 721cd0554ae6a6b369b3f8dbb584160a270d0f18
1 parent a21a1f8 commit 1e4ebf2

File tree

6 files changed

+66
-3
lines changed

6 files changed

+66
-3
lines changed

ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public class ReactFeatureFlags {
8383
/** Enables or disables MapBuffer Serialization */
8484
public static boolean mapBufferSerializationEnabled = false;
8585

86+
/** Enables or disables calculation of Transformed Frames */
87+
public static boolean calculateTransformedFramesEnabled = false;
88+
8689
/** Feature Flag to use overflowInset values provided by Yoga */
8790
public static boolean useOverflowInset = false;
8891

ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,10 @@ void Binding::installFabricUIManager(
434434
"MapBufferSerializationEnabled",
435435
getFeatureFlagValue("mapBufferSerializationEnabled"));
436436

437+
contextContainer->insert(
438+
"CalculateTransformedFramesEnabled",
439+
getFeatureFlagValue("calculateTransformedFramesEnabled"));
440+
437441
disablePreallocateViews_ = reactNativeConfig_->getBool(
438442
"react_fabric:disabled_view_preallocation_android");
439443

ReactCommon/react/renderer/core/LayoutableShadowNode.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,21 @@ LayoutMetrics LayoutableShadowNode::computeRelativeLayoutMetrics(
151151
}
152152

153153
// ------------------------------
154-
155-
auto transformedFrames = calculateTransformedFrames(shadowNodeList, policy);
154+
// TODO: T127619309 remove after validating that T127619309 is fixed
155+
auto optionalCalculateTransformedFrames =
156+
descendantNode->getContextContainer()
157+
? descendantNode->getContextContainer()->find<bool>(
158+
"CalculateTransformedFramesEnabled")
159+
: std::optional<bool>(false);
160+
161+
bool shouldCalculateTransformedFrames =
162+
optionalCalculateTransformedFrames.has_value()
163+
? optionalCalculateTransformedFrames.value()
164+
: false;
165+
166+
auto transformedFrames = shouldCalculateTransformedFrames
167+
? calculateTransformedFrames(shadowNodeList, policy)
168+
: LayoutableSmallVector<Rect>();
156169
auto layoutMetrics = descendantLayoutableNode->getLayoutMetrics();
157170
auto &resultFrame = layoutMetrics.frame;
158171
resultFrame.origin = {0, 0};
@@ -168,7 +181,9 @@ LayoutMetrics LayoutableShadowNode::computeRelativeLayoutMetrics(
168181
return EmptyLayoutMetrics;
169182
}
170183

171-
auto currentFrame = transformedFrames[i];
184+
auto currentFrame = shouldCalculateTransformedFrames
185+
? transformedFrames[i]
186+
: currentShadowNode->getLayoutMetrics().frame;
172187
if (i == size - 1) {
173188
// If it's the last element, its origin is irrelevant.
174189
currentFrame.origin = {0, 0};
@@ -185,6 +200,10 @@ LayoutMetrics LayoutableShadowNode::computeRelativeLayoutMetrics(
185200
}
186201

187202
resultFrame.origin += currentFrame.origin;
203+
if (!shouldCalculateTransformedFrames && i != 0 &&
204+
policy.includeTransform) {
205+
resultFrame.origin += currentShadowNode->getContentOriginOffset();
206+
}
188207
}
189208

190209
// ------------------------------

ReactCommon/react/renderer/core/ShadowNode.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ ShadowNode::Unshared ShadowNode::clone(
121121
return family_->componentDescriptor_.cloneShadowNode(*this, fragment);
122122
}
123123

124+
ContextContainer::Shared ShadowNode::getContextContainer() const {
125+
return family_->componentDescriptor_.getContextContainer();
126+
}
127+
124128
#pragma mark - Getters
125129

126130
ComponentName ShadowNode::getComponentName() const {

ReactCommon/react/renderer/core/ShadowNode.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ class ShadowNode : public Sealable, public DebugStringConvertible {
129129
*/
130130
const ComponentDescriptor &getComponentDescriptor() const;
131131

132+
/*
133+
* Returns the `ContextContainer` used by this ShadowNode.
134+
*/
135+
ContextContainer::Shared getContextContainer() const;
136+
132137
/*
133138
* Returns a state associated with the particular node.
134139
*/

ReactCommon/react/renderer/core/tests/LayoutableShadowNodeTest.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
using namespace facebook::react;
1515

16+
// TODO: T127619309 re-enable CalculateTransformedFrames
17+
bool enableCalculateTransformedFrames = false;
18+
1619
/*
1720
* ┌────────┐
1821
* │<View> │
@@ -450,6 +453,11 @@ TEST(LayoutableShadowNodeTest, invertedVerticalView) {
450453
auto builder = simpleComponentBuilder();
451454
auto childShadowNode1 = std::shared_ptr<ViewShadowNode>{};
452455
auto childShadowNode2 = std::shared_ptr<ViewShadowNode>{};
456+
457+
if (!enableCalculateTransformedFrames) {
458+
return;
459+
}
460+
453461
// clang-format off
454462
auto element =
455463
Element<ViewShadowNode>()
@@ -525,6 +533,11 @@ TEST(LayoutableShadowNodeTest, nestedInvertedVerticalView) {
525533
auto builder = simpleComponentBuilder();
526534
auto childShadowNode1 = std::shared_ptr<ViewShadowNode>{};
527535
auto childShadowNode2 = std::shared_ptr<ViewShadowNode>{};
536+
537+
if (!enableCalculateTransformedFrames) {
538+
return;
539+
}
540+
528541
// clang-format off
529542
auto element =
530543
Element<ViewShadowNode>()
@@ -601,6 +614,11 @@ TEST(LayoutableShadowNodeTest, invertedHorizontalView) {
601614
auto builder = simpleComponentBuilder();
602615
auto childShadowNode1 = std::shared_ptr<ViewShadowNode>{};
603616
auto childShadowNode2 = std::shared_ptr<ViewShadowNode>{};
617+
618+
if (!enableCalculateTransformedFrames) {
619+
return;
620+
}
621+
604622
// clang-format off
605623
auto element =
606624
Element<ViewShadowNode>()
@@ -672,6 +690,11 @@ TEST(LayoutableShadowNodeTest, nestedInvertedHorizontalView) {
672690
auto builder = simpleComponentBuilder();
673691
auto childShadowNode1 = std::shared_ptr<ViewShadowNode>{};
674692
auto childShadowNode2 = std::shared_ptr<ViewShadowNode>{};
693+
694+
if (!enableCalculateTransformedFrames) {
695+
return;
696+
}
697+
675698
// clang-format off
676699
auto element =
677700
Element<ViewShadowNode>()
@@ -738,6 +761,11 @@ TEST(LayoutableShadowNodeTest, inversedContentOriginOffset) {
738761
auto builder = simpleComponentBuilder();
739762

740763
auto childShadowNode = std::shared_ptr<ViewShadowNode>{};
764+
765+
if (!enableCalculateTransformedFrames) {
766+
return;
767+
}
768+
741769
// clang-format off
742770
auto element =
743771
Element<ScrollViewShadowNode>()

0 commit comments

Comments
 (0)