react-navigation / react-navigation/react-navigation.github.io
Recommended patterns for menus and dialogs
未关闭
@brentvatne 已经在做这个了。
开始于 2018年2月6日。
help wanted
high-priority
- 主要语言
- JavaScript
- 星标
- 324
- 派生
- 2k
- PR 合并指标
- 30 天内没有已合并 PR
描述
Copied from https://github.com/react-navigation/react-navigation/issues/1315
The preferred pattern for handling dialogs and menus don't seem to have been discussed yet.
Menus that open from a menu button are a fairly common pattern.
I can see 2 possible ways they might be implemented:
- As part of params: Menu is part of a scene's children, headerRight uses
setParamsto set a param indicating the menu is open and that param is passed to whatever prop on the menu indicates it is open. Closing the menu is anothersetParams. One would have to either use<Modal />or manually register aBackAndroid(nowBackHandler) to handle the Android "back button closes menu instead of navigating backwards" pattern. - As a navigator: Menus are implemented as a part of a MenuNavigator (or maybe a ModalNavigator), the navigator is used in place of the screen for a route in your {Stack,Drawer,Tab}Navigator and accepts one route that is the normal screen and other routes are menus. Menus are opened using
navigator.navigate('MenuName')and exited usingnavigator.goBack().
Dialogs are another modal type to consider (given the drawer is already considered a navigator).
Drawers make less sense as part of props but there are still 2-3 patterns I can think of for them:
- A DialogNavigator: Just like the MenuNavigator/ModalNavigator I described a DialogNavigator would be used in place of a normal screen and allow
navigator.navigateto open a specific dialog from the associated screen. - A top-level DialogNavigator: Instead of taking place of a deeper screen, the DialogNavigator would be top-level like the DrawerNavigator is. This would allow it to easily sit on top of everything else and put dialogs on top. Dialogs would become global, which could be a pro or a con depending on the app.
- As part of StackNavigator: Instead of a whole separate navigator StackNavigator would be modified to support modals (routes that can have no headers of their own, are drawn transparently over top of the other screens, and have a separate transition type). From the nesting and navigation perspectives this is a little simpler. There is no extra nesting of navigators that could make
navigation.navigatecalls more complex in any scenario, opening a dialog by navigating to it is simple, and closing a dialog vianavigator.goBack()is built-in. Also this would already handle full-screen dialogs pretty well and handle the tablet+mobile environment where a route may be a full-screen dialog with a header in the stack route on mobile but be a dialog on a tablet without a header.
Full-screen dialogs themselves are probably a separate more precise discussion.
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
评估
这个 Issue 还没有评估数据。