zoo*_*sis 5 javascript node.js react-native react-navigation expo
我使用反应导航库,特别是 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);
Run Code Online (Sandbox Code Playgroud)
watchList 路由包含一个名为符号的 jsonfile,我想将其传递给 alertsScreen.js 中的警报路由
export default class WatchListScreen extends React.Component {
constructor(props) {
super(props)
this.state = {
symbols: [],
}
}
LOTS OF OTHER STUFF
Run Code Online (Sandbox Code Playgroud)
警报屏幕.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>
);
}
}
Run Code Online (Sandbox Code Playgroud)
根据文档,我需要传递数据的行将是这样的
this.props.navigation.navigate('Alerts', {
jsonWatchList: [lots of data here],
});
Run Code Online (Sandbox Code Playgroud)
唯一的问题是我不知道它应该去哪里。
小智 -3
它在您的链接( https://reactnavigation.org/docs/en/params.html )中有详细记录。它解释了如何在路由之间传递参数。使用 astackNavigator或 a并不重要createBottomTabNavigator
像您想要的那样传递您的参数:
this.props.navigation.navigate('jsonWatchList', {
jsonWatchList: [lots of data here],
});
在你的另一个屏幕上,让它们像这样:
const data = this.props.navigation.getParam('jsonWatchList');
| 归档时间: |
|
| 查看次数: |
6411 次 |
| 最近记录: |