【发布时间】:2018-07-14 23:06:48
【问题描述】:
我正在使用 React 导航。我需要从 screen1 导航到 screen2。我创建了包含一些屏幕但不包含 screen1 的选项卡导航。当我单击 screen1 中的按钮转到 screen2 时,该按钮应显示在选项卡式屏幕中,它显示错误。
这是 screen1(Main.js)
import React, { Component } from 'react';
import {
ImageBackground,
StyleSheet,
Text,
View,
Modal
} from 'react-native';
import { Container, Header, Left, Content, Footer, FooterTab, Icon, Grid, Row, Button } from 'native-base';
import TabNav from '../screens/Dashboard';
import { Dashboard } from '../screens/Dashboard';
export default class Main extends Component<{}> {
render() {
return (
<Container>
<Grid>
<Row size={2}>
<View style={{alignItems: 'center', flexDirection: 'column', flex: 1, justifyContent: 'space-around' }}>
<View style={{flexDirection: 'row', alignItems: 'center', justifyContent: 'center'}}>
<Button style={styles.buttonBrowseStyle} onPress={() => this.props.navigation.navigate('Dashboard')}>
<Text>Browse</Text>
</Button>
</View>
</View>
</Row>
</Grid>
</Container>
);
}
}
这是 screen2(Dashboard.js)
import React from 'react';
import { Text } from 'react-native';
import { TabNavigator, TabBarBottom } from 'react-navigation';
import Post from './Post';
export const Dashboard = () => {
return (<Text>Dashboard</Text>);
}
const TabNav = TabNavigator ({
Dashboard: {
screen: Dashboard,
},
Post: {
screen: Post,
},
},
{
tabBarComponent: TabBarBottom,
tabBarPosition: 'bottom',
swipeEnabled: false,
animationEnabled: true,
activeBackgroundColor: 'yellow',
tabBarOptions: {
activeTintColor: 'tomato',
inactiveTintColor: 'gray',
},
tabBarIcon: ({focused, tintColor}) => {
const { routeName } = navigation.state;
let iconName;
if(routeName==='Main'){
}
}
}
);
export default TabNav;
点击“浏览”按钮时出现此错误。
【问题讨论】:
-
您似乎没有在任何地方使用
TabNav。此外,Main 不在导航树中。我认为您需要更仔细地阅读文档。 -
@Kraylog 我在 screen1(Main.js) 中包含了 TabNav,但它不提供任何导航道具。我也不想在 TabNav 中提及我的 Main.js,因为它会与其他选项卡创建一个新选项卡。
-
导航道具仅提供给在导航器中配置的屏幕。由于
Main不在任何导航器中,因此它没有获得该道具。要解决这个问题,您必须重新考虑导航树的结构。
标签: react-native react-navigation