Skip to content

Commit 0cdf520

Browse files
authored
[docs] Redirects (#3976)
## Description This PR adds redirects for our docs so that old gesture links will point to new version. ## Test plan Read docs 🤓
1 parent 560d1b5 commit 0cdf520

28 files changed

Lines changed: 2279 additions & 2 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"label": "Gesture Handler 2",
3+
"position": 4,
4+
"link": {
5+
"type": "generated-index"
6+
}
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### Callbacks common to all continuous gestures:
2+
3+
### `onUpdate(callback)`
4+
5+
Set the callback that is being called every time the gesture receives an update while it's active.
6+
7+
### `onChange(callback)`
8+
9+
Set the callback that is being called every time the gesture receives an update while it's active. This callback will receive information about change in value in relation to the last received event.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Properties common to all continuous gestures:
2+
3+
### `manualActivation(value: boolean)`
4+
5+
When `true` the handler will not activate by itself even if its activation criteria are met. Instead you can manipulate its state using [state manager](/docs/2.x/gestures/state-manager/).
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
### Callbacks common to all gestures:
2+
3+
### `onBegin(callback)`
4+
5+
Set the callback that is being called when given gesture handler starts receiving touches. At the moment of this callback the handler is not yet in an active state and we don't know yet if it will recognize the gesture at all.
6+
7+
### `onStart(callback)`
8+
9+
Set the callback that is being called when the gesture is recognized by the handler and it transitions to the active state.
10+
11+
### `onEnd(callback)`
12+
13+
Set the callback that is being called when the gesture that was recognized by the handler finishes. It will be called only if the handler was previously in the active state.
14+
15+
### `onFinalize(callback)`
16+
17+
Set the callback that is being called when the handler finalizes handling gesture - the gesture was recognized and has finished or it failed to recognize.
18+
19+
### `onTouchesDown(callback)`
20+
21+
Set the `onTouchesDown` callback which is called every time a finger is placed on the screen.
22+
23+
### `onTouchesMove(callback)`
24+
25+
Set the `onTouchesMove` callback which is called every time a finger is moved on the screen.
26+
27+
### `onTouchesUp(callback)`
28+
29+
Set the `onTouchesUp` callback which is called every time a finger is lifted from the screen.
30+
31+
### `onTouchesCancelled(callback)`
32+
33+
Set the `onTouchesCancelled` callback which is called every time a finger stops being tracked, for example when the gesture finishes.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
### Properties common to all gestures:
2+
3+
### `enabled(value: boolean)`
4+
5+
Indicates whether the given handler should be analyzing stream of touch events or not.
6+
When set to `false` we can be sure that the handler's state will **never** become [`ACTIVE`](/docs/2.x/fundamentals/states-events#active).
7+
If the value gets updated while the handler already started recognizing a gesture, then the handler's state it will immediately change to [`FAILED`](/docs/2.x/fundamentals/states-events#failed) or [`CANCELLED`](/docs/2.x/fundamentals/states-events#cancelled) (depending on its current state).
8+
Default value is `true`.
9+
10+
### `shouldCancelWhenOutside(value: boolean)`
11+
12+
When `true` the handler will [cancel](/docs/2.x/fundamentals/states-events#cancelled) or [fail](/docs/2.x/fundamentals/states-events#failed) recognition (depending on its current state) whenever the finger leaves the area of the connected view.
13+
Default value of this property is different depending on the handler type.
14+
Most handlers' `shouldCancelWhenOutside` property defaults to `false` except for the [`LongPressGesture`](/docs/2.x/gestures/long-press-gesture) and [`TapGesture`](/docs/2.x/gestures/tap-gesture) which default to `true`.
15+
16+
### `hitSlop(settings)`
17+
18+
This parameter enables control over what part of the connected view area can be used to [begin](/docs/2.x/fundamentals/states-events#began) recognizing the gesture.
19+
When a negative number is provided the bounds of the view will reduce the area by the given number of points in each of the sides evenly.
20+
21+
Instead you can pass an object to specify how each boundary side should be reduced by providing different number of points for `left`, `right`, `top` or `bottom` sides.
22+
You can alternatively provide `horizontal` or `vertical` instead of specifying directly `left`, `right` or `top` and `bottom`.
23+
Finally, the object can also take `width` and `height` attributes.
24+
When `width` is set it is only allow to specify one of the sides `right` or `left`.
25+
Similarly when `height` is provided only `top` or `bottom` can be set.
26+
Specifying `width` or `height` is useful if we only want the gesture to activate on the edge of the view. In which case for example we can set `left: 0` and `width: 20` which would make it possible for the gesture to be recognize when started no more than 20 points from the left edge.
27+
28+
**IMPORTANT:** Note that this parameter is primarily designed to reduce the area where gesture can activate. Hence it is only supported for all the values (except `width` and `height`) to be non positive (0 or lower). Although on Android it is supported for the values to also be positive and therefore allow to expand beyond view bounds but not further than the parent view bounds. To achieve this effect on both platforms you can use React Native's View [hitSlop](https://reactnative.dev/docs/view.html#hitslop) property.
29+
30+
### `withRef(ref)`
31+
32+
Sets a ref to the gesture object, allowing for interoperability with the old
33+
API.
34+
35+
### `withTestId(testID)`
36+
37+
Sets a `testID` property for gesture object, allowing for querying for it in tests.
38+
39+
### `cancelsTouchesInView(value)` (**iOS only**)
40+
41+
Accepts a boolean value.
42+
When `true`, the gesture will cancel touches for native UI components (`UIButton`, `UISwitch`, etc) it's attached to when it becomes [`ACTIVE`](/docs/2.x/fundamentals/states-events#active).
43+
Default value is `true`.
44+
45+
### `runOnJS(value: boolean)`
46+
47+
When `react-native-reanimated` is installed, the callbacks passed to the gestures are automatically workletized and run on the UI thread when called. This option allows for changing this behavior: when `true`, all the callbacks will be run on the JS thread instead of the UI thread, regardless of whether they are worklets or not.
48+
Defaults to `false`.
49+
50+
### `simultaneousWithExternalGesture(otherGesture1, otherGesture2, ...)`
51+
52+
Adds a gesture that should be recognized simultaneously with this one.
53+
54+
**IMPORTANT:** Note that this method only marks the relation between gestures, without [composing them](/docs/2.x/fundamentals/gesture-composition). [`GestureDetector`](/docs/2.x/gestures/gesture-detector) will not recognize the `otherGestures` and it needs to be added to another detector in order to be recognized.
55+
56+
### `requireExternalGestureToFail(otherGesture1, otherGesture2, ...)`
57+
58+
Adds a relation requiring another gesture to fail, before this one can activate.
59+
60+
### `blocksExternalGesture(otherGesture1, otherGesture2, ...)`
61+
62+
Adds a relation that makes other gestures wait with activation until this gesture fails (or doesn't start at all).
63+
64+
**IMPORTANT:** Note that this method only marks the relation between gestures, without [composing them](/docs/2.x/fundamentals/gesture-composition).[`GestureDetector`](/docs/2.x/gestures/gesture-detector) will not recognize the `otherGestures` and it needs to be added to another detector in order to be recognized.
65+
66+
### `activeCursor(value)` (Web only)
67+
68+
This parameter allows to specify which cursor should be used when gesture activates. Supports all CSS cursor values (e.g. `"grab"`, `"zoom-in"`). Default value is set to `"auto"`.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### Event attributes common to all gestures:
2+
3+
### `state`
4+
5+
Current [state](/docs/2.x/fundamentals/states-events) of the handler. Expressed as one of the constants exported under `State` object by the library.
6+
7+
### `numberOfPointers`
8+
9+
Represents the number of pointers (fingers) currently placed on the screen.
10+
11+
### `pointerType`
12+
13+
Indicates the type of pointer device in use. This value is represented by the `PointerType` enum, which includes the following fields:
14+
15+
- `TOUCH` - represents finger
16+
- `STYLUS` - represents stylus or digital pen
17+
- `MOUSE` - represents computer mouse
18+
- `KEY` - represents keyboard
19+
- `OTHER` - represents unknown device type that is not relevant
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
```jsx
2+
export default function Example() {
3+
const tap = Gesture.Tap().onStart(() => {
4+
console.log('tap');
5+
});
6+
7+
return (
8+
<GestureDetector gesture={tap}>
9+
<FunctionalComponent>
10+
<View style={styles.box} />
11+
</FunctionalComponent>
12+
</GestureDetector>
13+
);
14+
}
15+
16+
function FunctionalComponent(props) {
17+
return <View collapsable={false}>{props.children}</View>;
18+
}
19+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:::warning
2+
Heads up! This page covers the old builder-based API from Gesture Handler 2. We recommend checking out the newer hook-based API from Gesture Handler 3.
3+
:::
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
id: composed-gestures
3+
title: Composed gestures
4+
sidebar_label: Composed gestures
5+
sidebar_position: 13
6+
---
7+
8+
import OldAPIInfo from './\_shared/v2-info.md'
9+
10+
<OldAPIInfo />
11+
12+
Composed gestures (`Race`, `Simultaneous`, `Exclusive`) provide a simple way of building relations between gestures. See [Gesture Composition](/docs/2.x/fundamentals/gesture-composition) for more details.
13+
14+
## Reference
15+
16+
```jsx
17+
import { GestureDetector, Gesture } from 'react-native-gesture-handler';
18+
19+
function App() {
20+
const pan = Gesture.Pan();
21+
const longPress = Gesture.LongPress();
22+
23+
// highlight-next-line
24+
const composed = Gesture.Race(pan, longPress);
25+
26+
return (
27+
<GestureDetector gesture={composed}>
28+
<Animated.View />
29+
</GestureDetector>
30+
);
31+
}
32+
```
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
---
2+
id: fling-gesture
3+
title: Fling gesture
4+
sidebar_label: Fling gesture
5+
sidebar_position: 7
6+
---
7+
8+
import { vanishOnMobile, appearOnMobile, webContainer } from '@site/src/utils/getGestureStyles';
9+
10+
import useBaseUrl from '@docusaurus/useBaseUrl';
11+
12+
import FlingGestureBasic from '@site/static/examples/FlingGestureBasic';
13+
import FlingGestureBasicSrc from '!!raw-loader!@site/static/examples/FlingGestureBasicSrc';
14+
15+
import OldAPIInfo from './\_shared/v2-info.md'
16+
17+
<OldAPIInfo />
18+
19+
<div className={webContainer}>
20+
<div className={vanishOnMobile} style={{ display: 'flex', justifyContent: 'center', maxWidth: 360 }}>
21+
<video playsInline autoPlay muted loop style={{maxWidth: 360}}>
22+
<source src={useBaseUrl("/video/fling.mp4")} type="video/mp4"/>
23+
</video>
24+
</div>
25+
<InteractiveExample
26+
component={<FlingGestureBasic/>}
27+
src={FlingGestureBasicSrc}
28+
disableMarginBottom={true}
29+
/>
30+
</div>
31+
32+
import BaseEventData from './\_shared/base-gesture-event-data.md';
33+
import BaseEventConfig from './\_shared/base-gesture-config.md';
34+
import BaseEventCallbacks from './\_shared/base-gesture-callbacks.md';
35+
36+
A discrete gesture that activates when the movement is sufficiently long and fast.
37+
Gesture gets [ACTIVE](/docs/2.x/fundamentals/states-events#active) when movement is sufficiently long and it does not take too much time.
38+
When gesture gets activated it will turn into [END](/docs/2.x/fundamentals/states-events#end) state when finger is released.
39+
The gesture will fail to recognize if the finger is lifted before being activated.
40+
41+
<div className={appearOnMobile} style={{ display: 'flex', justifyContent: 'center' }}>
42+
<video playsInline autoPlay muted loop style={{maxWidth: 360}}>
43+
<source src={useBaseUrl("/video/fling.mp4")} type="video/mp4"/>
44+
</video>
45+
</div>
46+
47+
<samp id="FlingGestureBasicSrc">Fling Gesture</samp>
48+
49+
## Example
50+
51+
```jsx
52+
import { StyleSheet } from 'react-native';
53+
import {
54+
Gesture,
55+
GestureDetector,
56+
Directions,
57+
} from 'react-native-gesture-handler';
58+
import Animated, {
59+
useSharedValue,
60+
useAnimatedStyle,
61+
withTiming,
62+
} from 'react-native-reanimated';
63+
64+
export default function App() {
65+
const position = useSharedValue(0);
66+
// highlight-next-line
67+
const flingGesture = Gesture.Fling()
68+
.direction(Directions.RIGHT)
69+
.onStart((e) => {
70+
position.value = withTiming(position.value + 10, { duration: 100 });
71+
});
72+
73+
const animatedStyle = useAnimatedStyle(() => ({
74+
transform: [{ translateX: position.value }],
75+
}));
76+
77+
return (
78+
<GestureDetector gesture={flingGesture}>
79+
<Animated.View style={[styles.box, animatedStyle]} />
80+
</GestureDetector>
81+
);
82+
}
83+
84+
const styles = StyleSheet.create({
85+
box: {
86+
height: 120,
87+
width: 120,
88+
backgroundColor: '#b58df1',
89+
borderRadius: 20,
90+
marginBottom: 30,
91+
},
92+
});
93+
```
94+
95+
## Config
96+
97+
### Properties specific to `FlingGesture`:
98+
99+
### `direction(value: Directions)`
100+
101+
Expressed allowed direction of movement. Expected values are exported as constants in the `Directions` object. It's possible to pass one or many directions in one parameter:
102+
103+
```js
104+
import { Directions } from 'react-native-gesture-handler';
105+
fling.direction(Directions.RIGHT | Directions.LEFT);
106+
```
107+
108+
or
109+
110+
```js
111+
fling.direction(Directions.DOWN);
112+
```
113+
114+
### `numberOfPointers(value: number)`
115+
116+
Determine exact number of points required to handle the fling gesture.
117+
118+
### `mouseButton(value: MouseButton)` (Web & Android only)
119+
120+
Allows users to choose which mouse button should handler respond to. The enum `MouseButton` consists of the following predefined fields:
121+
122+
- `LEFT`
123+
- `RIGHT`
124+
- `MIDDLE`
125+
- `BUTTON_4`
126+
- `BUTTON_5`
127+
- `ALL`
128+
129+
Arguments can be combined using `|` operator, e.g. `mouseButton(MouseButton.LEFT | MouseButton.RIGHT)`. Default value is set to `MouseButton.LEFT`.
130+
131+
<BaseEventConfig />
132+
133+
## Callbacks
134+
135+
<BaseEventCallbacks />
136+
137+
## Event data
138+
139+
### Event attributes specific to `FlingGesture`:
140+
141+
### `x`
142+
143+
X coordinate of the current position of the pointer (finger or a leading pointer when there are multiple fingers placed) relative to the view attached to the [`GestureDetector`](./gesture-detector.md). Expressed in point units.
144+
145+
### `y`
146+
147+
Y coordinate of the current position of the pointer (finger or a leading pointer when there are multiple fingers placed) relative to the view attached to the [`GestureDetector`](./gesture-detector.md). Expressed in point units.
148+
149+
### `absoluteX`
150+
151+
X coordinate of the current position of the pointer (finger or a leading pointer when there are multiple fingers placed) relative to the window. The value is expressed in point units. It is recommended to use it instead of [`x`](#x) in cases when the original view can be transformed as an effect of the gesture.
152+
153+
### `absoluteY`
154+
155+
Y coordinate of the current position of the pointer (finger or a leading pointer when there are multiple fingers placed) relative to the window. The value is expressed in point units. It is recommended to use it instead of [`y`](#y) in cases when the original view can be transformed as an effect of the gesture.
156+
157+
<BaseEventData />

0 commit comments

Comments
 (0)