swimtracker-app/App.js

96 lines
3.2 KiB
JavaScript
Raw Normal View History

2019-09-17 20:24:01 +02:00
import React from 'react';
import { AppLoading } from 'expo';
import { Ionicons } from '@expo/vector-icons';
2020-06-04 18:46:15 +02:00
import * as Font from 'expo-font';
2020-09-03 19:06:31 +02:00
// Redux + Storage
2020-06-04 18:46:15 +02:00
import swimtrackerReducer from './state/Reducer';
import { createStore } from 'redux';
import { DeviceReduxCoupling } from './state/DeviceReduxCoupling';
2020-06-04 18:46:15 +02:00
import { Provider } from 'react-redux';
2020-09-03 19:06:31 +02:00
import AsyncStorage from '@react-native-community/async-storage';
import { persistStore, persistReducer } from 'redux-persist'
import hardSet from 'redux-persist/lib/stateReconciler/hardSet'
import { PersistGate } from 'redux-persist/integration/react'
2020-06-04 18:46:15 +02:00
2020-09-03 19:06:31 +02:00
// Navigation
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
2020-06-04 18:46:15 +02:00
2020-09-03 19:06:31 +02:00
// Own views
import MainMenuView from "./views/MainMenuView";
import SettingsView from "./views/SettingsView";
import TrainingView from "./views/TrainingView";
import LastSessionsView from "./views/LastSessionsView";
const persistConfig = {
key: 'root',
storage: AsyncStorage,
stateReconciler: hardSet,
};
const persistedReducer = persistReducer(persistConfig, swimtrackerReducer)
const store = createStore(persistedReducer);
const persistor = persistStore(store);
const Stack = createStackNavigator();
2019-09-17 20:24:01 +02:00
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
isReady: false,
2020-05-17 15:57:26 +02:00
};
2019-09-17 20:24:01 +02:00
}
async componentDidMount() {
await Font.loadAsync({
Roboto: require('native-base/Fonts/Roboto.ttf'),
Roboto_medium: require('native-base/Fonts/Roboto_medium.ttf'),
...Ionicons.font,
});
this.setState({ isReady: true });
2020-07-15 15:53:16 +02:00
this.device = new DeviceReduxCoupling(store);
2019-09-17 20:24:01 +02:00
}
render() {
if (!this.state.isReady) {
return <AppLoading />;
}
2020-09-03 19:06:31 +02:00
const screenOptions = {
headerShown: false,
};
2020-07-25 14:06:39 +02:00
return (
<Provider store={store}>
2020-09-03 19:06:31 +02:00
<PersistGate loading={<AppLoading />} persistor={persistor}>
<NavigationContainer>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen
name="Home"
component={MainMenuView}
options={screenOptions}
/>
<Stack.Screen
name="Settings"
component={SettingsView}
options={screenOptions}
/>
<Stack.Screen
name="Training"
component={TrainingView}
options={screenOptions}
/>
<Stack.Screen
name="LastSessions"
component={LastSessionsView}
options={screenOptions}
/>
</Stack.Navigator>
</NavigationContainer>
</PersistGate>
2020-07-25 14:06:39 +02:00
</Provider>
2019-09-17 20:24:01 +02:00
);
}
}