问题描述
当前正在使用某个应用程序,该应用程序将为您提供基于幻想api的班级/种族/背景故事.创建项目时,我使用了expo的标签模板.
Am currently working with an app that will provide you with a class/race/background story from an fantasy api. I used expo's tab template when i created the project.
所以我的问题是,我如何将在竞赛"屏幕中获取的数据发送到背景故事屏幕,以获取正确的背景故事?我一直在尝试谷歌搜索,但找不到一个有帮助的答案,我唯一发现的是它与导航器有关,因此为什么我将其链接了.
So my question is how would I send data that i fetched in my Race screen to my background-story screen in order to fetch the correct background-story? I've been trying to googling it but couldnt find an answer that helped, the only thing i found is that its something to do with the navigator, hence why i link it.
Maintabnavigator.js
Maintabnavigator.js
import React from 'react';
import { Platform } from 'react-native';
import { createStackNavigator, createBottomTabNavigator, createDrawerNavigator } from 'react-navigation';
import { Icon } from 'expo';
import { Ionicons} from '@expo/vector-icons';
import HomeScreen from '../screens/HomeScreen';
import CharacterScreen from '../screens/CharacterScreen';
import BackgroundDetails from '../screens/CharacterScreens/BackgroundDetails';
import RaceDetails from '../screens/CharacterScreens/RaceDetails';
import ClassDetails from '../screens/CharacterScreens/ClassDetails';
const RaceStack = createStackNavigator({
race: RaceDetails
});
const ClassStack = createStackNavigator({
class: ClassDetails
});
const BackgroundStack = createStackNavigator({
background: BackgroundDetails
});
const GeneratorStack = createStackNavigator({
generator: CharacterScreen,
});
GeneratorStack.navigationOptions= {
tabBarLabel: 'Generator',
tabBarIcon: ({focused}) => (
<Icon.Entypo
focused={focused}
name={'retweet'}
size={26}
/>
)
}
RaceStack.navigationOptions= {
tabBarLabel: 'Race',
tabBarIcon: ({focused}) => (
<Icon.MaterialIcons
focused={focused}
name={'person'}
size={26}
/>
)
}
ClassStack.navigationOptions= {
tabBarLabel: 'Class',
tabBarIcon: ({focused}) => (
<Icon.MaterialCommunityIcons
focused={focused}
name={'sword-cross'}
size={26}
/>
)
}
BackgroundStack.navigationOptions= {
tabBarLabel: 'Background Story',
tabBarIcon: ({focused}) => (
<Icon.Feather
focused={focused}
name={'book'}
size={26}
/>
)
}
export default createBottomTabNavigator({
GeneratorStack,
ClassStack,
RaceStack,
BackgroundStack,
});
推荐答案
当您从一个屏幕导航到另一个屏幕时,如下所示:
When you navigate from one screen to another as follows:
this.props.navigation.navigate('ContactDisplay', { item });
您可以在另一个屏幕上访问项目",如下所示:
You may access 'item' in the other screen as follows:
console.log(this.props.navigation.state.params.item);
这篇关于屏幕之间的发送状态反应本机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!