0

Android 模拟器环境:Pixel_3_XL_API_29

每当我在基于 expo 的应用程序中使用任何反应导航组件(例如堆栈或抽屉)时,并用鼠标单击屏幕上的任意位置时,它都会崩溃。如果我删除

<AppContainer /> 

在下面的示例中,并将其替换为

<LoginScreen/>

,一切正常。注意:LoginScreen 只是一个没有任何逻辑的空白屏幕。

我可以在 adb 日志中看到以下错误

02-13 15:52:32.562   751   751 E MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
02-13 15:52:32.562   751   751 E MessageQueue-JNI: java.lang.IllegalStateException: Already prepared or hasn't been reset
02-13 15:52:32.562   751   751 E MessageQueue-JNI:      at abi36_0_0.host.exp.exponent.modules.api.components.gesturehandler.GestureHandler.prepare(GestureHandler.java:7)
02-13 15:52:32.562   751   751 E MessageQueue-JNI:      at abi36_0_0.host.exp.exponent.modules.api.components.gesturehandler.GestureHandlerOrchestrator.recordHandlerIfNotPresent(GestureHandlerOrchestrator.java:8)
02-13 15:52:32.562   751   751 E MessageQueue-JNI:      at abi36_0_0.host.exp.exponent.modules.api.components.gesturehandler.GestureHandlerOrchestrator.recordViewHandlersForPointer(GestureHandlerOrchestrator.java:5)
02-13 15:52:32.562   751   751 E MessageQueue-JNI:      at abi36_0_0.host.exp.exponent.modules.api.components.gesturehandler.GestureHandlerOrchestrator.traverseWithPointerEvents(GestureHandlerOrchestrator.java:12)
02-13 15:52:32.562   751   751 E MessageQueue-JNI:      at abi36_0_0.host.exp.exponent.modules.api.components.gesturehandler.GestureHandlerOrchestrator.extractGestureHandlers(GestureHandlerOrchestrator.java:5)
02-13 15:52:32.562   751   751 E MessageQueue-JNI:      at abi36_0_0.host.exp.exponent.modules.api.components.gesturehandler.GestureHandlerOrchestrator.onTouchEvent(GestureHandlerOrchestrator.java:4)
02-13 15:52:32.562   751   751 E MessageQueue-JNI:      at abi36_0_0.host.exp.exponent.modules.api.components.gesturehandler.react.RNGestureHandlerRootHelper.dispatchTouchEvent(RNGestureHandlerRootHelper.java:2)
02-13 15:52:32.562   751   751 E MessageQueue-JNI:      at abi36_0_0.host.exp.exponent.modules.api.components.gesturehandler.react.RNGestureHandlerRootView.dispatchTouchEvent(RNGestureHandlerRootView.java:1)
02-13 15:52:32.562   751   751 E MessageQueue-JNI:      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
02-13 15:52:32.562   751   751 E MessageQueue-JNI:      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2698)

包.json

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start -c",
    "doctor": "expo doctor",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@react-native-community/masked-view": "0.1.5",
    "react-navigation-stack": "2.1.1",
    "react-navigation": "4.1.1",
    "axios": "0.19.2",
    "debounce": "1.2.0",
    "expo": "~36.0.0",
    "expo-secure-store": "~8.0.0",
    "native-base": "^2.13.8",
    "react": "~16.9.0",
    "react-dom": "~16.9.0",
    "react-native": "^0.61.5",
    "react-native-gesture-handler": "~1.5.0",
    "react-native-reanimated": "~1.4.0",
    "react-native-safe-area-context": "0.6.0",
    "react-native-screens": "2.0.0-alpha.12",
    "uuid": "3.4.0"
  },
  "devDependencies": {
    "babel-preset-expo": "~8.0.0",
    "@babel/core": "^7.0.0"
  },
  "private": true
}

应用程序.js

import 'react-native-gesture-handler';
import React from "react";
import { AppLoading } from "expo";
import * as Font from "expo-font";
import { Ionicons } from "@expo/vector-icons";
import MainMenu from './MainMenu'
import LoginScreen from './LoginScreen'
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';

 const navi = createStackNavigator({
 Login: {
    screen: LoginScreen,
  },
  Menu: {
    screen: MainMenu,
  }
}, {
    initialRouteName: 'Login',
  });


const AppContainer = createAppContainer(navi);

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      isReady: false
    };
  }
  async componentDidMount() {
    await Font.loadAsync({
      Roboto: require("native-base/Fonts/Roboto.ttf"),
      Roboto_medium: require("native-base/Fonts/Roboto_medium.ttf"),
      Ionicons: require("native-base/Fonts/Ionicons.ttf")
    });
    this.setState({ isReady: true });
  }
  render() {
    if (!this.state.isReady) {
      return <AppLoading />;
    }
    return (<AppContainer />);
  }
}

登录屏幕

import React from "react";
import { Container, Header, Body, Title, List, ListItem, Content, Text } from "native-base";
export default class MainMenu extends React.Component {
  constructor(props) 
  {
    super(props);
  }
  render() {
    return (
      <Container>
              <Header>
          <Body>
            <Title>Test</Title>
          </Body>
        </Header>
       <Content>
        </Content>
      </Container>
  );
  }
}

注意:我在 react-navigation 4 和 5 中遇到同样的错误

4

2 回答 2

0

我有同样的错误。问题出在react-native-gesture-handler包的某个地方,正如我所见,它还没有解决。

降级到版本1.4.0或尝试此解决方案

import 'react-native-gesture-handler';
...
if (Platform.OS === 'android') {
  const { UIManager } = NativeModules;
  if (UIManager) {
    // Add gesture specific events to genericDirectEventTypes object
    // exported from UIManager native module.
    // Once new event types are registered with react it is possible
    // to dispatch these events to all kind of native views.
    UIManager.genericDirectEventTypes = {
      ...UIManager.genericDirectEventTypes,
      onGestureHandlerEvent: { registrationName: 'onGestureHandlerEvent' },
      onGestureHandlerStateChange: {
        registrationName: 'onGestureHandlerStateChange',
      },
    };
  }
}
于 2020-02-19T20:30:56.720 回答
0

您是否尝试过清除缓存?

运行以下命令:

expo start -c

如果它不起作用,请尝试删除您的 node_modules 和 yarn.lock,然后重试。

于 2020-02-14T00:32:20.743 回答