已经有段时间没有写 RN, 之前用 Navigation 还是 2.x 版本, 现在已经 6.x .
看到RN 官方有这一段:
This native-stack navigator uses the native APIs:
UINavigationControlleron iOS andFragmenton Android so that navigation built withcreateNativeStackNavigatorwill behave the same and have the same performance characteristics as apps built natively on top of those APIs.
比较疑惑, RN 不是只有一个 RootView 吗? (rootViewController.view = rootView)
之前页面跳转(RN 里面)都是 Navigation 库给做的转场动画, 现在 它是怎么实现的用原生的 API 来做跳转?
猜测: ViewController 如果没有原生的 Navigation 只能 present, 不能 push/pop; 所以应该是做了某些魔法操作, 当用户使用 native-stack 的情况下, 在原生里添加的一层 Navigation.
但具体是怎么做的呢?