Repository navigation
fix(rn): 修复 MpxNav 在折叠屏场景下首页返回失效 - #2619
Open
mackwang112 wants to merge 1 commit into
Open
mackwang112 wants to merge 1 commit into
mackwang112 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题描述
在滴滴出行 App 的 DRN 容器中,Mpx demo 从二级页面返回首页后,首页导航栏返回按钮可能无法调用
onStackTopBack()退出容器。折叠、展开设备触发安全区更新时更容易复现。原实现通过渲染时读取的
navigation.getState().routes.length判断是否为首页,但栈总长度并不代表当前页面在栈中的位置。二级页面打开时,后台仍挂载的首页会因安全区更新而重渲染,捕获栈长度2;返回首页后,真实栈长度已为1,导航栏没有订阅状态变化,点击回调仍使用旧值并执行goBack(),导致无法退出容器。埋点已确认出现“回调捕获栈长度为 2,点击现场 getState() 栈长度为 1”的情况,导航器的真实栈已正确更新。
复现方式
报告环境:滴滴出行 App DRN 容器、iPhone Duo 折叠屏模拟器、iOS 27.1、React 18.3.1、React Native 0.77.2,
@mpxjs/core/@mpxjs/webpack-plugin为 2.10.20-beta.2。在二级页面先折叠、再展开、最后返回首页,也可能复现。二级页面能正常返回首页,不代表首页退出容器正常。
预期:首页返回按钮调用
onStackTopBack()退出 DRN 容器;非首页返回按钮调用navigation.goBack()。修复方案
useRoute()获取当前页面路由,通过useNavigationState(state => state.routes[0].key === route.key)订阅当前页面是否为栈底首页。isFirstPage,首页身份不随二级页面入栈改变,也能跟随导航状态更新。redirectTo首页路径时被误认为栈底首页。@react-navigation/native导入,补齐现有类型声明,并更新相关测试。测试结果
DRN 容器回归(用户提供)
redirectTo首页路径redirectTo其他页面reLaunch首页本地自动检查
git diff --check:通过。jest --watchman=false --config packages/webpack-plugin/jest.config.json --runInBand packages/webpack-plugin/test/runtime/react-native/mpx-nav.spec.ts:3 项通过,覆盖配置合并、二级页面打开及返回期间的首页身份、按钮显示和订阅清理。jest --watchman=false --config packages/core/jest.config.json --runInBand packages/core/__tests__/rn/createApp.spec.js:25 项通过。