react-native - 我如何跳过动画只替换为反应导航
问题描述
我正在使用@react-navigation/stack^5.14.4
and@react-navigation/native^5.9.4
来处理主页、登录和个人资料页面之间的场景转换。
我需要处理 2 个过渡案例:
- 主页 -> 个人资料(应该启用动画)
- 登录 -> 个人资料(需要跳过动画)
跳过动画的原因是我在登录过程中使用了类似于配置文件页面布局的加载骨架。在个人资料页面内容和骨架本身之间进行转换是很奇怪的。但是,如果从主页推送,我想保留很棒的动画。
有没有像这样的简单解决方案
navigation.replace("Profile"); // with animation
navigation.replace("Profile", { animationEnabled: false }); // skip animation
解决方案
您可以使用选项来获取路线属性并检查天气是否有任何参数可以禁用屏幕
小蛇:https ://snack.expo.dev/@ashwith00/react-navigation-5-boilerplate
这是一个例子
function TestScreen({ navigation }) {
return (
<View style={styles.content}>
<Button
mode="contained"
onPress={() => navigation.push('Test1', {disabledAnimation: true})}
style={styles.button}>
Push screen Without Animation
</Button>
<Button
mode="contained"
onPress={() => navigation.push('Test1')}
style={styles.button}>
Push new screen
</Button>
{navigation.canGoBack() ? (
<Button
mode="outlined"
onPress={() => navigation.pop()}
style={styles.button}>
Go back
</Button>
) : null}
</View>
);
}
const Stack = createStackNavigator();
function MyStack() {
return (
<Stack.Navigator>
<Stack.Screen
name="Test"
component={TestScreen}
options={{ title: 'Custom animation' }}
/>
<Stack.Screen
name="Test1"
component={TestScreen}
options={({ route }) => ({
title: 'Custom animation',
cardStyleInterpolator: !route.params?.disabledAnimation
? undefined
: CardStyleInterpolators.forNoAnimation,
})}
/>
</Stack.Navigator>
);
}
推荐阅读
- javascript - 无法提交使用 Javascript 类验证的 HTML 表单
- ios - 支持 iOS 上 PWA 的 Service Worker 和推送通知
- typescript - TypeScript 包含不应该包含的文件?
- ios - 如何检查我的应用程序是否由 WatchOS 上的 Siri 快捷方式启动?
- hyperledger-fabric - 如何部署 Web 应用程序以与 hyperledger fabric v1.4 交互?
- java - 如何将日期时间字符串转换为“yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSSZ”
- javascript - 使用反应和时刻的计时器
- orm - 使用django查询某个操作的q时出现意外情况
- opengl - 用什么着色器来计算关于图元的东西?
- java - 在“何时”块中运行 Platform.runLater() 的 Spock 计时问题