栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在反应导航中禁用后退按钮

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在反应导航中禁用后退按钮

1)要使后退按钮在react-navigation v2或更高版本中消失:

navigationOptions:  {    title: 'MyScreen',    headerLeft: null}

2)如果您要清理导航堆栈:

假设您位于要从其导航的屏幕上:

如果您使用的是反应导航版本v5或更高版本 ,则可以使用

navigation.reset
CommonActions.reset

 // Replace current navigation state with a new one, // index value will be the current active route:navigation.reset({  index: 0,  routes: [{ name: 'Profile' }],});

来源和更多信息在这里:https :
//reactnavigation.org/docs/navigation-
prop/#reset

要么:

navigation.dispatch(  CommonActions.reset({    index: 1,    routes: [      { name: 'Home' },      {        name: 'Profile',        params: { user: 'jane' },      },    ],  }));
来源和更多信息在这里:https
//reactnavigation.org/docs/navigation-
actions/#reset

对于旧版本的反应导航:

v2-v4 使用

StackActions.reset(...)

import { StackActions, NavigationActions } from 'react-navigation';const resetAction = StackActions.reset({  index: 0, // <-- currect active route from actions array  actions: [    NavigationActions.navigate({ routeName: 'myRouteWithDisabledBackFunctionality' }),  ],});this.props.navigation.dispatch(resetAction);

v1 使用

NavigationActions.reset

3)对于Android,您还必须使用BackHandler禁用硬件后退按钮

http://reactnative.dev/docs/backhandler.html

或者如果您想使用钩子:

https://github.com/react-native-
community/hooks#usebackhandler

否则,如果导航堆栈为空,则应用将在按android硬件后退按钮时关闭。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/485103.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号