2019-06-29 13:37:21 +02:00
|
|
|
// @flow
|
|
|
|
|
2019-08-06 13:28:11 +02:00
|
|
|
import * as React from 'react';
|
2019-09-17 10:37:52 +02:00
|
|
|
import {StatusBar, Platform } from 'react-native';
|
2019-08-07 14:39:20 +02:00
|
|
|
import {Root, StyleProvider} from 'native-base';
|
2019-09-12 23:02:28 +02:00
|
|
|
import {createAppContainerWithInitialRoute} from './navigation/AppNavigator';
|
2019-06-25 22:20:24 +02:00
|
|
|
import ThemeManager from './utils/ThemeManager';
|
|
|
|
import LocaleManager from './utils/LocaleManager';
|
|
|
|
import * as Font from 'expo-font';
|
2019-06-28 11:35:15 +02:00
|
|
|
// edited native-base-shoutem-theme according to
|
|
|
|
// https://github.com/GeekyAnts/theme/pull/5/files/91f67c55ca6e65fe3af779586b506950c9f331be#diff-4cfc2dd4d5dae7954012899f2268a422
|
|
|
|
// to allow for dynamic theme switching
|
2019-06-29 13:37:21 +02:00
|
|
|
import {clearThemeCache} from 'native-base-shoutem-theme';
|
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";
|
2019-08-20 20:00:34 +02:00
|
|
|
import {AppLoading} from 'expo';
|
2019-08-13 12:20:03 +02:00
|
|
|
import NotificationsManager from "./utils/NotificationsManager";
|
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,
|
2019-06-29 13:37:21 +02:00
|
|
|
currentTheme: ?Object,
|
|
|
|
};
|
|
|
|
|
|
|
|
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,
|
2019-06-29 13:37:21 +02:00
|
|
|
currentTheme: null,
|
|
|
|
};
|
2019-06-25 22:20:24 +02:00
|
|
|
|
2019-06-29 13:37:21 +02:00
|
|
|
constructor(props: Object) {
|
2019-06-25 22:20:24 +02:00
|
|
|
super(props);
|
2019-06-29 13:37:21 +02:00
|
|
|
LocaleManager.initTranslations();
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|
|
|
|
|
2019-06-29 13:37:21 +02:00
|
|
|
/**
|
2019-08-20 20:00:34 +02:00
|
|
|
* Updates the theme and clears the cache to force reloading the app colors. Need to edit shoutem theme for ti to work
|
2019-06-29 13:37:21 +02:00
|
|
|
*/
|
2019-08-20 20:00:34 +02:00
|
|
|
updateTheme() {
|
|
|
|
this.setState({
|
|
|
|
currentTheme: ThemeManager.getCurrentTheme()
|
|
|
|
});
|
2019-09-17 10:37:52 +02:00
|
|
|
this.setupStatusBar();
|
2019-08-20 20:00:34 +02:00
|
|
|
clearThemeCache();
|
|
|
|
}
|
|
|
|
|
2019-09-17 10:37:52 +02:00
|
|
|
setupStatusBar() {
|
|
|
|
if (Platform.OS === 'ios') {
|
|
|
|
console.log(ThemeManager.getNightMode());
|
|
|
|
if (ThemeManager.getNightMode()) {
|
|
|
|
console.log('setting light mode');
|
|
|
|
StatusBar.setBarStyle('light-content', true);
|
|
|
|
} else {
|
|
|
|
console.log('setting dark mode');
|
|
|
|
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,
|
|
|
|
});
|
2019-08-20 20:00:34 +02:00
|
|
|
AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.showIntro.key, '0');
|
2019-09-20 09:52:27 +02:00
|
|
|
AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.showUpdate2.key, '0');
|
2019-08-20 20:00:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async loadAssetsAsync() {
|
|
|
|
console.log('Starting loading assets...');
|
2019-08-06 13:28:11 +02:00
|
|
|
// Wait for custom fonts to be loaded before showing the app
|
2019-06-25 22:20:24 +02:00
|
|
|
await Font.loadAsync({
|
|
|
|
'Roboto': require('native-base/Fonts/Roboto.ttf'),
|
|
|
|
'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'),
|
|
|
|
});
|
2019-07-31 14:22:36 +02:00
|
|
|
await AsyncStorageManager.getInstance().loadPreferences();
|
2019-06-29 13:37:21 +02:00
|
|
|
ThemeManager.getInstance().setUpdateThemeCallback(() => this.updateTheme());
|
2019-08-13 12:20:03 +02:00
|
|
|
await NotificationsManager.initExpoToken();
|
2019-09-17 10:37:52 +02:00
|
|
|
// console.log(AsyncStorageManager.getInstance().preferences.expoToken.current);
|
2019-08-20 20:00:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onLoadFinished() {
|
2019-08-06 13:28:11 +02:00
|
|
|
// Only show intro if this is the first time starting the app
|
2019-08-20 20:00:34 +02:00
|
|
|
console.log('Finished loading');
|
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',
|
2019-09-20 09:52:27 +02:00
|
|
|
showUpdate: AsyncStorageManager.getInstance().preferences.showUpdate2.current === '1'
|
2019-08-08 13:57:03 +02:00
|
|
|
// showIntro: true
|
2019-06-25 22:20:24 +02:00
|
|
|
});
|
2019-09-17 10:37:52 +02:00
|
|
|
// Status bar goes dark if set too fast
|
|
|
|
setTimeout(this.setupStatusBar,
|
|
|
|
1000
|
|
|
|
)
|
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) {
|
2019-08-20 20:00:34 +02:00
|
|
|
return (
|
|
|
|
<AppLoading
|
2019-08-21 17:07:27 +02:00
|
|
|
startAsync={() => this.loadAssetsAsync()}
|
2019-08-20 20:00:34 +02:00
|
|
|
onFinish={() => this.onLoadFinished()}
|
|
|
|
onError={console.warn}
|
|
|
|
/>
|
|
|
|
);
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|
2019-09-16 00:10:14 +02:00
|
|
|
if (this.state.showIntro || this.state.showUpdate) {
|
|
|
|
return <CustomIntroSlider onDone={() => this.onIntroDone()} isUpdate={this.state.showUpdate && !this.state.showIntro}/>;
|
2019-08-05 17:18:48 +02:00
|
|
|
} else {
|
2019-09-12 23:02:28 +02:00
|
|
|
const AppNavigator = createAppContainerWithInitialRoute(AsyncStorageManager.getInstance().preferences.defaultStartScreen.current);
|
2019-08-05 17:18:48 +02:00
|
|
|
return (
|
|
|
|
<Root>
|
|
|
|
<StyleProvider style={this.state.currentTheme}>
|
2019-08-07 14:39:20 +02:00
|
|
|
<AppNavigator/>
|
2019-08-05 17:18:48 +02:00
|
|
|
</StyleProvider>
|
|
|
|
</Root>
|
|
|
|
);
|
|
|
|
}
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|
|
|
|
}
|