Skip to content

Commit a28e428

Browse files
committed
Use the same layout mechanism as the detector in buttons
1 parent ae9f92c commit a28e428

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

packages/react-native-gesture-handler/shared/shadowNodes/react/renderer/components/rngesturehandler_codegen/RNGestureHandlerButtonWrapperShadowNode.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ void RNGestureHandlerButtonWrapperShadowNode::appendChild(
4949

5050
void RNGestureHandlerButtonWrapperShadowNode::layout(
5151
LayoutContext layoutContext) {
52-
YogaLayoutableShadowNode::layout(layoutContext);
5352
react_native_assert(getChildren().size() == 1);
5453
react_native_assert(getChildren()[0]->getChildren().size() == 1);
5554

@@ -58,16 +57,37 @@ void RNGestureHandlerButtonWrapperShadowNode::layout(
5857
auto grandChild = std::static_pointer_cast<const YogaLayoutableShadowNode>(
5958
child->getChildren()[0]);
6059

60+
auto gradChildWithProtectedAccess =
61+
std::static_pointer_cast<const RNGestureHandlerButtonWrapperShadowNode>(
62+
grandChild);
63+
64+
auto shouldSkipCustomLayout =
65+
!gradChildWithProtectedAccess->yogaNode_.getHasNewLayout();
66+
67+
YogaLayoutableShadowNode::layout(layoutContext);
68+
6169
child->ensureUnsealed();
6270
grandChild->ensureUnsealed();
6371

6472
auto mutableChild = std::const_pointer_cast<YogaLayoutableShadowNode>(child);
6573
auto mutableGrandChild =
6674
std::const_pointer_cast<YogaLayoutableShadowNode>(grandChild);
6775

68-
// TODO: figure out the correct way to setup metrics between button wrapper
69-
// and the child
76+
// The grand child node did not have its layout changed, we can reuse previous
77+
// values
78+
if (shouldSkipCustomLayout) {
79+
react_native_assert(previousGrandChildLayoutMetrics_.has_value());
80+
mutableChild->setLayoutMetrics(previousGrandChildLayoutMetrics_.value());
81+
82+
auto metricsNoOrigin = previousGrandChildLayoutMetrics_.value();
83+
metricsNoOrigin.frame.origin = Point{};
84+
mutableGrandChild->setLayoutMetrics(metricsNoOrigin);
85+
return;
86+
}
87+
7088
auto metrics = grandChild->getLayoutMetrics();
89+
previousGrandChildLayoutMetrics_ = metrics;
90+
7191
mutableChild->setLayoutMetrics(metrics);
7292

7393
auto metricsNoOrigin = grandChild->getLayoutMetrics();

packages/react-native-gesture-handler/shared/shadowNodes/react/renderer/components/rngesturehandler_codegen/RNGestureHandlerButtonWrapperShadowNode.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ class RNGestureHandlerButtonWrapperShadowNode final
3434
const ShadowNode &sourceShadowNode,
3535
const ShadowNodeFragment &fragment)
3636
: ConcreteViewShadowNode(sourceShadowNode, fragment) {
37+
const auto &sourceWrapperNode =
38+
static_cast<const RNGestureHandlerButtonWrapperShadowNode &>(
39+
sourceShadowNode);
40+
previousGrandChildLayoutMetrics_ =
41+
sourceWrapperNode.previousGrandChildLayoutMetrics_;
42+
3743
initialize();
3844
}
3945

@@ -43,6 +49,8 @@ class RNGestureHandlerButtonWrapperShadowNode final
4349
private:
4450
void initialize();
4551
void prepareChildren();
52+
53+
std::optional<LayoutMetrics> previousGrandChildLayoutMetrics_;
4654
};
4755

4856
} // namespace facebook::react

0 commit comments

Comments
 (0)