reactjs - React-native-navigation 导航时更改屏幕方向

标签 reactjs react-native react-native-navigation

导航屏幕时的默认屏幕动画是从右到左的屏幕。在某些情况下,我希望屏幕在导航时执行不同的操作,例如从左到右或从下到上。 如何更改屏幕动画以在导航时从屏幕左侧转到屏幕右侧或从下到上?

我提供了snack example here这准确地再现了我想要做的事情以及下面的一些代码。

感谢您提供的任何见解,我比您知道的更感激。

<Stack.Navigator
     initialRouteName="Home">       
      <Stack.Screen name="Home" component= {Home} options={{headerShown: false}}/>
      <Stack.Screen name="Screen2" component= {Screen2} options={{headerShown: false}}/>
    </Stack.Navigator>


<TouchableOpacity onPress={() => this.props.navigation.navigate('Screen2')}>
        <Text style={{fontSize: 20, fontWeight: 'bold', color: 'white'}}>
            Press me to navigate, I want to be able to change the direction the screen comes in from, like left to right or bottom to top.
        </Text>
        </TouchableOpacity>

最佳答案

您可以使用cardStyleInterpolator属性来实现屏幕动画。在下面的示例中,页面将从左向右滚动。

例如:

<Stack.Navigator 
   initialRouteName="Home"
   screenOptions={{
    cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS,
  }}
>       
      <Stack.Screen name="Home" component= {Home} options={{headerShown: false}}/>
      <Stack.Screen name="Screen2" component= {Screen2} options={{headerShown: false}}/>
</Stack.Navigator>

可以使用什么(cardStyleInterpolator):

forBottomSheetAndroid
forFadeFromBottomAndroid
forFadeFromCenter
forHorizontalIOS
forModalPresentationIOS
forNoAnimation
forRevealFromBottomAndroid
forScaleFromCenterAndroid
forVerticalIOS

关于reactjs - React-native-navigation 导航时更改屏幕方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71280584/

相关文章:

javascript - JS Filter/Map 获取之间的对象

reactjs - Apollo React 使用查询结果调用异步函数

android - this.props.logged in 不是未定义的函数

react-native - react native : Unable to resolve module ./CameraRollView

android - 无法在空对象 : react. gradle 上调用方法 doFirst()

javascript - 错误 : A navigator can only contain 'Screen' components as its direct children

javascript - 从无状态功能组件动态渲染按钮

reactjs - 查看或打开存储在本地 Expo React Native 的 PDF 文件

react-native - 如何在android上正确安装react-native-navigation

android - 在平板电脑等大型设备上始终显示侧边菜单(抽屉)[react-native-navigation]