Skip to content

Commit 06aab22

Browse files
authored
[Native] Fix ButtonWrapper Shadow Node custom layout logic (#3974)
## Description After #3634 the Pressable did not work on iOS. The reason lied in the shadow node of the button wrapper introduced in aforementioned PR which took the layout of the button and instead of changing its own layout to the button's it changed the child view's layout. As a result, the detector got bounds (0,0,0,0) thus all the non-native were considered out of bounds. This broke pressable as it relies on longPress to register touches. ## Test plan Tested on the following code <details> ```tsx import React from 'react'; import { Text, StyleSheet, View } from 'react-native'; import { Pressable, GestureHandlerRootView } from 'react-native-gesture-handler' const PressableExample = () => { const [count, setCount] = React.useState(0); return ( <GestureHandlerRootView style={styles.container}> <Pressable onPress={() => setCount((c) => c + 1)}> <View style={styles.pressable}> <Text>{count}</Text> </View> </Pressable> </GestureHandlerRootView > ); }; const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', }, pressable: { alignItems: 'center', justifyContent: 'center', backgroundColor: 'green', width: 100, height: 100 }, wrapperCustom: { borderRadius: 8, padding: 16, minWidth: 150, alignItems: 'center', }, text: { fontSize: 18, color: 'white', fontWeight: '600', }, }); export default PressableExample; ``` </details>
1 parent 8fc4f04 commit 06aab22

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,25 @@ void RNGestureHandlerButtonWrapperShadowNode::layout(
7777
// values
7878
if (shouldSkipCustomLayout) {
7979
react_native_assert(previousGrandChildLayoutMetrics_.has_value());
80-
mutableChild->setLayoutMetrics(previousGrandChildLayoutMetrics_.value());
80+
setLayoutMetrics(previousGrandChildLayoutMetrics_.value());
8181

8282
auto metricsNoOrigin = previousGrandChildLayoutMetrics_.value();
8383
metricsNoOrigin.frame.origin = Point{};
84+
85+
mutableChild->setLayoutMetrics(metricsNoOrigin);
8486
mutableGrandChild->setLayoutMetrics(metricsNoOrigin);
8587
return;
8688
}
8789

8890
auto metrics = grandChild->getLayoutMetrics();
8991
previousGrandChildLayoutMetrics_ = metrics;
9092

91-
mutableChild->setLayoutMetrics(metrics);
93+
setLayoutMetrics(metrics);
9294

9395
auto metricsNoOrigin = grandChild->getLayoutMetrics();
9496
metricsNoOrigin.frame.origin = Point{};
97+
98+
mutableChild->setLayoutMetrics(metricsNoOrigin);
9599
mutableGrandChild->setLayoutMetrics(metricsNoOrigin);
96100
}
97101

0 commit comments

Comments
 (0)