Commit c173e17
authored
[android] fix talkback on pressable (#4017)
## Description
When TalkBack is activated, pressable cannot be clicked on android. This
PR fixes the issue.
The reason was that Pressable requires a specific order of events. This
order of events is hardcoded and found empirically. However, with
talback enabled the order of events is different, I added a function
which queries native side whether or not talback is enabled and adjusts
expected event order accordingly.
Moreover with talback enabled longPress gets both onPointerUp and
onPointerDown before native side receives its events, thus we must not
reset the state machine state on onPointerUp.
## Test plan
Tested on the following example:
<details>
```tsx
import React from 'react';
import { Text, StyleSheet, View } from 'react-native';
import { Pressable, GestureHandlerRootView } from 'react-native-gesture-handler'
const PressableExample = () => {
const [count, setCount] = React.useState(0);
return (
<GestureHandlerRootView style={styles.container}>
<Pressable onPress={() => setCount((c) => c + 1)}>
<View style={styles.pressable}>
<Text>{count}</Text>
</View>
</Pressable>
</GestureHandlerRootView >
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
pressable: {
alignItems: 'center', justifyContent: 'center', backgroundColor: 'green', width: 100, height: 100
},
wrapperCustom: {
borderRadius: 8,
padding: 16,
minWidth: 150,
alignItems: 'center',
},
text: {
fontSize: 18,
color: 'white',
fontWeight: '600',
},
});
export default PressableExample;
```
</details>1 parent b33f704 commit c173e17
File tree
4 files changed
+74
-9
lines changed- packages/react-native-gesture-handler/src
- components/Pressable
- v3/components
4 files changed
+74
-9
lines changedLines changed: 10 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
202 | 203 | | |
203 | 204 | | |
204 | 205 | | |
| 206 | + | |
205 | 207 | | |
206 | 208 | | |
207 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
208 | 214 | | |
209 | | - | |
| 215 | + | |
210 | 216 | | |
211 | 217 | | |
212 | 218 | | |
| |||
259 | 265 | | |
260 | 266 | | |
261 | 267 | | |
262 | | - | |
| 268 | + | |
263 | 269 | | |
264 | 270 | | |
265 | 271 | | |
| |||
280 | 286 | | |
281 | 287 | | |
282 | 288 | | |
283 | | - | |
| 289 | + | |
284 | 290 | | |
285 | 291 | | |
286 | 292 | | |
| |||
Lines changed: 24 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
32 | 51 | | |
33 | 52 | | |
34 | 53 | | |
| |||
109 | 128 | | |
110 | 129 | | |
111 | 130 | | |
112 | | - | |
| 131 | + | |
| 132 | + | |
113 | 133 | | |
114 | 134 | | |
115 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
116 | 138 | | |
117 | 139 | | |
118 | 140 | | |
| |||
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
Lines changed: 9 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
199 | 200 | | |
200 | 201 | | |
201 | 202 | | |
| 203 | + | |
202 | 204 | | |
203 | 205 | | |
204 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
205 | 211 | | |
206 | | - | |
| 212 | + | |
207 | 213 | | |
208 | 214 | | |
209 | 215 | | |
| |||
257 | 263 | | |
258 | 264 | | |
259 | 265 | | |
260 | | - | |
| 266 | + | |
261 | 267 | | |
262 | 268 | | |
263 | 269 | | |
| |||
0 commit comments