使用react-native-gesture-handler长按时Expo Go应用程序崩溃

问题描述 投票:0回答:1

仅在使用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 模拟器进行测试。

react-native expo
1个回答
0
投票

使用 runOnJS(true)。

const longPressGesture = Gesture.LongPress().runOnJS(true).onEnd((_e, success) => {
  if (success) {
    router.push('/products/edit'); // Crashes resolved
  }
});
© www.soinside.com 2019 - 2024. All rights reserved.