问题
I'm trying to create a swipe navigation between different screens from a same StackNavigator
when i set swipeEnabled:true
in navigationOptions
, my app rather navigate between different Tabs.
I'd rather want to navigate inside a same stack from Screen A
to Screen B
for example.
How can i do this trick ?
回答1:
I had the same use case. I wanted a swipaeable <StackNavigator>
. The solution I was able to find was to simulate a <StackNavigator>
using a <TabNavigator>
, or more specifically, using createMaterialTopTabNavigator()
.
What I did was to create this tab (which is the only in the react-navigation 2 which allows swipeEnabled
) and added display: none
to its style. This way I can have a <TabNavigator>
that behaves like a <StackNavigator>
.
This is the code:
const SwipeableNavigator = createMaterialTopTabNavigator({
FrontCard: FrontCardScreen,
BackCard: BackCardScreen
},
{
swipeEnabled: true,
tabBarOptions: {
style: { display: "none" }
}
});
And then just call <SwipeableNavigator />
wherever you want.
来源:https://stackoverflow.com/questions/51483105/how-to-swipe-horizontally-inside-stacknavigator-screens