application-amicale/navigation/DrawerNavigator.js

266 lines
8.1 KiB
JavaScript
Raw Normal View History

// @flow
2020-03-05 10:29:15 +01:00
import * as React from 'react';
import {createDrawerNavigator} from '@react-navigation/drawer';
import TabNavigator from './MainTabNavigator';
import SettingsScreen from '../screens/SettingsScreen';
import AboutScreen from '../screens/About/AboutScreen';
import AboutDependenciesScreen from '../screens/About/AboutDependenciesScreen';
import SelfMenuScreen from '../screens/SelfMenuScreen';
import AvailableRoomScreen from "../screens/Websites/AvailableRoomScreen";
2020-03-06 09:12:56 +01:00
import BibScreen from "../screens/Websites/BibScreen";
2020-03-15 18:44:32 +01:00
import TetrisScreen from "../screens/Tetris/TetrisScreen";
2020-03-08 14:22:03 +01:00
import DebugScreen from '../screens/About/DebugScreen';
import Sidebar from "../components/Sidebar";
2020-03-05 10:29:15 +01:00
import {createStackNavigator, TransitionPresets} from "@react-navigation/stack";
import HeaderButton from "../components/HeaderButton";
2020-03-08 12:17:04 +01:00
import i18n from "i18n-js";
2020-03-29 11:47:27 +02:00
import LoginScreen from "../screens/Amicale/LoginScreen";
2020-03-06 09:12:56 +01:00
const defaultScreenOptions = {
gestureEnabled: true,
cardOverlayEnabled: true,
...TransitionPresets.SlideFromRightIOS,
};
function getDrawerButton(navigation: Object) {
return (
<HeaderButton icon={'menu'} onPress={navigation.openDrawer}/>
2020-03-06 09:12:56 +01:00
);
}
2020-03-05 10:29:15 +01:00
const AboutStack = createStackNavigator();
2020-03-05 10:29:15 +01:00
function AboutStackComponent() {
return (
<AboutStack.Navigator
initialRouteName="AboutScreen"
2020-03-06 09:12:56 +01:00
headerMode="float"
screenOptions={defaultScreenOptions}
2020-03-05 10:29:15 +01:00
>
<AboutStack.Screen
name="AboutScreen"
component={AboutScreen}
2020-03-06 09:12:56 +01:00
options={({navigation}) => {
const openDrawer = getDrawerButton.bind(this, navigation);
return {
2020-03-08 12:17:04 +01:00
title: i18n.t('screens.about'),
2020-03-06 09:12:56 +01:00
headerLeft: openDrawer
};
}}
2020-03-05 10:29:15 +01:00
/>
<AboutStack.Screen
name="AboutDependenciesScreen"
component={AboutDependenciesScreen}
2020-03-06 09:12:56 +01:00
options={{
2020-03-08 12:17:04 +01:00
title: i18n.t('aboutScreen.libs')
2020-03-06 09:12:56 +01:00
}}
2020-03-05 10:29:15 +01:00
/>
<AboutStack.Screen
name="DebugScreen"
component={DebugScreen}
2020-03-06 09:12:56 +01:00
options={{
2020-03-08 12:17:04 +01:00
title: i18n.t('aboutScreen.debug')
2020-03-06 09:12:56 +01:00
}}
2020-03-05 10:29:15 +01:00
/>
</AboutStack.Navigator>
);
}
2020-03-06 09:12:56 +01:00
const SettingsStack = createStackNavigator();
function SettingsStackComponent() {
return (
<SettingsStack.Navigator
initialRouteName="SettingsScreen"
headerMode="float"
screenOptions={defaultScreenOptions}
>
<SettingsStack.Screen
name="SettingsScreen"
component={SettingsScreen}
options={({navigation}) => {
const openDrawer = getDrawerButton.bind(this, navigation);
return {
2020-03-08 12:17:04 +01:00
title: i18n.t('screens.settings'),
2020-03-06 09:12:56 +01:00
headerLeft: openDrawer
};
}}
/>
</SettingsStack.Navigator>
);
}
const SelfMenuStack = createStackNavigator();
function SelfMenuStackComponent() {
return (
<SelfMenuStack.Navigator
initialRouteName="SelfMenuScreen"
headerMode="float"
screenOptions={defaultScreenOptions}
>
<SelfMenuStack.Screen
name="SelfMenuScreen"
component={SelfMenuScreen}
options={({navigation}) => {
const openDrawer = getDrawerButton.bind(this, navigation);
return {
2020-03-08 12:17:04 +01:00
title: i18n.t('screens.menuSelf'),
2020-03-06 09:12:56 +01:00
headerLeft: openDrawer
};
}}
/>
</SelfMenuStack.Navigator>
);
}
const AvailableRoomStack = createStackNavigator();
function AvailableRoomStackComponent() {
return (
<AvailableRoomStack.Navigator
initialRouteName="AvailableRoomScreen"
headerMode="float"
screenOptions={defaultScreenOptions}
>
<AvailableRoomStack.Screen
name="AvailableRoomScreen"
component={AvailableRoomScreen}
options={({navigation}) => {
const openDrawer = getDrawerButton.bind(this, navigation);
return {
2020-03-08 12:17:04 +01:00
title: i18n.t('screens.availableRooms'),
2020-03-06 09:12:56 +01:00
headerLeft: openDrawer
};
}}
/>
</AvailableRoomStack.Navigator>
);
}
const BibStack = createStackNavigator();
function BibStackComponent() {
return (
<BibStack.Navigator
initialRouteName="BibScreen"
headerMode="float"
screenOptions={defaultScreenOptions}
>
<BibStack.Screen
name="BibScreen"
component={BibScreen}
options={({navigation}) => {
const openDrawer = getDrawerButton.bind(this, navigation);
return {
2020-03-08 12:17:04 +01:00
title: i18n.t('screens.bib'),
2020-03-06 09:12:56 +01:00
headerLeft: openDrawer
};
}}
/>
</BibStack.Navigator>
);
}
2020-03-15 18:44:32 +01:00
const TetrisStack = createStackNavigator();
function TetrisStackComponent() {
return (
<TetrisStack.Navigator
initialRouteName="TetrisScreen"
headerMode="float"
screenOptions={defaultScreenOptions}
>
<TetrisStack.Screen
name="TetrisScreen"
component={TetrisScreen}
options={({navigation}) => {
const openDrawer = getDrawerButton.bind(this, navigation);
return {
2020-03-28 12:21:33 +01:00
title: i18n.t("game.title"),
2020-03-15 18:44:32 +01:00
headerLeft: openDrawer
};
}}
/>
</TetrisStack.Navigator>
);
}
2020-03-29 11:47:27 +02:00
const LoginStack = createStackNavigator();
function LoginStackComponent() {
return (
<LoginStack.Navigator
initialRouteName="LoginScreen"
headerMode="float"
screenOptions={defaultScreenOptions}
>
<LoginStack.Screen
name="LoginScreen"
component={LoginScreen}
options={({navigation}) => {
const openDrawer = getDrawerButton.bind(this, navigation);
return {
title: 'LOGIN',
headerLeft: openDrawer
};
}}
/>
</LoginStack.Navigator>
);
}
2020-03-05 10:29:15 +01:00
const Drawer = createDrawerNavigator();
function getDrawerContent(props) {
return <Sidebar {...props}/>
2020-02-04 19:42:40 +01:00
}
2020-03-05 10:29:15 +01:00
export default function DrawerNavigator() {
return (
<Drawer.Navigator
initialRouteName={'Main'}
2020-03-06 09:12:56 +01:00
headerMode={'float'}
backBehavior={'initialRoute'}
drawerType={'front'}
drawerContent={(props) => getDrawerContent(props)}
2020-03-06 09:12:56 +01:00
screenOptions={defaultScreenOptions}
2020-03-05 10:29:15 +01:00
>
<Drawer.Screen
name="Main"
component={TabNavigator}
>
</Drawer.Screen>
<Drawer.Screen
name="SettingsScreen"
2020-03-06 09:12:56 +01:00
component={SettingsStackComponent}
2020-03-05 10:29:15 +01:00
/>
<Drawer.Screen
name="AboutScreen"
component={AboutStackComponent}
/>
<Drawer.Screen
name="SelfMenuScreen"
2020-03-06 09:12:56 +01:00
component={SelfMenuStackComponent}
2020-03-05 10:29:15 +01:00
/>
<Drawer.Screen
name="AvailableRoomScreen"
2020-03-06 09:12:56 +01:00
component={AvailableRoomStackComponent}
2020-03-05 10:29:15 +01:00
/>
2020-03-06 09:12:56 +01:00
<Drawer.Screen
name="BibScreen"
component={BibStackComponent}
/>
2020-03-15 18:44:32 +01:00
<Drawer.Screen
name="TetrisScreen"
component={TetrisStackComponent}
/>
2020-03-29 11:47:27 +02:00
<Drawer.Screen
name="LoginScreen"
component={LoginStackComponent}
/>
2020-03-06 09:12:56 +01:00
</Drawer.Navigator>
);
}