Skip to content

Commit 67006d6

Browse files
m-bertCopilotj-piasecki
authored
[docs] Update docs (#3959)
## Description In this PR, I go through each section and make sure that everything is in the same style, has correct information and there are no broken links. ## Test plan Read docs 🤓 --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jakub Piasecki <jakub.piasecki@swmansion.com>
1 parent 06aab22 commit 67006d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1818
-1329
lines changed

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

Lines changed: 171 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,133 +7,237 @@ sidebar_label: Pressable
77
import useBaseUrl from '@docusaurus/useBaseUrl';
88
import GifGallery from '@site/components/GifGallery';
99

10-
<GifGallery>
11-
<img src={useBaseUrl('gifs/pressable.gif')} width="70%" />
12-
</GifGallery>
13-
1410
:::info
1511
This component is a drop-in replacement for the `Pressable` component.
1612
:::
1713

18-
`Pressable` is a component that can detect various stages of tap, press, and hover interactions on any of its children.
14+
<GifGallery>
15+
<img src={useBaseUrl('gifs/pressable.gif')} width="70%" />
16+
</GifGallery>
1917

20-
### Usage:
18+
`Pressable` is a component that can detect various stages of tap, press, and hover interactions on any of its children.
2119

22-
To use `Pressable`, import it in the following way:
20+
To use `Pressable`, ensure that your app is wrapped in `GestureHandlerRootView` and import it as follows:
2321

24-
```js
22+
```ts
2523
import { Pressable } from 'react-native-gesture-handler';
2624
```
2725

2826
## Properties
2927

30-
### `children`
28+
### children
29+
30+
```ts
31+
children?:
32+
| React.ReactNode
33+
| ((state: PressableStateCallbackType) => React.ReactNode);
34+
```
35+
36+
Either children or a render prop that receives a boolean reflecting whether the component is currently pressed.
37+
38+
### style
39+
40+
```ts
41+
style?:
42+
| StyleProp<ViewStyle>
43+
| ((state: PressableStateCallbackType) => StyleProp<ViewStyle>);
44+
```
3145

32-
either children or a render function that receives a boolean reflecting whether
33-
the component is currently pressed.
46+
Either view styles or a function that receives a boolean reflecting whether the component is currently pressed and returns view styles.
3447

35-
### `style`
48+
### onPress
3649

37-
either view styles or a function that receives a boolean reflecting whether
38-
the component is currently pressed and returns view styles.
50+
```ts
51+
onPress?: null | ((event: PressableEvent) => void);
52+
```
3953

40-
### `onPress`
54+
Called after [`onPressOut`](#onpressout) when a single tap gesture is detected. Details about the event object can be found in the [PressableEvent](#pressableevent) section below.
4155

42-
called after `onPressOut` when a single tap gesture is detected.
56+
### onPressIn
4357

44-
### `onPressIn`
58+
```ts
59+
onPressIn?: null | ((event: PressableEvent) => void);
60+
```
4561

46-
called before `onPress` when a touch is engaged.
62+
Called before `onPress` when a touch is engaged. Details about the event object can be found in the [PressableEvent](#pressableevent) section below.
4763

48-
### `onPressOut`
64+
### onPressOut
4965

50-
called before `onPress` when a touch is released.
66+
```ts
67+
onPressOut?: null | ((event: PressableEvent) => void);
68+
```
5169

52-
### `onLongPress`
70+
Called before `onPress` when a touch is released (before [`onPress`](#onpress)). Details about the event object can be found in the [PressableEvent](#pressableevent) section below.
5371

54-
called immediately after pointer has been down for at least `delayLongPress` milliseconds (`500` ms by default).
72+
### onLongPress
5573

56-
After `onLongPress` has been called, `onPressOut` will be called as soon as the pointer is lifted and `onPress` will not be called at all.
74+
```ts
75+
onLongPress?: null | ((event: PressableEvent) => void);
76+
```
5777

58-
### `cancelable`
78+
Called immediately after pointer has been down for at least [`delayLongPress`](#delaylongpress) milliseconds.
5979

60-
whether a press gesture can be interrupted by a parent gesture such as a scroll event. Defaults to `true`.
80+
After `onLongPress` has been called, [`onPressOut`](#onpressout) will be called as soon as the pointer is lifted and [`onPress`](#onpress) will not be called at all.
6181

62-
### `onHoverIn` (Web only)
82+
### cancelable
6383

64-
called when pointer is hovering over the element.
84+
```ts
85+
cancelable?: null | boolean;
86+
```
6587

66-
### `onHoverOut` (Web only)
88+
Whether a press gesture can be interrupted by a parent gesture such as a scroll event. Defaults to `true`.
6789

68-
called when pointer stops hovering over the element.
90+
### onHoverIn (Web only)
6991

70-
### `delayHoverIn` (Web only)
92+
```ts
93+
onHoverIn?: null | ((event: PressableEvent) => void);
94+
```
7195

72-
duration to wait after hover in before calling `onHoverIn`.
96+
Called when pointer is hovering over the element.
7397

74-
### `delayHoverOut` (Web only)
98+
### onHoverOut (Web only)
7599

76-
duration to wait after hover out before calling `onHoverOut`.
100+
```ts
101+
onHoverOut?: null | ((event: PressableEvent) => void);
102+
```
77103

78-
### `delayLongPress`
104+
Called when pointer stops hovering over the element.
79105

80-
duration (in milliseconds) from `onPressIn` before `onLongPress` is called.
106+
### delayHoverIn (Web only)
81107

82-
### `disabled`
108+
```ts
109+
delayHoverIn?: number | null;
110+
```
83111

84-
whether the `Pressable` behavior is disabled.
112+
Duration to wait after hover in before calling `onHoverIn`.
85113

86-
### `hitSlop` (Android & iOS only)
114+
### delayHoverOut (Web only)
87115

88-
additional distance outside of the view in which a press is detected and `onPressIn` is triggered.
116+
```ts
117+
delayHoverOut?: number | null;
118+
```
89119

90-
Accepts values of type `number` or [`Rect`](https://reactnative.dev/docs/rect)
120+
Duration to wait after hover out before calling `onHoverOut`.
91121

92-
### `pressRetentionOffset` (Android & iOS only)
122+
### delayLongPress
93123

94-
additional distance outside of the view (or `hitSlop` if present) in which a touch is considered a
95-
press before `onPressOut` is triggered.
124+
```ts
125+
delayLongPress?: null | number;
126+
```
96127

97-
Accepts values of type `number` or [`Rect`](https://reactnative.dev/docs/rect)
128+
Duration (in milliseconds) from `onPressIn` before `onLongPress` is called. Default value is `500` ms.
98129

99-
### `android_disableSound` (Android only)
130+
### disabled
100131

101-
if `true`, doesn't play system sound on touch.
132+
```ts
133+
disabled?: null | boolean;
134+
```
102135

103-
### `android_ripple` (Android only)
136+
Whether the `Pressable` behavior is disabled.
104137

105-
enables the Android ripple effect and configures its color, radius and other parameters.
138+
### hitSlop (Android & iOS only)
106139

107-
Accepts values of type [`RippleConfig`](https://reactnative.dev/docs/pressable#rippleconfig)
140+
```ts
141+
hitSlop?: null | Insets | number;
142+
```
108143

109-
### `testOnly_pressed`
144+
Additional distance outside of the view in which a press is detected and [`onPressIn`](#onpressin) is triggered.
110145

111-
used only for documentation or testing (e.g. snapshot testing).
146+
The `Insets` type is essentially the same as [`Rect`](https://reactnative.dev/docs/rect).
112147

113-
### `unstable_pressDelay`
148+
### pressRetentionOffset (Android & iOS only)
114149

115-
duration (in milliseconds) to wait after press down before calling `onPressIn`.
150+
```ts
151+
pressRetentionOffset?: null | Insets | number;
152+
```
116153

117-
### Example:
154+
Additional distance outside of the view (or [`hitSlop`](#hitslop) if present) in which a touch is considered a
155+
press before [`onPressOut`](#onpressout) is triggered.
118156

119-
See the full [pressable example](https://github.com/software-mansion/react-native-gesture-handler/blob/main/apps/common-app/src/new_api/pressable/index.tsx) from `GestureHandler` example app.
157+
The `Insets` type is essentially the same as [`Rect`](https://reactnative.dev/docs/rect).
120158

121-
import GestureStateFlowExample from '@site/src/examples/GestureStateFlowExample';
159+
### android_disableSound (Android only)
122160

123-
```js
161+
```ts
162+
android_disableSound?: null | boolean;
163+
```
164+
165+
If `true`, doesn't play system sound on touch.
166+
167+
### android_ripple (Android only)
168+
169+
```ts
170+
android_ripple?: null | PressableAndroidRippleConfig;
171+
```
172+
173+
Enables the Android [ripple](https://developer.android.com/reference/android/graphics/drawable/RippleDrawable) effect and configures its color, radius and other parameters.
174+
175+
Accepts values of type [`RippleConfig`](https://reactnative.dev/docs/pressable#rippleconfig).
176+
177+
### testOnly_pressed
178+
179+
```ts
180+
testOnly_pressed?: null | boolean;
181+
```
182+
183+
Used only for documentation or testing (e.g. snapshot testing).
184+
185+
### unstable_pressDelay
186+
187+
```ts
188+
unstable_pressDelay?: number | undefined;
189+
```
190+
191+
Duration (in milliseconds) to wait after press down before calling [`onPressIn`](#onpressin).
192+
193+
## PressableEvent
194+
195+
All `Pressable` callbacks receive an event object as a parameter, which is of type `PressableEvent` and has the following structure:
196+
197+
```ts
198+
export type PressableEvent = { nativeEvent: InnerPressableEvent };
199+
200+
export type InnerPressableEvent = {
201+
changedTouches: InnerPressableEvent[];
202+
identifier: number;
203+
locationX: number;
204+
locationY: number;
205+
pageX: number;
206+
pageY: number;
207+
target: number;
208+
timestamp: number;
209+
touches: InnerPressableEvent[];
210+
force?: number;
211+
};
212+
```
213+
214+
## Example
215+
216+
See the full example in [Gesture Handler repository](https://github.com/software-mansion/react-native-gesture-handler/blob/main/apps/common-app/src/legacy/v2_api/pressable/index.tsx).
217+
218+
<CollapsibleCode
219+
label="Show full example"
220+
expandedLabel="Hide full example"
221+
lineBounds={[5, 20]}
222+
src={`
124223
import { View, Text, StyleSheet } from 'react-native';
125-
import { Pressable } from 'react-native-gesture-handler';
224+
import {
225+
GestureHandlerRootView,
226+
Pressable,
227+
} from 'react-native-gesture-handler';
126228
127229
export default function Example() {
128230
return (
129-
<Pressable
130-
style={({ pressed }) => (pressed ? styles.highlight : styles.pressable)}
131-
hitSlop={20}
132-
pressRetentionOffset={20}>
133-
<View style={styles.textWrapper}>
134-
<Text style={styles.text}>Pressable!</Text>
135-
</View>
136-
</Pressable>
231+
<GestureHandlerRootView>
232+
<Pressable
233+
style={({ pressed }) => (pressed ? styles.highlight : styles.pressable)}
234+
hitSlop={20}
235+
pressRetentionOffset={20}>
236+
<View style={styles.textWrapper}>
237+
<Text style={styles.text}>Pressable!</Text>
238+
</View>
239+
</Pressable>
240+
</GestureHandlerRootView>
137241
);
138242
}
139243
@@ -159,4 +263,4 @@ const styles = StyleSheet.create({
159263
color: 'black',
160264
},
161265
});
162-
```
266+
`}/>

0 commit comments

Comments
 (0)