Improve navigators to match linter

This commit is contained in:
Arnaud Vergnet 2020-08-05 00:16:05 +02:00
parent 7107a8eadf
commit 3e4f2f4ac1
2 changed files with 465 additions and 417 deletions

View file

@ -1,35 +1,41 @@
// @flow
import * as React from 'react';
import {createStackNavigator, TransitionPresets} from '@react-navigation/stack';
import i18n from 'i18n-js';
import {Platform} from 'react-native';
import SettingsScreen from '../screens/Other/Settings/SettingsScreen';
import AboutScreen from '../screens/About/AboutScreen';
import AboutDependenciesScreen from '../screens/About/AboutDependenciesScreen';
import DebugScreen from '../screens/About/DebugScreen';
import {createStackNavigator, TransitionPresets} from "@react-navigation/stack";
import i18n from "i18n-js";
import TabNavigator from "./TabNavigator";
import GameMainScreen from "../screens/Game/screens/GameMainScreen";
import VoteScreen from "../screens/Amicale/VoteScreen";
import LoginScreen from "../screens/Amicale/LoginScreen";
import {Platform} from "react-native";
import SelfMenuScreen from "../screens/Services/SelfMenuScreen";
import ProximoMainScreen from "../screens/Services/Proximo/ProximoMainScreen";
import ProximoListScreen from "../screens/Services/Proximo/ProximoListScreen";
import ProximoAboutScreen from "../screens/Services/Proximo/ProximoAboutScreen";
import ProfileScreen from "../screens/Amicale/ProfileScreen";
import ClubListScreen from "../screens/Amicale/Clubs/ClubListScreen";
import ClubAboutScreen from "../screens/Amicale/Clubs/ClubAboutScreen";
import ClubDisplayScreen from "../screens/Amicale/Clubs/ClubDisplayScreen";
import {createScreenCollapsibleStack, getWebsiteStack} from "../utils/CollapsibleUtils";
import BugReportScreen from "../screens/Other/FeedbackScreen";
import WebsiteScreen from "../screens/Services/WebsiteScreen";
import EquipmentScreen from "../screens/Amicale/Equipment/EquipmentListScreen";
import EquipmentLendScreen from "../screens/Amicale/Equipment/EquipmentRentScreen";
import EquipmentConfirmScreen from "../screens/Amicale/Equipment/EquipmentConfirmScreen";
import DashboardEditScreen from "../screens/Other/Settings/DashboardEditScreen";
import GameStartScreen from "../screens/Game/screens/GameStartScreen";
import TabNavigator from './TabNavigator';
import GameMainScreen from '../screens/Game/screens/GameMainScreen';
import VoteScreen from '../screens/Amicale/VoteScreen';
import LoginScreen from '../screens/Amicale/LoginScreen';
import SelfMenuScreen from '../screens/Services/SelfMenuScreen';
import ProximoMainScreen from '../screens/Services/Proximo/ProximoMainScreen';
import ProximoListScreen from '../screens/Services/Proximo/ProximoListScreen';
import ProximoAboutScreen from '../screens/Services/Proximo/ProximoAboutScreen';
import ProfileScreen from '../screens/Amicale/ProfileScreen';
import ClubListScreen from '../screens/Amicale/Clubs/ClubListScreen';
import ClubAboutScreen from '../screens/Amicale/Clubs/ClubAboutScreen';
import ClubDisplayScreen from '../screens/Amicale/Clubs/ClubDisplayScreen';
import {
createScreenCollapsibleStack,
getWebsiteStack,
} from '../utils/CollapsibleUtils';
import BugReportScreen from '../screens/Other/FeedbackScreen';
import WebsiteScreen from '../screens/Services/WebsiteScreen';
import EquipmentScreen from '../screens/Amicale/Equipment/EquipmentListScreen';
import EquipmentLendScreen from '../screens/Amicale/Equipment/EquipmentRentScreen';
import EquipmentConfirmScreen from '../screens/Amicale/Equipment/EquipmentConfirmScreen';
import DashboardEditScreen from '../screens/Other/Settings/DashboardEditScreen';
import GameStartScreen from '../screens/Game/screens/GameStartScreen';
const modalTransition = Platform.OS === 'ios' ? TransitionPresets.ModalPresentationIOS : TransitionPresets.ModalSlideFromBottomIOS;
const modalTransition =
Platform.OS === 'ios'
? TransitionPresets.ModalPresentationIOS
: TransitionPresets.ModalSlideFromBottomIOS;
const defaultScreenOptions = {
gestureEnabled: true,
@ -37,91 +43,100 @@ const defaultScreenOptions = {
...TransitionPresets.SlideFromRightIOS,
};
const MainStack = createStackNavigator();
function MainStackComponent(props: { createTabNavigator: () => React.Node }) {
function MainStackComponent(props: {
createTabNavigator: () => React.Node,
}): React.Node {
const {createTabNavigator} = props;
return (
<MainStack.Navigator
initialRouteName={'main'}
headerMode={'screen'}
screenOptions={defaultScreenOptions}
>
initialRouteName="main"
headerMode="screen"
screenOptions={defaultScreenOptions}>
<MainStack.Screen
name="main"
component={props.createTabNavigator}
component={createTabNavigator}
options={{
headerShown: false,
title: i18n.t('screens.home.title'),
}}
/>
{createScreenCollapsibleStack(
"settings",
'settings',
MainStack,
SettingsScreen,
i18n.t('screens.settings.title'))}
i18n.t('screens.settings.title'),
)}
{createScreenCollapsibleStack(
"dashboard-edit",
'dashboard-edit',
MainStack,
DashboardEditScreen,
i18n.t('screens.settings.dashboardEdit.title'))}
i18n.t('screens.settings.dashboardEdit.title'),
)}
{createScreenCollapsibleStack(
"about",
'about',
MainStack,
AboutScreen,
i18n.t('screens.about.title'))}
i18n.t('screens.about.title'),
)}
{createScreenCollapsibleStack(
"dependencies",
'dependencies',
MainStack,
AboutDependenciesScreen,
i18n.t('screens.about.libs'))}
i18n.t('screens.about.libs'),
)}
{createScreenCollapsibleStack(
"debug",
'debug',
MainStack,
DebugScreen,
i18n.t('screens.about.debug'))}
i18n.t('screens.about.debug'),
)}
{createScreenCollapsibleStack(
"game-start",
'game-start',
MainStack,
GameStartScreen,
i18n.t('screens.game.title'))}
i18n.t('screens.game.title'),
)}
<MainStack.Screen
name="game-main"
component={GameMainScreen}
options={{
title: i18n.t("screens.game.title"),
title: i18n.t('screens.game.title'),
}}
/>
{createScreenCollapsibleStack(
"login",
'login',
MainStack,
LoginScreen,
i18n.t('screens.login.title'),
true,
{headerTintColor: "#fff"},
'transparent')}
{getWebsiteStack("website", MainStack, WebsiteScreen, "")}
{headerTintColor: '#fff'},
'transparent',
)}
{getWebsiteStack('website', MainStack, WebsiteScreen, '')}
{createScreenCollapsibleStack(
"self-menu",
'self-menu',
MainStack,
SelfMenuScreen,
i18n.t('screens.menu.title'))}
i18n.t('screens.menu.title'),
)}
{createScreenCollapsibleStack(
"proximo",
'proximo',
MainStack,
ProximoMainScreen,
i18n.t('screens.proximo.title'))}
i18n.t('screens.proximo.title'),
)}
{createScreenCollapsibleStack(
"proximo-list",
'proximo-list',
MainStack,
ProximoListScreen,
i18n.t('screens.proximo.articleList'),
)}
{createScreenCollapsibleStack(
"proximo-about",
'proximo-about',
MainStack,
ProximoAboutScreen,
i18n.t('screens.proximo.title'),
@ -130,75 +145,87 @@ function MainStackComponent(props: { createTabNavigator: () => React.Node }) {
)}
{createScreenCollapsibleStack(
"profile",
'profile',
MainStack,
ProfileScreen,
i18n.t('screens.profile.title'))}
i18n.t('screens.profile.title'),
)}
{createScreenCollapsibleStack(
"club-list",
'club-list',
MainStack,
ClubListScreen,
i18n.t('screens.clubs.title'))}
i18n.t('screens.clubs.title'),
)}
{createScreenCollapsibleStack(
"club-information",
'club-information',
MainStack,
ClubDisplayScreen,
i18n.t('screens.clubs.details'),
true,
{...modalTransition})}
{...modalTransition},
)}
{createScreenCollapsibleStack(
"club-about",
'club-about',
MainStack,
ClubAboutScreen,
i18n.t('screens.clubs.title'),
true,
{...modalTransition})}
{...modalTransition},
)}
{createScreenCollapsibleStack(
"equipment-list",
'equipment-list',
MainStack,
EquipmentScreen,
i18n.t('screens.equipment.title'))}
i18n.t('screens.equipment.title'),
)}
{createScreenCollapsibleStack(
"equipment-rent",
'equipment-rent',
MainStack,
EquipmentLendScreen,
i18n.t('screens.equipment.book'))}
i18n.t('screens.equipment.book'),
)}
{createScreenCollapsibleStack(
"equipment-confirm",
'equipment-confirm',
MainStack,
EquipmentConfirmScreen,
i18n.t('screens.equipment.confirm'))}
i18n.t('screens.equipment.confirm'),
)}
{createScreenCollapsibleStack(
"vote",
'vote',
MainStack,
VoteScreen,
i18n.t('screens.vote.title'))}
i18n.t('screens.vote.title'),
)}
{createScreenCollapsibleStack(
"feedback",
'feedback',
MainStack,
BugReportScreen,
i18n.t('screens.feedback.title'))}
i18n.t('screens.feedback.title'),
)}
</MainStack.Navigator>
);
}
type Props = {
type PropsType = {
defaultHomeRoute: string | null,
defaultHomeData: { [key: string]: any }
}
export default class MainNavigator extends React.Component<Props> {
// eslint-disable-next-line flowtype/no-weak-types
defaultHomeData: {[key: string]: string},
};
export default class MainNavigator extends React.Component<PropsType> {
createTabNavigator: () => React.Node;
constructor(props: Props) {
constructor(props: PropsType) {
super(props);
this.createTabNavigator = () => <TabNavigator {...props}/>
}
render() {
return (
<MainStackComponent createTabNavigator={this.createTabNavigator}/>
this.createTabNavigator = (): React.Node => (
<TabNavigator
defaultHomeRoute={props.defaultHomeRoute}
defaultHomeData={props.defaultHomeData}
/>
);
}
render(): React.Node {
return <MainStackComponent createTabNavigator={this.createTabNavigator} />;
}
}

View file

@ -1,32 +1,39 @@
// @flow
import * as React from 'react';
import {createStackNavigator, TransitionPresets} from '@react-navigation/stack';
import {createBottomTabNavigator} from "@react-navigation/bottom-tabs";
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
import {Title, useTheme} from 'react-native-paper';
import {Platform} from 'react-native';
import i18n from 'i18n-js';
import {createCollapsibleStack} from 'react-navigation-collapsible';
import {View} from 'react-native-animatable';
import HomeScreen from '../screens/Home/HomeScreen';
import PlanningScreen from '../screens/Planning/PlanningScreen';
import PlanningDisplayScreen from '../screens/Planning/PlanningDisplayScreen';
import ProxiwashScreen from '../screens/Proxiwash/ProxiwashScreen';
import ProxiwashAboutScreen from '../screens/Proxiwash/ProxiwashAboutScreen';
import PlanexScreen from '../screens/Planex/PlanexScreen';
import AsyncStorageManager from "../managers/AsyncStorageManager";
import {Title, useTheme} from 'react-native-paper';
import {Platform} from 'react-native';
import i18n from "i18n-js";
import ClubDisplayScreen from "../screens/Amicale/Clubs/ClubDisplayScreen";
import ScannerScreen from "../screens/Home/ScannerScreen";
import FeedItemScreen from "../screens/Home/FeedItemScreen";
import {createCollapsibleStack} from "react-navigation-collapsible";
import GroupSelectionScreen from "../screens/Planex/GroupSelectionScreen";
import CustomTabBar from "../components/Tabbar/CustomTabBar";
import WebsitesHomeScreen from "../screens/Services/ServicesScreen";
import ServicesSectionScreen from "../screens/Services/ServicesSectionScreen";
import AmicaleContactScreen from "../screens/Amicale/AmicaleContactScreen";
import {createScreenCollapsibleStack, getWebsiteStack} from "../utils/CollapsibleUtils";
import {View} from "react-native-animatable";
import Mascot, {MASCOT_STYLE} from "../components/Mascot/Mascot";
const modalTransition = Platform.OS === 'ios' ? TransitionPresets.ModalPresentationIOS : TransitionPresets.ModalSlideFromBottomIOS;
import AsyncStorageManager from '../managers/AsyncStorageManager';
import ClubDisplayScreen from '../screens/Amicale/Clubs/ClubDisplayScreen';
import ScannerScreen from '../screens/Home/ScannerScreen';
import FeedItemScreen from '../screens/Home/FeedItemScreen';
import GroupSelectionScreen from '../screens/Planex/GroupSelectionScreen';
import CustomTabBar from '../components/Tabbar/CustomTabBar';
import WebsitesHomeScreen from '../screens/Services/ServicesScreen';
import ServicesSectionScreen from '../screens/Services/ServicesSectionScreen';
import AmicaleContactScreen from '../screens/Amicale/AmicaleContactScreen';
import {
createScreenCollapsibleStack,
getWebsiteStack,
} from '../utils/CollapsibleUtils';
import Mascot, {MASCOT_STYLE} from '../components/Mascot/Mascot';
const modalTransition =
Platform.OS === 'ios'
? TransitionPresets.ModalPresentationIOS
: TransitionPresets.ModalSlideFromBottomIOS;
const defaultScreenOptions = {
gestureEnabled: true,
@ -34,94 +41,98 @@ const defaultScreenOptions = {
...modalTransition,
};
const ServicesStack = createStackNavigator();
function ServicesStackComponent() {
function ServicesStackComponent(): React.Node {
return (
<ServicesStack.Navigator
initialRouteName="index"
headerMode={"screen"}
screenOptions={defaultScreenOptions}
>
headerMode="screen"
screenOptions={defaultScreenOptions}>
{createScreenCollapsibleStack(
"index",
'index',
ServicesStack,
WebsitesHomeScreen,
i18n.t('screens.services.title'))}
i18n.t('screens.services.title'),
)}
{createScreenCollapsibleStack(
"services-section",
'services-section',
ServicesStack,
ServicesSectionScreen,
"SECTION")}
'SECTION',
)}
{createScreenCollapsibleStack(
"amicale-contact",
'amicale-contact',
ServicesStack,
AmicaleContactScreen,
i18n.t('screens.amicaleAbout.title'))}
i18n.t('screens.amicaleAbout.title'),
)}
</ServicesStack.Navigator>
);
}
const ProxiwashStack = createStackNavigator();
function ProxiwashStackComponent() {
function ProxiwashStackComponent(): React.Node {
return (
<ProxiwashStack.Navigator
initialRouteName="index"
headerMode={"screen"}
screenOptions={defaultScreenOptions}
>
headerMode="screen"
screenOptions={defaultScreenOptions}>
{createScreenCollapsibleStack(
"index",
'index',
ProxiwashStack,
ProxiwashScreen,
i18n.t('screens.proxiwash.title'))}
i18n.t('screens.proxiwash.title'),
)}
{createScreenCollapsibleStack(
"proxiwash-about",
'proxiwash-about',
ProxiwashStack,
ProxiwashAboutScreen,
i18n.t('screens.proxiwash.title'))}
i18n.t('screens.proxiwash.title'),
)}
</ProxiwashStack.Navigator>
);
}
const PlanningStack = createStackNavigator();
function PlanningStackComponent() {
function PlanningStackComponent(): React.Node {
return (
<PlanningStack.Navigator
initialRouteName="index"
headerMode={"screen"}
screenOptions={defaultScreenOptions}
>
headerMode="screen"
screenOptions={defaultScreenOptions}>
<PlanningStack.Screen
name="index"
component={PlanningScreen}
options={{title: i18n.t('screens.planning.title'),}}
options={{title: i18n.t('screens.planning.title')}}
/>
{createScreenCollapsibleStack(
"planning-information",
'planning-information',
PlanningStack,
PlanningDisplayScreen,
i18n.t('screens.planning.eventDetails'))}
i18n.t('screens.planning.eventDetails'),
)}
</PlanningStack.Navigator>
);
}
const HomeStack = createStackNavigator();
function HomeStackComponent(initialRoute: string | null, defaultData: { [key: string]: any }) {
let params = undefined;
function HomeStackComponent(
initialRoute: string | null,
defaultData: {[key: string]: string},
): React.Node {
let params;
if (initialRoute != null)
params = {data: defaultData, nextScreen: initialRoute, shouldOpen: true};
const {colors} = useTheme();
return (
<HomeStack.Navigator
initialRouteName={"index"}
headerMode={"screen"}
screenOptions={defaultScreenOptions}
>
initialRouteName="index"
headerMode="screen"
screenOptions={defaultScreenOptions}>
{createCollapsibleStack(
<HomeStack.Screen
name="index"
@ -131,113 +142,123 @@ function HomeStackComponent(initialRoute: string | null, defaultData: { [key: st
headerStyle: {
backgroundColor: colors.surface,
},
headerTitle: () =>
<View style={{flexDirection: "row"}}>
headerTitle: (): React.Node => (
<View style={{flexDirection: 'row'}}>
<Mascot
style={{
width: 50
width: 50,
}}
emotion={MASCOT_STYLE.RANDOM}
animated={true}
animated
entryAnimation={{
animation: "bounceIn",
duration: 1000
animation: 'bounceIn',
duration: 1000,
}}
loopAnimation={{
animation: "pulse",
animation: 'pulse',
duration: 2000,
iterationCount: "infinite"
iterationCount: 'infinite',
}}
/>
<Title style={{
<Title
style={{
marginLeft: 10,
marginTop: "auto",
marginBottom: "auto",
}}>{i18n.t('screens.home.title')}</Title>
marginTop: 'auto',
marginBottom: 'auto',
}}>
{i18n.t('screens.home.title')}
</Title>
</View>
),
}}
initialParams={params}
/>,
{
collapsedColor: colors.surface,
useNativeDriver: true,
}
},
)}
<HomeStack.Screen
name="scanner"
component={ScannerScreen}
options={{title: i18n.t('screens.scanner.title'),}}
options={{title: i18n.t('screens.scanner.title')}}
/>
{createScreenCollapsibleStack(
"club-information",
'club-information',
HomeStack,
ClubDisplayScreen,
i18n.t('screens.clubs.details'))}
i18n.t('screens.clubs.details'),
)}
{createScreenCollapsibleStack(
"feed-information",
'feed-information',
HomeStack,
FeedItemScreen,
i18n.t('screens.home.feed'))}
i18n.t('screens.home.feed'),
)}
{createScreenCollapsibleStack(
"planning-information",
'planning-information',
HomeStack,
PlanningDisplayScreen,
i18n.t('screens.planning.eventDetails'))}
i18n.t('screens.planning.eventDetails'),
)}
</HomeStack.Navigator>
);
}
const PlanexStack = createStackNavigator();
function PlanexStackComponent() {
function PlanexStackComponent(): React.Node {
return (
<PlanexStack.Navigator
initialRouteName="index"
headerMode={"screen"}
screenOptions={defaultScreenOptions}
>
headerMode="screen"
screenOptions={defaultScreenOptions}>
{getWebsiteStack(
"index",
'index',
PlanexStack,
PlanexScreen,
i18n.t("screens.planex.title"))}
i18n.t('screens.planex.title'),
)}
{createScreenCollapsibleStack(
"group-select",
'group-select',
PlanexStack,
GroupSelectionScreen,
"")}
'',
)}
</PlanexStack.Navigator>
);
}
const Tab = createBottomTabNavigator();
type Props = {
type PropsType = {
defaultHomeRoute: string | null,
defaultHomeData: { [key: string]: any }
}
defaultHomeData: {[key: string]: string},
};
export default class TabNavigator extends React.Component<Props> {
export default class TabNavigator extends React.Component<PropsType> {
createHomeStackComponent: () => React.Node;
createHomeStackComponent: () => HomeStackComponent;
defaultRoute: string;
constructor(props) {
constructor(props: PropsType) {
super(props);
if (props.defaultHomeRoute != null)
this.defaultRoute = 'home';
if (props.defaultHomeRoute != null) this.defaultRoute = 'home';
else
this.defaultRoute = AsyncStorageManager.getString(AsyncStorageManager.PREFERENCES.defaultStartScreen.key).toLowerCase();
this.createHomeStackComponent = () => HomeStackComponent(props.defaultHomeRoute, props.defaultHomeData);
this.defaultRoute = AsyncStorageManager.getString(
AsyncStorageManager.PREFERENCES.defaultStartScreen.key,
).toLowerCase();
this.createHomeStackComponent = (): React.Node =>
HomeStackComponent(props.defaultHomeRoute, props.defaultHomeData);
}
render() {
render(): React.Node {
return (
<Tab.Navigator
initialRouteName={this.defaultRoute}
tabBar={props => <CustomTabBar {...props} />}
>
// eslint-disable-next-line react/jsx-props-no-spreading
tabBar={(props: {...}): React.Node => <CustomTabBar {...props} />}>
<Tab.Screen
name="services"
option
@ -263,7 +284,7 @@ export default class TabNavigator extends React.Component<Props> {
<Tab.Screen
name="planex"
component={PlanexStackComponent}
options={{title: i18n.t("screens.planex.title")}}
options={{title: i18n.t('screens.planex.title')}}
/>
</Tab.Navigator>
);