lock drawer mode state to closed for settings screen

This commit is contained in:
Akinwale Ariwodola 2018-04-22 05:03:32 +01:00
parent 3aad8491cf
commit b2313f1766

View file

@ -1,32 +1,23 @@
import React from 'react';
import DiscoverPage from '../page/discover';
import FilePage from '../page/file';
import SearchPage from '../page/search';
import SettingsPage from '../page/settings';
import SplashScreen from '../page/splash';
import SearchInput from '../component/searchInput';
import {
addNavigationHelpers,
DrawerNavigator,
StackNavigator,
NavigationActions
} from 'react-navigation';
import { addNavigationHelpers, DrawerNavigator, StackNavigator } from 'react-navigation';
import { connect } from 'react-redux';
import { addListener } from '../utils/redux';
import { AppState, BackHandler, NativeModules, TextInput } from 'react-native';
import { AppState, BackHandler, NativeModules } from 'react-native';
import { SETTINGS } from 'lbry-redux';
import { makeSelectClientSetting } from '../redux/selectors/settings';
import Feather from 'react-native-vector-icons/Feather';
import discoverStyle from '../styles/discover';
import searchStyle from '../styles/search';
import { makeSelectClientSetting } from '../redux/selectors/settings';
const discoverStack = StackNavigator({
Discover: {
screen: DiscoverPage,
navigationOptions: ({ navigation }) => ({
title: 'Discover',
headerLeft: <Feather name="menu" size={24} style={discoverStyle.drawerHamburger} onPress={() => navigation.navigate('DrawerOpen')} />,
headerRight: <Feather name="search" size={24} style={discoverStyle.rightHeaderIcon} onPress={() => navigation.navigate('Search')} />
headerLeft: <Feather name="menu" size={24} style={discoverStyle.drawerHamburger} onPress={() => navigation.navigate('DrawerOpen')} />
})
},
File: {
@ -35,13 +26,6 @@ const discoverStack = StackNavigator({
header: null,
drawerLockMode: 'locked-closed'
}
},
Search: {
screen: SearchPage,
navigationOptions: ({ navigation }) => ({
headerTitle: <SearchInput style={searchStyle.searchInput} />,
headerRight: <Feather name="x" size={24} style={discoverStyle.rightHeaderIcon} onPress={() => navigation.dispatch(NavigationActions.back())} />
})
}
}, {
headerMode: 'screen',
@ -49,10 +33,7 @@ const discoverStack = StackNavigator({
const drawer = DrawerNavigator({
Discover: { screen: discoverStack },
Settings: {
screen: SettingsPage,
headerMode: 'screen'
}
Settings: { screen: SettingsPage, navigationOptions: { drawerLockMode: 'locked-closed' } }
}, {
drawerWidth: 300,
headerMode: 'none'
@ -60,10 +41,7 @@ const drawer = DrawerNavigator({
export const AppNavigator = new StackNavigator({
Splash: {
screen: SplashScreen,
navigationOptions: {
drawerLockMode: 'locked-closed'
}
screen: SplashScreen
},
Main: {
screen: drawer
@ -77,20 +55,11 @@ class AppWithNavigationState extends React.Component {
AppState.addEventListener('change', this._handleAppStateChange);
BackHandler.addEventListener('hardwareBackPress', function() {
const { dispatch, navigation, nav } = this.props;
// There should be a better way to check this
if (nav.routes.length > 1) {
const subRoutes = nav.routes[1].routes[0].routes;
const lastRoute = subRoutes[subRoutes.length - 1];
if (['Settings'].indexOf(lastRoute.key) > -1) {
if (nav.routes.length === 2 && nav.routes[1].routeName === 'Main') {
if (nav.routes[1].routes[0].routes[0].index > 0) {
dispatch({ type: 'Navigation/BACK' });
return true;
}
if (nav.routes[1].routeName === 'Main') {
if (nav.routes[1].routes[0].routes[0].index > 0) {
dispatch({ type: 'Navigation/BACK' });
return true;
}
}
}
return false;
}.bind(this));
@ -108,7 +77,7 @@ class AppWithNavigationState extends React.Component {
NativeModules.DaemonServiceControl) {
if (!keepDaemonRunning) {
// terminate the daemon background service when is suspended / inactive
NativeModules.DaemonServiceControl.stopService();
// NativeModules.DaemonServiceControl.stopService(); // moved to onDestory in activity for better handling
}
}
}