2019-09-17 20:24:01 +02:00
|
|
|
import React from 'react';
|
2021-05-24 13:19:04 +02:00
|
|
|
import AppLoading from 'expo-app-loading';
|
2019-09-17 20:24:01 +02:00
|
|
|
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';
|
2020-06-28 18:55:58 +02:00
|
|
|
import { DeviceReduxCoupling } from './state/DeviceReduxCoupling';
|
2020-06-04 18:46:15 +02:00
|
|
|
import { Provider } from 'react-redux';
|
2021-05-24 13:19:04 +02:00
|
|
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
2020-09-03 19:06:31 +02:00
|
|
|
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";
|
2021-05-24 13:19:04 +02:00
|
|
|
import ConnectingView from './views/ConnectingView';
|
|
|
|
import WifiSelectionView from './views/WifiSelectionView';
|
|
|
|
import WifiPasswordView from './views/WifiPasswordView';
|
2020-09-03 19:06:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
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() {
|
2021-05-24 13:19:04 +02:00
|
|
|
/*await Font.loadAsync({
|
2019-09-17 20:24:01 +02:00
|
|
|
Roboto: require('native-base/Fonts/Roboto.ttf'),
|
|
|
|
Roboto_medium: require('native-base/Fonts/Roboto_medium.ttf'),
|
|
|
|
...Ionicons.font,
|
2021-05-24 13:19:04 +02:00
|
|
|
});*/
|
2019-09-17 20:24:01 +02:00
|
|
|
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,
|
|
|
|
};
|
2021-06-06 21:31:41 +02:00
|
|
|
|
|
|
|
|
2021-05-24 13:19:04 +02:00
|
|
|
return (
|
|
|
|
<Provider store={store}>
|
|
|
|
<PersistGate loading={<AppLoading />} persistor={persistor}>
|
|
|
|
<NavigationContainer>
|
2021-06-06 21:31:41 +02:00
|
|
|
<Stack.Navigator initialRouteName="WifiSelectionView">
|
|
|
|
<Stack.Screen
|
|
|
|
name="WifiSelectionView"
|
|
|
|
options={screenOptions} >
|
|
|
|
{props => <WifiSelectionView {...props} device={this.device} />}
|
|
|
|
</Stack.Screen>
|
2021-05-24 13:19:04 +02:00
|
|
|
<Stack.Screen
|
|
|
|
name="WifiPasswordView"
|
|
|
|
options={screenOptions}
|
2021-06-06 21:31:41 +02:00
|
|
|
component={WifiPasswordView}
|
|
|
|
>
|
|
|
|
</Stack.Screen>
|
2021-05-24 13:19:04 +02:00
|
|
|
</Stack.Navigator>
|
|
|
|
</NavigationContainer>
|
|
|
|
</PersistGate>
|
|
|
|
</Provider>
|
|
|
|
);
|
|
|
|
|
2021-06-06 21:31:41 +02:00
|
|
|
/*
|
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
|
|
|
);
|
2021-06-06 21:31:41 +02:00
|
|
|
*/
|
2019-09-17 20:24:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|