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 中遇到同样的错误