How to swipe horizontally inside stackNavigator screens?

断了今生、忘了曾经 提交于 2020-01-03 17:21:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!