Commit 2a90922
authored
[iOS] Remove dropped native handlers (#3819)
## What is happening
While working on #3800 I've noticed frequent crashes on `iOS`. I'll
explain this using the demo from the test code, basically two screens,
second screen has a `RectButton`.
1. Navigate to second screen
2. Go back
3. Navigate to the second screen again
4. App crashes
Sometime it crashes immediately on startup.
## Why is it happening?
`Native` handlers are handled differently compared to others. The main
problem was that we tried to attach handler that was previously dropped,
but `NativeDetector` has no information that this happened. The flow
here looks as follows:
1. We navigate to screen with button
2. `addSubview` is called - at this point it won't attach anything as
`_nativeHandlers` is empty
3. `updateProps` is called - handlers are attached
4. We navigate back to first screen
5. Handler is dropped
6. We navigate again to second screen
7. `addSubview` is called - it tries to attach handler that was dropped,
therefore app crashes
## Solution
To fix this issue, we clear `_nativeHandlers` in `prepareForRecycle`
method.
## Test plan
<details>
<summary>I've tested it on my branch with components re-written to new
API, using the following code in EmptyExample:</summary>
```tsx
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { RectButton } from 'react-native-gesture-handler';
export default function EmptyExample() {
return (
<View style={styles.container}>
<RectButton
style={styles.button}
onPress={() => console.log('Hello World!')}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
button: {
width: 100,
height: 30,
borderRadius: 10,
backgroundColor: 'pink',
},
});
```
</details>1 parent 48e3a79 commit 2a90922
File tree
1 file changed
+17
-5
lines changed- packages/react-native-gesture-handler/apple
1 file changed
+17
-5
lines changedLines changed: 17 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 36 | + | |
41 | 37 | | |
42 | 38 | | |
43 | 39 | | |
| |||
72 | 68 | | |
73 | 69 | | |
74 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
75 | 80 | | |
76 | 81 | | |
77 | 82 | | |
| |||
127 | 132 | | |
128 | 133 | | |
129 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
130 | 142 | | |
131 | 143 | | |
132 | 144 | | |
| |||
0 commit comments