gpt4 book ai didi

react-native - react-navigation:禁用模态动画

转载 作者:行者123 更新时间:2023-12-04 04:47:55 27 4
gpt4 key购买 nike

是否可以禁用 React Navigation 的模态动画?

class HomeScreen extends React.Component {
static navigationOptions = ({ navigation }) => {
const params = navigation.state.params || {};

return {
headerLeft: (
<Button
onPress={() => navigation.navigate('MyModal')}
title="Info"
color="#fff"
/>
),
/* the rest of this config is unchanged */
};
};

/* render function, etc */
}

class ModalScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text style={{ fontSize: 30 }}>This is a modal!</Text>
<Button
onPress={() => this.props.navigation.goBack()}
title="Dismiss"
/>
</View>
);
}
}

const MainStack = createStackNavigator(
{
Home: {
screen: HomeScreen,
},
Details: {
screen: DetailsScreen,
},
},
{
/* Same configuration as before */
}
);

const RootStack = createStackNavigator(
{
Main: {
screen: MainStack,
},
MyModal: {
screen: ModalScreen,
},
},
{
mode: 'modal',
headerMode: 'none',
}
);

例子取自React Native官方文档:https://reactnavigation.org/docs/en/modal.html

最佳答案

解决方案

使用 transitionConfig 中的 transitionSpec 进行自定义屏幕过渡。并将过渡持续时间设为零。 Official

示例(未测试)

const ModalNavigator = createStackNavigator(
{
Main: { screen: Main },
Login: { screen: Login },
},
{
headerMode: 'none',
mode: 'modal',
defaultNavigationOptions: {
gesturesEnabled: false,
},
transitionConfig: () => ({
transitionSpec: {
duration: 0,
},
})
...

关于react-native - react-navigation:禁用模态动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53587246/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com