Commit fb1089b
authored
Fix updating
## Description
#4158 added
[`useJSResponderHandler`](https://github.com/software-mansion/react-native-gesture-handler/blob/main/packages/react-native-gesture-handler/src/v3/hooks/useJSResponderHandler.ts).
The problem here is that `notifyEnabledChanged` is initialized as
`runOnJS`, and then passed to UI. `runOnJS` should be executed on UI,
otherwise app throws error:
```
Error: [Worklets] Tried to synchronously call a Remote Function. Called "anonymous" on the UI Runtime.
222-E/ReactNativeJS(28820): See https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#tried-to-synchronously-call-a-remote-function for more details.
```
## Test plan
<details>
<summary>Tested on the following example:</summary>
```tsx
import React, { useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import {
GestureDetector,
Touchable,
usePanGesture,
} from 'react-native-gesture-handler';
import Animated, { useSharedValue } from 'react-native-reanimated';
export const COLORS = {
offWhite: '#f8f9ff',
headerSeparator: '#eef0ff',
PURPLE: '#b58df1',
DARK_PURPLE: '#7d63d9',
NAVY: '#001A72',
RED: '#A41623',
YELLOW: '#F2AF29',
GREEN: '#0F956F',
DARK_GREEN: '#217838',
GRAY: '#ADB1C2',
KINDA_RED: '#FFB2AD',
DARK_SALMON: '#d97973',
KINDA_YELLOW: '#FFF096',
KINDA_GREEN: '#C4E7DB',
KINDA_BLUE: '#A0D5EF',
LIGHT_BLUE: '#5f97c8',
WEB_BLUE: '#1067c4',
ANDROID: '#34a853',
};
export default function SharedValueEnabledExample() {
const enabled = useSharedValue(true);
const [enabledLabel, setEnabledLabel] = useState(true);
const pan = usePanGesture({ enabled });
return (
<View style={styles.container}>
<Touchable
onPress={() => {
enabled.value = !enabled.value;
setEnabledLabel(!enabledLabel);
}}
style={{
padding: 16,
backgroundColor: COLORS.WEB_BLUE,
borderRadius: 8,
}}
/>
<Text style={styles.status}>{`enabled: ${enabledLabel}`}</Text>
<GestureDetector gesture={pan}>
<Animated.View style={[styles.box]} />
</GestureDetector>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
paddingTop: 24,
},
status: {
fontSize: 18,
marginVertical: 16,
},
box: {
width: 160,
height: 160,
borderRadius: 16,
backgroundColor: COLORS.PURPLE,
},
});
```
</details>SharedValue crash (#4315)1 parent 98cb1e7 commit fb1089b
2 files changed
Lines changed: 9 additions & 5 deletions
File tree
- packages/react-native-gesture-handler/src
- handlers/gestures
- v3/hooks
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| |||
Lines changed: 7 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
67 | 69 | | |
68 | | - | |
| 70 | + | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
73 | | - | |
| 75 | + | |
74 | 76 | | |
75 | 77 | | |
| 78 | + | |
| 79 | + | |
76 | 80 | | |
77 | 81 | | |
78 | 82 | | |
| |||
0 commit comments