mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-03-27 22:56:07 +08:00
Fix drawer closing behavior
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import * as React from 'react';
|
||||
import Expo from 'expo';
|
||||
import { FlatList } from 'react-native';
|
||||
import { createStackNavigator } from 'react-navigation';
|
||||
import { createSwitchNavigator, createStackNavigator } from 'react-navigation';
|
||||
import { ListSection, Divider } from 'react-native-paper';
|
||||
import SimpleDrawer from './src/SimpleDrawer';
|
||||
|
||||
@@ -35,8 +35,8 @@ class Home extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
const App = createStackNavigator({
|
||||
Home,
|
||||
const App = createSwitchNavigator({
|
||||
Home: createStackNavigator({ Home }),
|
||||
...data.reduce((acc, it) => {
|
||||
acc[it.routeName] = {
|
||||
screen: it.component,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"expo": {
|
||||
"name": "React Navigation Material Bottom Tabs Example",
|
||||
"name": "React Navigation Drawer Example",
|
||||
"description": "Demonstrates the various capabilities of react-navigation-drawer",
|
||||
"slug": "react-navigation-drawer-demo",
|
||||
"sdkVersion": "27.0.0",
|
||||
|
||||
@@ -16,6 +16,10 @@ const MyNavScreen = ({ navigation, banner }) => (
|
||||
title="Open other screen"
|
||||
/>
|
||||
<Button onPress={() => navigation.goBack(null)} title="Go back" />
|
||||
<Button
|
||||
onPress={() => navigation.navigate('Home')}
|
||||
title="Go back to list"
|
||||
/>
|
||||
</SafeAreaView>
|
||||
<StatusBar barStyle="default" />
|
||||
</ScrollView>
|
||||
|
||||
@@ -22,13 +22,17 @@ export default class DrawerView extends React.PureComponent {
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
const { isDrawerOpen } = this.props.navigation.state;
|
||||
const { isDrawerOpen, key } = this.props.navigation.state;
|
||||
const prevKey = prevProps.navigation.state.key;
|
||||
const wasDrawerOpen = prevProps.navigation.state.isDrawerOpen;
|
||||
const shouldOpen = this._shouldOpen(isDrawerOpen, wasDrawerOpen);
|
||||
const shouldClose =
|
||||
this._shouldClose(isDrawerOpen, wasDrawerOpen) || key !== prevKey;
|
||||
|
||||
if (this._shouldOpen(isDrawerOpen, wasDrawerOpen)) {
|
||||
if (shouldOpen) {
|
||||
this._drawerState = 'opening';
|
||||
this._drawer.openDrawer();
|
||||
} else if (this._shouldClose(isDrawerOpen, wasDrawerOpen)) {
|
||||
} else if (shouldClose) {
|
||||
this._drawerState = 'closing';
|
||||
this._drawer.closeDrawer();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user