Browse Source

Allow selecting default screen on application start

keplyx 2 years ago
parent
commit
540d94d877

+ 2
- 1
App.js View File

@@ -2,7 +2,7 @@
2 2
 
3 3
 import * as React from 'react';
4 4
 import {Root, StyleProvider} from 'native-base';
5
-import AppNavigator from './navigation/AppNavigator';
5
+import {createAppContainerWithInitialRoute} from './navigation/AppNavigator';
6 6
 import ThemeManager from './utils/ThemeManager';
7 7
 import LocaleManager from './utils/LocaleManager';
8 8
 import * as Font from 'expo-font';
@@ -94,6 +94,7 @@ export default class App extends React.Component<Props, State> {
94 94
         if (this.state.showIntro) {
95 95
             return <CustomIntroSlider onDone={() => this.onIntroDone()}/>;
96 96
         } else {
97
+            const AppNavigator = createAppContainerWithInitialRoute(AsyncStorageManager.getInstance().preferences.defaultStartScreen.current);
97 98
             return (
98 99
                 <Root>
99 100
                     <StyleProvider style={this.state.currentTheme}>

+ 24
- 21
navigation/AppNavigator.js View File

@@ -1,7 +1,7 @@
1 1
 // @flow
2 2
 
3 3
 import {createAppContainer, createStackNavigator} from 'react-navigation';
4
-import MainTabNavigator from './MainTabNavigator';
4
+import {createMaterialBottomTabNavigatorWithInitialRoute} from './MainTabNavigator';
5 5
 import SettingsScreen from '../screens/SettingsScreen';
6 6
 import AboutScreen from '../screens/About/AboutScreen';
7 7
 import ProximoListScreen from '../screens/Proximo/ProximoListScreen';
@@ -15,23 +15,26 @@ import {fromRight} from "react-navigation-transitions";
15 15
 /**
16 16
  * Create a stack navigator using the drawer to handle navigation between screens
17 17
  */
18
-export default createAppContainer(
19
-    createStackNavigator({
20
-            Main: MainTabNavigator,
21
-            // Drawer: MainDrawerNavigator,
22
-            ProximoListScreen: {screen: ProximoListScreen},
23
-            SettingsScreen: {screen: SettingsScreen},
24
-            AboutScreen: {screen: AboutScreen},
25
-            AboutDependenciesScreen: {screen: AboutDependenciesScreen},
26
-            SelfMenuScreen: {screen: SelfMenuScreen},
27
-            ProxiwashAboutScreen: {screen: ProxiwashAboutScreen},
28
-            ProximoAboutScreen: {screen: ProximoAboutScreen},
29
-            DebugScreen: {screen: DebugScreen},
30
-        },
31
-        {
32
-            initialRouteName: "Main",
33
-            mode: 'card',
34
-            headerMode: "none",
35
-            transitionConfig: () => fromRight(),
36
-        })
37
-);
18
+function createAppContainerWithInitialRoute(initialRoute: string) {
19
+    return createAppContainer(
20
+        createStackNavigator({
21
+                Main: createMaterialBottomTabNavigatorWithInitialRoute(initialRoute),
22
+                // Drawer: MainDrawerNavigator,
23
+                ProximoListScreen: {screen: ProximoListScreen},
24
+                SettingsScreen: {screen: SettingsScreen},
25
+                AboutScreen: {screen: AboutScreen},
26
+                AboutDependenciesScreen: {screen: AboutDependenciesScreen},
27
+                SelfMenuScreen: {screen: SelfMenuScreen},
28
+                ProxiwashAboutScreen: {screen: ProxiwashAboutScreen},
29
+                ProximoAboutScreen: {screen: ProximoAboutScreen},
30
+                DebugScreen: {screen: DebugScreen},
31
+            },
32
+            {
33
+                initialRouteName: "Main",
34
+                mode: 'card',
35
+                headerMode: "none",
36
+                transitionConfig: () => fromRight(),
37
+            })
38
+    );
39
+}
40
+export {createAppContainerWithInitialRoute};

+ 26
- 20
navigation/MainTabNavigator.js View File

@@ -8,6 +8,7 @@ import ProximoMainScreen from '../screens/Proximo/ProximoMainScreen';
8 8
 import PlanexScreen from '../screens/PlanexScreen';
9 9
 import CustomMaterialIcon from "../components/CustomMaterialIcon";
10 10
 import ThemeManager from "../utils/ThemeManager";
11
+import AsyncStorageManager from "../utils/AsyncStorageManager";
11 12
 
12 13
 const TAB_ICONS = {
13 14
     Home: 'triangle',
@@ -17,25 +18,30 @@ const TAB_ICONS = {
17 18
     Planex: 'timetable',
18 19
 };
19 20
 
21
+function createMaterialBottomTabNavigatorWithInitialRoute(initialRoute: string) {
22
+    return createMaterialBottomTabNavigator({
23
+        Home: {screen: HomeScreen},
24
+        Planning: {screen: PlanningScreen,},
25
+        Proxiwash: {screen: ProxiwashScreen,},
26
+        Proximo: {screen: ProximoMainScreen,},
27
+        Planex: {screen: PlanexScreen},
28
+    }, {
29
+        defaultNavigationOptions: ({navigation}) => ({
30
+            tabBarIcon: ({focused, horizontal, tintColor}) => {
31
+                let icon = TAB_ICONS[navigation.state.routeName];
20 32
 
21
-export default createMaterialBottomTabNavigator({
22
-    Home: {screen: HomeScreen},
23
-    Planning: {screen: PlanningScreen,},
24
-    Proxiwash: {screen: ProxiwashScreen,},
25
-    Proximo: {screen: ProximoMainScreen,},
26
-    Planex: {screen: PlanexScreen},
27
-}, {
28
-    defaultNavigationOptions: ({navigation}) => ({
29
-        tabBarIcon: ({focused, horizontal, tintColor}) => {
30
-            let icon = TAB_ICONS[navigation.state.routeName];
33
+                return <CustomMaterialIcon icon={icon} color={tintColor}/>;
34
+            }
35
+        }),
36
+        order: ['Proximo', 'Planning', 'Home', 'Proxiwash', 'Planex'],
37
+        initialRouteName: initialRoute,
38
+        activeColor: '#f0edf6',
39
+        inactiveColor: '#4e1108',
40
+        backBehavior: 'initialRoute',
41
+        barStyle: {backgroundColor: ThemeManager.getCurrentThemeVariables().brandPrimary},
42
+    });
43
+}
44
+
45
+
46
+export {createMaterialBottomTabNavigatorWithInitialRoute};
31 47
 
32
-            return <CustomMaterialIcon icon={icon} color={tintColor}/>;
33
-        }
34
-    }),
35
-    order: ['Proximo', 'Planning', 'Home', 'Proxiwash', 'Planex'],
36
-    initialRouteName: 'Home',
37
-    activeColor: '#f0edf6',
38
-    inactiveColor: '#4e1108',
39
-    backBehavior: 'initialRoute',
40
-    barStyle: {backgroundColor: ThemeManager.getCurrentThemeVariables().brandPrimary},
41
-});

+ 1
- 0
screens/HomeScreen.js View File

@@ -8,6 +8,7 @@ import CustomMaterialIcon from '../components/CustomMaterialIcon';
8 8
 import FetchedDataSectionList from "../components/FetchedDataSectionList";
9 9
 import Autolink from 'react-native-autolink';
10 10
 import ThemeManager from "../utils/ThemeManager";
11
+import AsyncStorageManager from "../utils/AsyncStorageManager";
11 12
 
12 13
 const ICON_AMICALE = require('../assets/amicale.png');
13 14
 const NAME_AMICALE = 'Amicale INSA Toulouse';

+ 42
- 4
screens/SettingsScreen.js View File

@@ -32,6 +32,7 @@ type Props = {
32 32
 type State = {
33 33
     nightMode: boolean,
34 34
     proxiwashNotifPickerSelected: string,
35
+    startScreenPickerSelected: string,
35 36
 };
36 37
 
37 38
 /**
@@ -41,6 +42,7 @@ export default class SettingsScreen extends React.Component<Props, State> {
41 42
     state = {
42 43
         nightMode: ThemeManager.getNightMode(),
43 44
         proxiwashNotifPickerSelected: AsyncStorageManager.getInstance().preferences.proxiwashNotifications.current,
45
+        startScreenPickerSelected: AsyncStorageManager.getInstance().preferences.defaultStartScreen.current,
44 46
     };
45 47
 
46 48
     /**
@@ -61,6 +63,19 @@ export default class SettingsScreen extends React.Component<Props, State> {
61 63
     }
62 64
 
63 65
     /**
66
+     * Save the value for the proxiwash reminder notification time
67
+     *
68
+     * @param value The value to store
69
+     */
70
+    onStartScreenPickerValueChange(value: string) {
71
+        let key = AsyncStorageManager.getInstance().preferences.defaultStartScreen.key;
72
+        AsyncStorageManager.getInstance().savePref(key, value);
73
+        this.setState({
74
+            startScreenPickerSelected: value
75
+        });
76
+    }
77
+
78
+    /**
64 79
      * Returns a picker allowing the user to select the proxiwash reminder notification time
65 80
      *
66 81
      * @returns {React.Node}
@@ -84,12 +99,34 @@ export default class SettingsScreen extends React.Component<Props, State> {
84 99
     }
85 100
 
86 101
     /**
102
+     * Returns a picker allowing the user to select the start screen
103
+     *
104
+     * @returns {React.Node}
105
+     */
106
+    getStartScreenPicker() {
107
+        return (
108
+            <Picker
109
+                note
110
+                mode="dropdown"
111
+                style={{width: 120}}
112
+                selectedValue={this.state.startScreenPickerSelected}
113
+                onValueChange={(value) => this.onStartScreenPickerValueChange(value)}
114
+            >
115
+                <Picker.Item label={i18n.t('screens.home')} value="Home"/>
116
+                <Picker.Item label={i18n.t('screens.planning')} value="Planning"/>
117
+                <Picker.Item label={i18n.t('screens.proxiwash')} value="Proxiwash"/>
118
+                <Picker.Item label={i18n.t('screens.proximo')} value="Proximo"/>
119
+                <Picker.Item label={'Planex'} value="Planex"/>
120
+            </Picker>
121
+        );
122
+    }
123
+
124
+    /**
87 125
      * Toggle night mode and save it to preferences
88 126
      */
89 127
     toggleNightMode() {
90 128
         ThemeManager.getInstance().setNightMode(!this.state.nightMode);
91 129
         this.setState({nightMode: !this.state.nightMode});
92
-        // Alert.alert(i18n.t('settingsScreen.nightMode'), i18n.t('settingsScreen.restart'));
93 130
         this.resetStack();
94 131
     }
95 132
 
@@ -133,7 +170,7 @@ export default class SettingsScreen extends React.Component<Props, State> {
133 170
                         {subtitle}
134 171
                     </Text>
135 172
                 </Body>
136
-                <Right style={{flex: 1}}>
173
+                <Right>
137 174
                     <CheckBox checked={this.state.nightMode}
138 175
                               onPress={() => this.toggleNightMode()}/>
139 176
                 </Right>
@@ -167,7 +204,7 @@ export default class SettingsScreen extends React.Component<Props, State> {
167 204
                     </Text>
168 205
                 </Body>
169 206
 
170
-                <Right style={{flex: 1}}>
207
+                <Right>
171 208
                     {control}
172 209
                 </Right>
173 210
             </ListItem>
@@ -195,10 +232,11 @@ export default class SettingsScreen extends React.Component<Props, State> {
195 232
                 <Content padder>
196 233
                     <Card>
197 234
                         <CardItem header>
198
-                            <Text>{i18n.t('settingsScreen.appearanceCard')}</Text>
235
+                            <Text>{i18n.t('settingsScreen.generalCard')}</Text>
199 236
                         </CardItem>
200 237
                         <List>
201 238
                             {this.getToggleItem(() => this.toggleNightMode(), 'theme-light-dark', i18n.t('settingsScreen.nightMode'), i18n.t('settingsScreen.nightModeSub'))}
239
+                            {SettingsScreen.getGeneralItem(this.getStartScreenPicker(), 'power', i18n.t('settingsScreen.startScreen'), i18n.t('settingsScreen.startScreenSub'))}
202 240
                         </List>
203 241
                     </Card>
204 242
                     <Card>

+ 3
- 1
translations/en.json View File

@@ -36,9 +36,11 @@
36 36
     }
37 37
   },
38 38
   "settingsScreen": {
39
-    "appearanceCard": "Appearance",
39
+    "generalCard": "General",
40 40
     "nightMode": "Night Mode",
41 41
     "nightModeSub": "Switch the app to a dark or light theme",
42
+    "startScreen": "Start Screen",
43
+    "startScreenSub": "Select which screen to start the app on",
42 44
     "proxiwashNotifReminder": "Machine running reminder",
43 45
     "proxiwashNotifReminderSub": "Choose when to send a notification to remind you a machine is running with your laundry",
44 46
     "proxiwashNotifReminderPicker": {

+ 3
- 1
translations/fr.json View File

@@ -36,9 +36,11 @@
36 36
     }
37 37
   },
38 38
   "settingsScreen": {
39
-    "appearanceCard": "Apparence",
39
+    "generalCard": "Général",
40 40
     "nightMode": "Mode Nuit",
41 41
     "nightModeSub": "Passer l'application dans un thème sombre ou clair",
42
+    "startScreen": "Écran de démarrage",
43
+    "startScreenSub": "Choisissez l'écran utilisé au démarrage",
42 44
     "proxiwashNotifReminder": "Rappel de machine en cours",
43 45
     "proxiwashNotifReminderSub": "Choississez quand envoyer une notification pour vous rappeler qu'une machine avec votre linge est en cours",
44 46
     "proxiwashNotifReminderPicker": {

+ 5
- 0
utils/AsyncStorageManager.js View File

@@ -53,6 +53,11 @@ export default class AsyncStorageManager {
53 53
             key: 'debugUnlocked',
54 54
             default: '0',
55 55
             current: '',
56
+        },
57
+        defaultStartScreen: {
58
+            key: 'defaultStartScreen',
59
+            default: 'Home',
60
+            current: '',
56 61
         }
57 62
     };
58 63
 

Loading…
Cancel
Save