Skip to content

Commit 4e99364

Browse files
committed
PureNativeButton
1 parent 38219bf commit 4e99364

3 files changed

Lines changed: 17 additions & 40 deletions

File tree

packages/docs-gesture-handler/docs/components/buttons.mdx

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ import GifGallery from '@site/components/GifGallery';
1313

1414
The Gesture Handler library offers native components that function as buttons, serving as alternatives to `TouchableHighlight` or `TouchableOpacity` from the core React Native framework. These buttons process touch recognition natively, which ensures a deterministic response. This capability significantly enhances performance; for example, it allows for immediate ripple effects on Android, unlike `TouchableNativeFeedback`, which requires a touch event roundtrip to JavaScript that can cause delays, especially noticeable on older devices. Additionally, these components handle default platform interactions natively, particularly in scrollable containers where interactions are smartly delayed to prevent unintended highlighting during a fling.
1515

16-
Currently Gesture Handler library exposes three components that render native touchable elements under the hood:
16+
Gesture Handler library exposes components that render native touchable elements under the hood:
1717

18+
- [`RawButton`](#rawbutton)
1819
- [`BaseButton`](#basebutton)
1920
- [`RectButton`](#rectbutton)
2021
- [`BorderlessButton`](#borderlessbutton)
2122

2223
On top of that all the buttons are wrapped with [`Native`](/docs/gestures/use-native-gesture) gesture and therefore allow for all its [properties](/docs/gestures/use-native-gesture#config) to be applied to them.
2324

25+
## RawButton
26+
27+
The most basic button component does not provide any feedback and lacks props such as `onPress`. It serves as a foundation for other button components and is ideal if you wish to implement your own custom interactions for when the button is pressed.
28+
2429
## BaseButton
2530

2631
Can be used as a base class if you'd like to implement some custom interaction for when the button is pressed.
@@ -175,41 +180,3 @@ It should be used if you wish to handle non-crucial actions and supportive behav
175180
<img src={useBaseUrl('gifs/androidmail.gif')} width="280" />
176181
<img src={useBaseUrl('gifs/iosmail.gif')} width="280" />
177182
</GifGallery>
178-
179-
### PureNativeButton
180-
181-
Use a `PureNativeButton` for accessing the host component used for build more complex buttons listed above.
182-
Normally it is not recommended to use, but it might be useful if you want to wrap it using [Animated](https://reactnative.dev/docs/animated) or [Reanimated](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started/).
183-
184-
```tsx
185-
import {
186-
createNativeWrapper,
187-
PureNativeButton,
188-
} from 'react-native-gesture-handler';
189-
import Animated from 'react-native-reanimated';
190-
const { event, Value, createAnimatedComponent } = Animated;
191-
192-
const AnimatedRawButton = createNativeWrapper(
193-
createAnimatedComponent(PureNativeButton),
194-
{
195-
shouldCancelWhenOutside: false,
196-
shouldActivateOnStart: false,
197-
}
198-
);
199-
200-
export default class App extends React.Component {
201-
constructor(props) {
202-
super(props);
203-
const state = new Value();
204-
this._onGestureEvent = event([
205-
{
206-
nativeEvent: { state },
207-
},
208-
]);
209-
}
210-
211-
render() {
212-
return <AnimatedRawButton onHandlerStateChange={this._onGestureEvent} />;
213-
}
214-
}
215-
```

packages/docs-gesture-handler/docs/guides/upgrading-to-3.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ code2={
248248

249249
The implementation of buttons has been updated, resolving most button-related issues. They have also been internally rewritten to utilize the new hook API. The original button components are still accessible but have been renamed with the prefix `Legacy`, e.g., `RectButton` is now available as `LegacyRectButton`.
250250

251-
Although the legacy JS implementation of the buttons is still available, they also use the new host component internally.
251+
Although the legacy JS implementation of the buttons is still available, they also use the new host component internally. Because of that, `PureNativeButton` is no longer available in Gesture Handler 3.
252252

253253
<details>
254254
<summary>Legacy buttons</summary>
@@ -259,6 +259,7 @@ Although the legacy JS implementation of the buttons is still available, they al
259259
| `BaseButton` | `LegacyBaseButton` |
260260
| `RectButton` | `LegacyRectButton` |
261261
| `BorderlessButton` | `LegacyBorderlessButton` |
262+
| `PureNativeButton` | *Not available in Gesture Handler 3* |
262263

263264
</details>
264265

skills/gesture-handler-3-migration/SKILL.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ The exception to thait is `Gesture.ForceTouch` which DOES NOT have a counterpart
3535
#### Callback changes
3636

3737
In Gesture Handler 3 some of the callbacks were renamed, namely:
38+
3839
- `onStart` -> `onActivate`
3940
- `onEnd` -> `onDeactivate`
4041
- `onTouchesCancelled` -> `onTouchesCancel`
4142

4243
In the hooks API `onChange` is no longer available. Instead the `*change*` properties were moved to the event available inside `onUpdate`.
4344

4445
All callbacks of a gesture are now using the same type:
46+
4547
- `usePanGesture()` -> `PanGestureEvent`
4648
- `useTapGesture()` -> `TapGestureEvent`
4749
- `useLongPressGesture()` -> `LongPressGestureEvent`
@@ -53,6 +55,7 @@ All callbacks of a gesture are now using the same type:
5355
- `useManualGesture()` -> `ManualGestureEvent`
5456

5557
The exception to this is touch events:
58+
5659
- `onTouchesDown`
5760
- `onTouchesUp`
5861
- `onTouchesMove`
@@ -65,12 +68,14 @@ Where each callback receives `GestureTouchEvent` regardless of the hook used.
6568
In Gesture Handler 3, `stateManager` is no longer passed to `TouchEvent` callbacks. Instead, you should use the global `GestureStateManager`.
6669

6770
`GestureStateManager` provides methods for imperative state management:
71+
6872
- .begin(handlerTag: number)
6973
- .activate(handlerTag: number)
7074
- .deactivate(handlerTag: number) (.end() in the old API)
7175
- .fail(handlerTag: number)
7276

7377
`handlerTag` can be obtained in two ways:
78+
7479
1. From the gesture object returned by the hook (`gesture.handlerTag`)
7580
2. From the event inside callback (`event.handlerTag`)
7681

@@ -83,13 +88,15 @@ Callback definitions CANNOT reference the gesture that's being defined. In this
8388
`Gesture.Simultaneous(gesture1, gesture2);` becomes `useSimultaneousGestures(pan1, pan2);`
8489

8590
All relations from the old API and their counterparts in the new one:
91+
8692
- `Gesture.Race()` -> `useCompetingGestures()`
8793
- `Gesture.Simultaneous()` -> `useSimultaneousGestures()`
8894
- `Gesture.Exclusive()` -> `useExclusiveGestures()`
8995

9096
#### Cross components relations properties
9197

9298
Properties used to define cross-components interactions were renamed:
99+
93100
- `.simultaneousWithExternalGesture` -> `simultaneousWith:`
94101
- `.requireExternalGestureToFail` -> `requireToFail:`
95102
- `.blocksExternalGesture` -> `block:`
@@ -160,6 +167,8 @@ Don't suggest replacing buttons from Gesture Handler with components from React
160167

161168
The implementation of buttons has been updated, resolving most button-related issues. They have also been internally rewritten to utilize the new hook API. The legacy JS implementations of button components are still accessible but have been renamed with the prefix `Legacy`, e.g., `RectButton` is now available as `LegacyRectButton`. Those still use the new native component under the hood.
162169

170+
`PureNativeButton` has been removed. If encountered, inform the user that it has been removed and let them decide how to handle that case. They can achieve similar funcionality with other buttons.
171+
163172
Other components have also been internally rewritten using the new hook API but are exported under their original names, so no changes are necessary on your part. However, if you need to use the previous implementation for any reason, the legacy components are also available and are prefixed with `Legacy`, e.g., `ScrollView` is now available as `LegacyScrollView`.
164173

165174
### Replaced types

0 commit comments

Comments
 (0)