Commit 7a4f774
[Native]
## Description
Changes the button implementation of the native `GestureHandlerButton`
component, not to re-export the button component. Instead, it provides a
"sandwich" implementation based on `display: contents`.
The issues we had with the styling of the buttons in the past stemmed
from it extending `ViewGroup` instead of `ReactViewGroup`. This cannot
be changed due to the difference in handling of `onTouchEvent`. We
experimented with wrapping the button with a `View` in the past, but
properly handling layout turned out to be quite a challenge. Hopefully,
with the addition of `display: contents`, this will be easier now.
This PR changes the structure of the button to be:
- `RNGestureHandlerButtonWrapperNativeComponent`
- `View`
- `ButtonComponent`
The styles passed from the user are split into two categories:
- visual only
- affecting layout
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`, and `transformOrigin`, which need to be on the
View. `zIndex` because 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 `View` component as its parent to handle all styles that React
Native supports properly.
### Why not just `ButtonComponent` wrapped with `View`?
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 `ContentsButton` file
---------
Co-authored-by: Michał Bert <63123542+m-bert@users.noreply.github.com>display: contents based button styling (#3634)1 parent 3da9a68 commit 7a4f774
18 files changed
Lines changed: 1054 additions & 7 deletions
File tree
- apps/basic-example
- ios
- src
- packages/react-native-gesture-handler
- android/src/main/java/com/swmansion/gesturehandler
- react
- apple
- src
- components
- specs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2919 | 2919 | | |
2920 | 2920 | | |
2921 | 2921 | | |
2922 | | - | |
| 2922 | + | |
2923 | 2923 | | |
2924 | 2924 | | |
2925 | 2925 | | |
| |||
2993 | 2993 | | |
2994 | 2994 | | |
2995 | 2995 | | |
2996 | | - | |
| 2996 | + | |
2997 | 2997 | | |
2998 | 2998 | | |
2999 | 2999 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
24 | 29 | | |
25 | 30 | | |
26 | 31 | | |
| |||
0 commit comments