Fix bug in DrawerView

When attempting to navigate to a drawer item while the drawer's state
is 'opening' or 'closing' results in a state where the underlying navigator's
screen correctly changes but the drawer fails to automatically dismiss itself.

Instead, we should allow the drawer to respond to updates and change it's state
even if it's in the middle of 'opening' or 'closing'.
This commit is contained in:
Solomon Hawk
2018-06-06 13:12:03 -07:00
committed by satyajit.happy
parent cfff4956a2
commit e5ae16dbed

View File

@@ -24,10 +24,10 @@ export default class DrawerView extends React.PureComponent {
const { isDrawerOpen } = this.props.navigation.state;
const wasDrawerOpen = prevProps.navigation.state.isDrawerOpen;
if (isDrawerOpen && !wasDrawerOpen && this._drawerState === 'closed') {
if (this._shouldOpen(isDrawerOpen, wasDrawerOpen)) {
this._drawerState = 'opening';
this._drawer.openDrawer();
} else if (wasDrawerOpen && !isDrawerOpen && this._drawerState === 'open') {
} else if (this._shouldClose(isDrawerOpen, wasDrawerOpen)) {
this._drawerState = 'closing';
this._drawer.closeDrawer();
}
@@ -39,6 +39,22 @@ export default class DrawerView extends React.PureComponent {
_drawerState = 'closed';
_shouldOpen = (isDrawerOpen, wasDrawerOpen) => {
return (
isDrawerOpen &&
!wasDrawerOpen &&
(this._drawerState === 'closed' || this._drawerState === 'closing')
);
};
_shouldClose = (isDrawerOpen, wasDrawerOpen) => {
return (
wasDrawerOpen &&
!isDrawerOpen &&
(this._drawerState === 'open' || this._drawerState === 'opening')
);
};
_handleDrawerOpen = () => {
const { navigation } = this.props;
const { isDrawerOpen } = navigation.state;