display: contents based button styling#3634
Merged
Merged
Conversation
c5661d1 to
fbf37bb
Compare
612fb8e to
773da37
Compare
773da37 to
d735767
Compare
m-bert
reviewed
Oct 27, 2025
m-bert
reviewed
Jan 7, 2026
m-bert
approved these changes
Jan 27, 2026
…tector.mm Co-authored-by: Michał Bert <63123542+m-bert@users.noreply.github.com>
akwasniewski
added a commit
that referenced
this pull request
Feb 13, 2026
## 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Changes the button implementation of the native
GestureHandlerButtoncomponent, not to re-export the button component. Instead, it provides a "sandwich" implementation based ondisplay: contents.The issues we had with the styling of the buttons in the past stemmed from it extending
ViewGroupinstead ofReactViewGroup. This cannot be changed due to the difference in handling ofonTouchEvent. We experimented with wrapping the button with aViewin the past, but properly handling layout turned out to be quite a challenge. Hopefully, with the addition ofdisplay: contents, this will be easier now.This PR changes the structure of the button to be:
RNGestureHandlerButtonWrapperNativeComponentViewButtonComponentThe styles passed from the user are split into two categories:
Those affecting the layout need to be set on the button itself, while visual changes need to be set on the View wrapping it. Exceptions are:
zIndex,transform, andtransformOrigin, which need to be on the View.zIndexbecause the View is being rendered in the hierarchy at the level the button would be expected, and transforms to properly calculate touch coordinate transforms.Why not just
ButtonComponent?We need a
Viewcomponent as its parent to handle all styles that React Native supports properly.Why not just
ButtonComponentwrapped withView?In order for the view to always match the layout of the button, we need to set it at the shadow node level. Shadow nodes only have references to their children, not their parents. To have access to the layout of the button and the ability to copy it to the view wrapping it, there needs to be one more node as the parent of that subtree. That node is responsible for making sure that the size and positioning of the View match the Button.
The native components for the wrapper serve no purpose, since it's being rendered with
display: contents, but RN doesn't know that - there needs to be something it can link to.Test plan
See the
ContentsButtonfile