仅在使用router.push时发生崩溃;当替换为 console.log() 时不会发生。
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
import { router } from 'expo-router';
// ...
const longPressGesture = Gesture.LongPress().onEnd((_e, success) => {
if (success) {
router.push('/products/edit'); // Crashes here
}
});
// ...
<GestureDetector gesture={longPressGesture}>
<ScrollView>
{products.map((product, index) => (
<Card key={index} />
))}
</ScrollView>
</GestureDetector>
使用的react-native-gesture-handler
版本是2.14.0
和 expo
版本是 50.0.5
我已经用
GestureHandlerRootView
包裹了根布局并使用 Expo Go 模拟器进行测试。
使用 runOnJS(true)。
const longPressGesture = Gesture.LongPress().runOnJS(true).onEnd((_e, success) => {
if (success) {
router.push('/products/edit'); // Crashes resolved
}
});