我无法让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)...')
为什么标签导航器不起作用?
注意:如果我使用堆栈导航器替换Tab导航器的所有实例,则错误消失。但是我需要一个标签导航器,而不是一个堆栈导航器
答案 0 :(得分:1)
尝试从package.json中删除react-navigation包,然后安装react-navigation。希望它有所帮助。
执行此操作后,您会注意到package.json将列出特定版本的react-natigation,而不仅仅是指向存储库的链接
答案 1 :(得分:0)
在v2以上的react-navigation中,一个新的TabNavigator是介绍器,您可以使用createMaterialTopTabNavigator
在屏幕顶部创建TabNavigator。
import {createMaterialTopTabNavigator} from "react-navigation";
const TabsAB = createMaterialTopTabNavigator({
Tab_A: {
screen: ScreenA,
....