Commit 8ec2529
authored
[iOS] Fix gestures not ending properly on
## Description
There's a change in gesture recognizers introduced in `iOS` 26. Now when
`reset` method is called, recognizers go back to
`UIGestureRecognizerStatePossible` state. This breaks our current
behavior, because this state is mapped into
`RNGestureHandlerStateBegan`, so if for example `Pan` fails, it tries to
send event with `Began` state.
Unfortunately, changing recognizer state is not possible outside of
`touches*` methods, therefore we had to move `triggerAction` into those
callbacks.
Let me know if you see a different approach into this problem.
Fixes #3733
> [!WARNING]
> `triggerAction` call was already present in `Tap` right before `reset`
([see
here](https://github.com/software-mansion/react-native-gesture-handler/blob/21c4943d5769d3fff60f7bf0550c5810f6011e13/packages/react-native-gesture-handler/apple/Handlers/RNTapHandler.m#L120)).
Looks like it was called twice for some reason (but I believe that
[check for
_lastState](https://github.com/software-mansion/react-native-gesture-handler/blob/21c4943d5769d3fff60f7bf0550c5810f6011e13/packages/react-native-gesture-handler/apple/RNGestureHandler.mm#L311)
prevented any problems with this redundancy). For now I have not
included second call. If you think it is required, let me know.
## Test plan
Tested on the code provided below, on the following platforms:
- [x] iOS 26.0 (iPhone 17 Pro)
- [x] iOS 18.5 (iPhone 16e)
- [x] OSX (macOS 15.6.1)
<details>
<summary>Test code:</summary>
```tsx
import { StyleSheet, View, Text } from 'react-native';
import {
GestureHandlerRootView,
Gesture,
GestureDetector,
GestureType,
} from 'react-native-gesture-handler';
function TestBox({
gestureType,
bgColor,
}: {
gestureType: GestureType;
bgColor: string;
}) {
const handlerName = gestureType.handlerName;
const gesture = gestureType
.onEnd(() => {
console.log(`[${handlerName}] onEnd`);
})
.onFinalize(() => {
console.log(`[${handlerName}] onFinalize`);
})
.runOnJS(true);
return (
<View style={styles.center}>
<Text>{handlerName}</Text>
<GestureDetector gesture={gesture}>
<View style={[styles.box, { backgroundColor: bgColor }]} />
</GestureDetector>
</View>
);
}
export default function App() {
return (
<GestureHandlerRootView style={[{ flex: 1, padding: 50 }, styles.center]}>
<TestBox gestureType={Gesture.Pan()} bgColor="#b58df1" />
<TestBox gestureType={Gesture.LongPress()} bgColor="#f1a85d" />
<TestBox gestureType={Gesture.Fling()} bgColor="#5df1a8" />
<TestBox gestureType={Gesture.Tap()} bgColor="#5d8ef1" />
</GestureHandlerRootView>
);
}
const styles = StyleSheet.create({
center: {
display: 'flex',
justifyContent: 'space-around',
alignItems: 'center',
},
box: {
height: 100,
width: 100,
backgroundColor: '#b58df1',
borderRadius: 20,
marginBottom: 30,
},
});
```
</details>iOS 26 (#3740)1 parent f7209a7 commit 8ec2529
File tree
4 files changed
+22
-9
lines changed- packages/react-native-gesture-handler/apple/Handlers
4 files changed
+22
-9
lines changedLines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| 65 | + | |
| 66 | + | |
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
| |||
69 | 73 | | |
70 | 74 | | |
71 | 75 | | |
72 | | - | |
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
110 | 112 | | |
| 113 | + | |
| 114 | + | |
111 | 115 | | |
112 | 116 | | |
113 | 117 | | |
| |||
181 | 185 | | |
182 | 186 | | |
183 | 187 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| |||
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
| 168 | + | |
| 169 | + | |
168 | 170 | | |
169 | 171 | | |
170 | 172 | | |
| |||
243 | 245 | | |
244 | 246 | | |
245 | 247 | | |
| 248 | + | |
| 249 | + | |
246 | 250 | | |
247 | 251 | | |
248 | 252 | | |
249 | 253 | | |
250 | 254 | | |
251 | 255 | | |
| 256 | + | |
| 257 | + | |
252 | 258 | | |
253 | 259 | | |
254 | 260 | | |
255 | 261 | | |
256 | 262 | | |
257 | 263 | | |
258 | | - | |
259 | 264 | | |
260 | 265 | | |
261 | 266 | | |
| |||
Lines changed: 8 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
134 | 136 | | |
135 | 137 | | |
136 | 138 | | |
| |||
141 | 143 | | |
142 | 144 | | |
143 | 145 | | |
| 146 | + | |
| 147 | + | |
144 | 148 | | |
145 | 149 | | |
146 | 150 | | |
| |||
200 | 204 | | |
201 | 205 | | |
202 | 206 | | |
| 207 | + | |
| 208 | + | |
203 | 209 | | |
204 | 210 | | |
205 | 211 | | |
206 | 212 | | |
207 | 213 | | |
208 | 214 | | |
| 215 | + | |
| 216 | + | |
209 | 217 | | |
210 | 218 | | |
211 | 219 | | |
| |||
243 | 251 | | |
244 | 252 | | |
245 | 253 | | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | 254 | | |
250 | 255 | | |
251 | 256 | | |
| |||
0 commit comments