Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/toggle #2492

Merged
merged 2 commits into from
Aug 30, 2017
Merged

Feature/toggle #2492

merged 2 commits into from
Aug 30, 2017

Conversation

GantMan
Copy link

@GantMan GantMan commented Aug 29, 2017

Every drawer menu needs a toggle. Especially when navigating to a drawer 'DrawerOpen' twice can cause bugs/issues. To solve this currently everyone needs to know about drawer state and structure, which causes code to look like so:

    headerLeft: <Text onPress={() => {
      if (navigation.state.index === 0) {
        navigation.navigate('DrawerOpen')
      } else {
        navigation.navigate('DrawerClose')
      }
    }}>
      Toggle Drawer
    </Text>

This is not readable or future-proof. Instead toggle should be a first class citizen of drawers.

    headerLeft: <Text onPress={() => navigation.navigate('DrawerToggle')}/>
        Toggle Drawer
    </Text>

That is what this PR includes. Also updates docs.

@GantMan GantMan requested review from skevy and grabbou August 29, 2017 18:40
@@ -63,6 +63,12 @@ export default class DrawerView<T: *> extends PureComponent<void, Props, void> {
const { routes, index } = nextProps.navigation.state;
if (routes[index].routeName === 'DrawerOpen') {
this._drawer.openDrawer();
} else if (routes[index].routeName === 'DrawerToggle') {
if (this._drawer.state.drawerShown) {
this.props.navigation.navigate('DrawerClose');

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

@spencercarli spencercarli merged commit 8fdfc6d into master Aug 30, 2017
@spencercarli spencercarli deleted the feature/toggle branch August 30, 2017 02:55
sourcecode911 pushed a commit to sourcecode911/react-navigation that referenced this pull request Mar 9, 2020
* add toggle functionality

* add documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants