2019-06-29 13:37:21 +02:00
|
|
|
// @flow
|
|
|
|
|
2019-08-06 13:28:11 +02:00
|
|
|
import * as React from 'react';
|
2020-02-04 12:23:32 +01:00
|
|
|
import {Platform, StatusBar} from 'react-native';
|
2019-06-25 22:20:24 +02:00
|
|
|
import LocaleManager from './utils/LocaleManager';
|
2019-07-31 14:22:36 +02:00
|
|
|
import AsyncStorageManager from "./utils/AsyncStorageManager";
|
2019-08-07 14:39:20 +02:00
|
|
|
import CustomIntroSlider from "./components/CustomIntroSlider";
|
2020-03-05 10:29:15 +01:00
|
|
|
import {SplashScreen} from 'expo';
|
2020-02-04 12:23:32 +01:00
|
|
|
import ThemeManager from './utils/ThemeManager';
|
2020-03-06 23:15:01 +01:00
|
|
|
import {NavigationContainer} from '@react-navigation/native';
|
|
|
|
import {createStackNavigator} from '@react-navigation/stack';
|
2020-03-05 10:29:15 +01:00
|
|
|
import DrawerNavigator from './navigation/DrawerNavigator';
|
2020-03-05 21:48:37 +01:00
|
|
|
import NotificationsManager from "./utils/NotificationsManager";
|
2020-03-06 23:15:01 +01:00
|
|
|
import {Provider as PaperProvider} from 'react-native-paper';
|
2020-03-11 19:55:48 +01:00
|
|
|
import AprilFoolsManager from "./utils/AprilFoolsManager";
|
2020-03-11 21:04:17 +01:00
|
|
|
import Update from "./constants/Update";
|
2019-06-29 13:37:21 +02:00
|
|
|
|
|
|
|
type Props = {};
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
isLoading: boolean,
|
2019-08-05 17:18:48 +02:00
|
|
|
showIntro: boolean,
|
2019-09-16 00:10:14 +02:00
|
|
|
showUpdate: boolean,
|
2020-03-11 19:55:48 +01:00
|
|
|
showAprilFools: boolean,
|
2019-06-29 13:37:21 +02:00
|
|
|
currentTheme: ?Object,
|
|
|
|
};
|
|
|
|
|
2020-03-05 10:29:15 +01:00
|
|
|
const Stack = createStackNavigator();
|
|
|
|
|
2019-06-29 13:37:21 +02:00
|
|
|
export default class App extends React.Component<Props, State> {
|
2019-06-25 22:16:14 +02:00
|
|
|
|
2019-06-29 13:37:21 +02:00
|
|
|
state = {
|
|
|
|
isLoading: true,
|
2019-08-05 17:18:48 +02:00
|
|
|
showIntro: true,
|
2019-09-16 00:10:14 +02:00
|
|
|
showUpdate: true,
|
2020-03-11 19:55:48 +01:00
|
|
|
showAprilFools: false,
|
2019-06-29 13:37:21 +02:00
|
|
|
currentTheme: null,
|
|
|
|
};
|
2019-06-25 22:20:24 +02:00
|
|
|
|
2020-03-05 21:48:37 +01:00
|
|
|
onIntroDone: Function;
|
2020-03-10 11:33:22 +01:00
|
|
|
onUpdateTheme: Function;
|
2020-03-05 21:48:37 +01:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
2019-06-29 13:37:21 +02:00
|
|
|
LocaleManager.initTranslations();
|
2020-03-05 21:48:37 +01:00
|
|
|
this.onIntroDone = this.onIntroDone.bind(this);
|
2020-03-10 11:33:22 +01:00
|
|
|
this.onUpdateTheme = this.onUpdateTheme.bind(this);
|
2020-03-08 19:50:17 +01:00
|
|
|
SplashScreen.preventAutoHide();
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|
|
|
|
|
2019-06-29 13:37:21 +02:00
|
|
|
/**
|
2020-03-07 11:49:32 +01:00
|
|
|
* Updates the theme
|
2019-06-29 13:37:21 +02:00
|
|
|
*/
|
2020-03-10 11:33:22 +01:00
|
|
|
onUpdateTheme() {
|
2019-08-20 20:00:34 +02:00
|
|
|
this.setState({
|
|
|
|
currentTheme: ThemeManager.getCurrentTheme()
|
|
|
|
});
|
2019-09-17 10:37:52 +02:00
|
|
|
this.setupStatusBar();
|
2019-08-20 20:00:34 +02:00
|
|
|
}
|
|
|
|
|
2019-09-17 10:37:52 +02:00
|
|
|
setupStatusBar() {
|
|
|
|
if (Platform.OS === 'ios') {
|
|
|
|
if (ThemeManager.getNightMode()) {
|
|
|
|
StatusBar.setBarStyle('light-content', true);
|
|
|
|
} else {
|
|
|
|
StatusBar.setBarStyle('dark-content', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-20 20:00:34 +02:00
|
|
|
/**
|
2019-09-16 00:10:14 +02:00
|
|
|
* Callback when user ends the intro. Save in preferences to avaoid showing back the introSlides
|
2019-08-20 20:00:34 +02:00
|
|
|
*/
|
|
|
|
onIntroDone() {
|
2019-09-16 00:10:14 +02:00
|
|
|
this.setState({
|
|
|
|
showIntro: false,
|
|
|
|
showUpdate: false,
|
2020-03-11 19:55:48 +01:00
|
|
|
showAprilFools: false,
|
2019-09-16 00:10:14 +02:00
|
|
|
});
|
2019-08-20 20:00:34 +02:00
|
|
|
AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.showIntro.key, '0');
|
2020-03-11 21:04:17 +01:00
|
|
|
AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.updateNumber.key, Update.number.toString());
|
2020-03-11 19:55:48 +01:00
|
|
|
AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.showAprilFoolsStart.key, '0');
|
2019-08-20 20:00:34 +02:00
|
|
|
}
|
|
|
|
|
2020-03-05 10:29:15 +01:00
|
|
|
async componentDidMount() {
|
|
|
|
await this.loadAssetsAsync();
|
|
|
|
}
|
|
|
|
|
2019-08-20 20:00:34 +02:00
|
|
|
async loadAssetsAsync() {
|
2019-08-06 13:28:11 +02:00
|
|
|
// Wait for custom fonts to be loaded before showing the app
|
2019-07-31 14:22:36 +02:00
|
|
|
await AsyncStorageManager.getInstance().loadPreferences();
|
2020-03-10 11:33:22 +01:00
|
|
|
ThemeManager.getInstance().setUpdateThemeCallback(this.onUpdateTheme);
|
2020-03-11 21:04:17 +01:00
|
|
|
await NotificationsManager.initExpoToken();
|
2020-03-05 10:29:15 +01:00
|
|
|
this.onLoadFinished();
|
2019-08-20 20:00:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onLoadFinished() {
|
2020-03-05 21:48:37 +01:00
|
|
|
// console.log("finished");
|
2019-08-06 13:28:11 +02:00
|
|
|
// Only show intro if this is the first time starting the app
|
2019-06-25 22:20:24 +02:00
|
|
|
this.setState({
|
|
|
|
isLoading: false,
|
2019-08-05 17:18:48 +02:00
|
|
|
currentTheme: ThemeManager.getCurrentTheme(),
|
2019-09-16 00:10:14 +02:00
|
|
|
showIntro: AsyncStorageManager.getInstance().preferences.showIntro.current === '1',
|
2020-03-11 21:04:17 +01:00
|
|
|
showUpdate: AsyncStorageManager.getInstance().preferences.updateNumber.current !== Update.number.toString(),
|
2020-03-11 19:55:48 +01:00
|
|
|
showAprilFools: AprilFoolsManager.getInstance().isAprilFoolsEnabled() && AsyncStorageManager.getInstance().preferences.showAprilFoolsStart.current === '1',
|
2019-06-25 22:20:24 +02:00
|
|
|
});
|
2019-09-17 10:37:52 +02:00
|
|
|
// Status bar goes dark if set too fast
|
2020-03-05 10:29:15 +01:00
|
|
|
setTimeout(this.setupStatusBar, 1000);
|
|
|
|
SplashScreen.hide();
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|
|
|
|
|
2019-06-29 13:37:21 +02:00
|
|
|
/**
|
|
|
|
* Renders the app based on loading state
|
|
|
|
*/
|
2019-06-25 22:20:24 +02:00
|
|
|
render() {
|
|
|
|
if (this.state.isLoading) {
|
2020-03-05 10:29:15 +01:00
|
|
|
return null;
|
2020-03-11 19:55:48 +01:00
|
|
|
} else if (this.state.showIntro || this.state.showUpdate || this.state.showAprilFools) {
|
2020-03-08 13:21:14 +01:00
|
|
|
return <CustomIntroSlider
|
|
|
|
onDone={this.onIntroDone}
|
|
|
|
isUpdate={this.state.showUpdate && !this.state.showIntro}
|
2020-03-11 19:55:48 +01:00
|
|
|
isAprilFools={this.state.showAprilFools && !this.state.showIntro}
|
2020-03-08 13:21:14 +01:00
|
|
|
/>;
|
2019-08-05 17:18:48 +02:00
|
|
|
} else {
|
|
|
|
return (
|
2020-03-06 23:15:01 +01:00
|
|
|
<PaperProvider theme={this.state.currentTheme}>
|
|
|
|
<NavigationContainer theme={this.state.currentTheme}>
|
|
|
|
<Stack.Navigator headerMode="none">
|
|
|
|
<Stack.Screen name="Root" component={DrawerNavigator}/>
|
|
|
|
</Stack.Navigator>
|
|
|
|
</NavigationContainer>
|
|
|
|
</PaperProvider>
|
2019-08-05 17:18:48 +02:00
|
|
|
);
|
|
|
|
}
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|
|
|
|
}
|