我在 react-native 中遇到了 TabNavigator 和 StackNavigator 的问题。我想在按下按钮时重置导航。我的标签导航中有我的堆栈导航。问题是我只能重置一个导航...
计划:
-tabNavigator
-listing.js
-stackNavigator
-types.js
-picture.js
-ad.js
因此,当我在 ad.js 中单击它时,我有一个按钮,我的 stackNavigation 在 Listing.js 上重置为 type.js 和 tabNavigator 所以我想最终返回 Linsting.js。
我的导航:navigation.js
export const resetAction = NavigationActions.reset({
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'Types'}),
],
key: null
})
export const listingAction = NavigationActions.navigate({
routeName: 'Listing',
})
const Stack = StackNavigator(
{
Types: {screen: SelectTypesScreen},
Picture: {screen: SelectPictureScreen},
Ad: {screen: CreateAd}
})
const Tab = TabNavigator(
{
Listing: {screen: ListingScreen},
Preference: {screen: PreferencesScreen},
Add: {screen : Stack}
},
{
}
)
export default class App extends Component {
render() {
return (
<Tab />
);
}
}
选项卡导航 linsting.js
export default class Listing extends Component {
render() {
return (
<View>
<Text> Listing </Text>
</View>
);
}
}
堆栈导航 ad.js
export default class CreateAd extends Component {
render() {
return (
<View>
<Text style={{marginTop: '80%', marginLeft: '40%'}}> Ad </Text>
<Button title="Ok" onPress={() => {console.log("displayer 1"), this.props.navigation.dispatch(resetAction), console.log("displayer 2"), this.props.navigation.dispatch(listingAction)}} />
</View>
);
}
}