Limitations
作为 library 的潜在用户,了解你可以做什么和不可以做什么很重要。 有了这些知识,你可以选择采用 不同的库 。 我们在优点 & 缺点这一章节讨论了高级设计决策,在这里我们将介绍一些不支持或难以实现的用例,这些用例可能是无法实现的。 如果你的应用有以下任何限制,则 React Navigation 可能不适合你。
动态路由
It's not a limitation anymore with React Navigation 5 which uses a new component based API to be able to support this use case.
这需要对 React Navigation 有一点了解才能充分发挥。
React Navigation 要求你静态地定义你的路由,如下所示:
const FriendsNavigator = createDrawerNavigator({
Feed: FeedScreen,
FriendList: FriendListScreen,
});
const AuthNavigator = createStackNavigator({
SignIn: SignInScreen,
ForgotPassword: ForgotPasswordScreen,
});
const AppNavigator = createSwitchNavigator({
App: FriendsNavigator,
Auth: AuthNavigator,
});
const AppContainer = createAppContainer(AppNavigator);
export default class MyApp extends React.Component {
render() {
return <AppContainer />;
}
}
比方说,当用户登录应用程序时,你需要获取用户的好友列表,并在FriendsNavigator
中为每个好友页面添加路由。 这将使得每个好友在 drawer 中有一个带有好友名称的按钮。 React Navigation 目前不提供简单的方法来执行此操作。 目前情况下,当你的路由可以静态定义时,React Navigation使用效果最好。 请记住,这并不意味着你不能传递任何数据给路由 — 可以使用 params 进行此操作。
如果你一定要使用动态路由,也有解决方案,但可能会有一些额外的复杂度。
带有大文本的 iOS 11 样式标题栏
React Navigation 5 includes a new native stack navigator which uses the platform navigation primitives. It supports the native large title on iOS.
这是实施的路线图,但目前在 React Navigation 中不可用。 这里有几个构建了自己的版本的 fork ,但你的里程可能会有所不同。
Right-to-left (RTL) 布局支持
We try to handle RTL layouts properly in React Navigation, however the team working on React Navigation is fairly small and we do not have the bandwidth or processes at the moment to test all changes against RTL layouts. So you might encounter issues with RTL layouts.
如果您喜欢React Navigation提供的内容,但由于此限制而被关闭,我们鼓励你参与并获得 RTL 布局支持的所有权。 请在 Twitter 上联系我们: @reactnavigation。
性能限制
React Navigation 5 includes a new native stack navigator which uses the platform navigation primitives. While the customization options are limited with it, the performance is close to native.
我们可以使用 React Native 的原生动画驱动程序将动画分流到另一个线程,但我们目前仍然需要回到 JavaScript 中进行手势操作(尽管有计划在不久的将来对此进行补救)。 React Navigation 完全由 React 组件组成,并且 state 在 JavaScript 中以与应用程序的其余部分相同的线程进行管理。 这使得 React Navigation 在很多方面都很出色,但这也意味着你的应用程序逻辑通过 React Navigation 争取 CPU 时间 — 每帧只有很多 JavaScript 执行时间可用。
微妙的平台特定行为
React Navigation does not include support for the peek & pop feature available on devices with 3D touch.