我无法让 TabNavigator 在 iOS 上运行,尽管它在 Android 上运行良好。这是我重现问题的步骤
打开终端窗口。
react-native init tabnav
cd tabnav
rm -rf node_modules
rm -rf package.json
rm -rf package-lock.json
然后我打开package.json
并粘贴以下内容:
{
"name": "tabnav",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.0.0-beta.5",
"react-native": "0.49.3",
"react-navigation": "git+https://github.com/react-community/react-navigation.git"
},
"devDependencies": {
"babel-jest": "22.4.1",
"babel-preset-react-native": "4.0.0",
"jest": "22.4.2",
"react-test-renderer": "16.3.0-alpha.1"
},
"jest": {
"preset": "react-native"
}
然后我打开App.js
并粘贴内容:
import React, { Component } from 'react';
import {TabNavigator} from 'react-navigation';
import {
Text,
View
} from 'react-native';
type Props = {};
class Page extends Component<Props> {
render() {
return (
<View style={{flex:1}}>
<Text>
Welcome to React Native!
</Text>
</View>
);
}
}
const Navigator = TabNavigator({
Recent: {screen: Page},
Popular:{screen:Page}
}
);
export default Navigator;
然后我打开 Xcode 项目,清理并运行该项目。
然后我得到这个错误:
undefined 不是函数(在'...(0,_reactNavigation.TabNavigator)...'附近)
为什么标签导航器不起作用?
注意:如果我用堆栈导航器替换选项卡导航器的所有实例,错误就会消失。但我需要一个标签导航器,而不是堆栈导航器