Pat*_*nch 5 android ios react-native react-navigation
我只在iOS上收到错误:
TypeError: undefined is not an object (evaluating 'this._callListeners.bind')
This error is located at:
in DrawerLayout (at DrawerView.js:161)
...
Run Code Online (Sandbox Code Playgroud)
项目依赖项:
"dependencies": {
"@babel/runtime": "7.2.0",
"@babel/plugin-proposal-async-generator-functions": "7.2.0",
"@babel/plugin-proposal-class-properties": "7.2.1",
"@babel/plugin-proposal-object-rest-spread": "7.2.0",
"babel-preset-expo": "5.0.0",
"expo": "31.0.2",
"expo-cli": "2.5.0",
"native-base": "2.8.1",
"react": "16.6.3",
"react-native": "0.57.8",
"react-redux": "6.0.0",
"react-navigation": "3.0.8",
"react-native-vector-icons": "6.1.0",
"redux": "4.0.1"
}
Run Code Online (Sandbox Code Playgroud)
这开始于我开始使用反应导航; 但在Android上运行正常.
这是我们使用react-navigation的代码,这是导入包括Home和Settings屏幕的主要应用程序:
//imports...
const routes = {
Home: Home,
Settings: Settings
};
const AppNavigator = createDrawerNavigator(routes);
const AppContainer = createAppContainer(AppNavigator);
export default class App extends React.Component {
state = {}
render() {
if (this.state.isReady) {
return (
<AppContainer/>
);
}
else {
return (<Container><Spinner/></Container>);
}
}
componentWillMount() {
this._loadAssets();
}
async _loadAssets() {
await Expo.Font.loadAsync({
Roboto: require("native-base/Fonts/Roboto.ttf"),
Roboto_medium: require("native-base/Fonts/Roboto_medium.ttf")
});
this.setState({ isReady: true });
}
}
Run Code Online (Sandbox Code Playgroud)
经过大量迭代可能的解决方案后,我终于能够让它发挥作用。
看起来我遇到了一些问题 - 包版本冲突和 .babelrc 配置。
有了这些,我就能够启动并运行了。
package.json 依赖项:
"dependencies": {
"@babel/plugin-proposal-async-generator-functions": "7.2.0",
"@babel/plugin-proposal-class-properties": "7.2.1",
"@babel/plugin-proposal-decorators": "7.2.0",
"@babel/plugin-proposal-object-rest-spread": "7.2.0",
"@babel/plugin-transform-runtime": "7.2.0",
"@babel/runtime": "7.2.0",
"@react-navigation/core": "3.0.2",
"@react-navigation/native": "3.1.0",
"babel-preset-expo": "5.0.0",
"expo": "31.0.6",
"native-base": "2.10.0",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz",
"react-native-vector-icons": "6.1.0",
"react-navigation": "3.0.9",
"react-navigation-drawer": "1.0.5",
"react-redux": "6.0.0",
"redux": "4.0.1"
}
Run Code Online (Sandbox Code Playgroud)
和 .babelrc 在我的根目录中:
{
"presets": ["babel-preset-expo"],
"plugins": [
["module-resolver", {
"root": ["./"],
"alias": {
"_framework": "./framework",
"_apps": "./apps"
}
}]
]
}
Run Code Online (Sandbox Code Playgroud)