【发布时间】:2019-08-23 13:47:08
【问题描述】:
我正在使用 react 导航库,特别是 createBottomTabNavigator
https://reactnavigation.org/docs/en/params.html 的文档解释了如何使用堆栈导航器在路由之间传递参数,但我使用的是选项卡导航器,但我找不到任何可以解释如何在选项卡导航设置中执行此操作的内容
我在 App.js 中的标签导航器是
const BottomTabMenu = createBottomTabNavigator (
{
WatchList: { screen: WatchListScreen },
Alerts: { screen: AlertsScreen },
Analytics: { screen: AnalyticsScreen },
Settings: { screen: SettingsScreen },
},
{
initialRouteName: 'WatchList',
defaultNavigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, horizontal, tintColor }) => {
const { routeName } = navigation.state;
let IconComponent = Ionicons;
let iconName;
if (routeName === 'WatchList') { iconName = 'md-list'; }
if (routeName === 'Alerts') { iconName = 'md-alert'; }
if (routeName === 'Analytics') { iconName = 'md-analytics'; }
if (routeName === 'Settings') { iconName = 'md-settings'; }
return <IconComponent name={iconName} size={25} color={tintColor} />;
},
}),
tabBarOptions: {
activeTintColor: 'tomato',
inactiveTintColor: 'gray',
},
}
);
const AppContainer = createAppContainer(BottomTabMenu);
watchList 路由包含一个名为 symbols 的 json 文件,我想将它传递给 alertsScreen.js 中的 alerts 路由
export default class WatchListScreen extends React.Component {
constructor(props) {
super(props)
this.state = {
symbols: [],
}
}
LOTS OF OTHER STUFF
ALERTSSCREEN.JS
export default class AlertsScreen extends React.Component {
render() {
//according to the docs, this is how to receive in the props
const { navigation } = this.props;
const jsonWatchList = navigation.getParam('jsonWatchList', '[]');
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>blah blah blah</Text>
</View>
);
}
}
根据文档,我需要传递数据的行是这样的
this.props.navigation.navigate('Alerts', {
jsonWatchList: [lots of data here],
});
唯一的问题是我不知道它应该去哪里。
【问题讨论】:
标签: javascript node.js react-native react-navigation expo