2019-06-29 13:37:21 +02:00
|
|
|
// @flow
|
|
|
|
|
2019-06-25 22:16:14 +02:00
|
|
|
import React from 'react';
|
2019-06-28 11:35:15 +02:00
|
|
|
import {StyleProvider, Root, View} from 'native-base';
|
2019-06-25 22:20:24 +02:00
|
|
|
import AppNavigator from './navigation/AppNavigator';
|
|
|
|
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';
|
|
|
|
|
|
|
|
type Props = {};
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
isLoading: boolean,
|
|
|
|
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,
|
|
|
|
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-07-26 14:14:01 +02:00
|
|
|
* Loads FetchedData before components are mounted, like fonts and themes
|
2019-06-29 13:37:21 +02:00
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
2019-06-25 22:20:24 +02:00
|
|
|
async componentWillMount() {
|
|
|
|
await Font.loadAsync({
|
|
|
|
'Roboto': require('native-base/Fonts/Roboto.ttf'),
|
|
|
|
'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'),
|
|
|
|
});
|
2019-06-29 13:37:21 +02:00
|
|
|
ThemeManager.getInstance().setUpdateThemeCallback(() => this.updateTheme());
|
2019-06-25 22:20:24 +02:00
|
|
|
await ThemeManager.getInstance().getDataFromPreferences();
|
|
|
|
this.setState({
|
|
|
|
isLoading: false,
|
|
|
|
currentTheme: ThemeManager.getInstance().getCurrentTheme()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-29 13:37:21 +02:00
|
|
|
/**
|
|
|
|
* Updates the theme and clears the cache to force reloading the app colors
|
|
|
|
*/
|
2019-06-25 22:20:24 +02:00
|
|
|
updateTheme() {
|
2019-06-28 13:47:52 +02:00
|
|
|
// console.log('update theme called');
|
2019-06-28 11:35:15 +02:00
|
|
|
this.setState({
|
|
|
|
currentTheme: ThemeManager.getInstance().getCurrentTheme()
|
|
|
|
});
|
|
|
|
clearThemeCache();
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|
|
|
|
|
2019-06-29 13:37:21 +02:00
|
|
|
/**
|
|
|
|
* Renders the app based on loading state
|
|
|
|
*
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
2019-06-25 22:20:24 +02:00
|
|
|
render() {
|
|
|
|
if (this.state.isLoading) {
|
|
|
|
return <View/>;
|
|
|
|
}
|
2019-06-28 13:47:52 +02:00
|
|
|
// console.log('rendering');
|
|
|
|
// console.log(this.state.currentTheme.variables.containerBgColor);
|
2019-06-25 22:20:24 +02:00
|
|
|
return (
|
2019-06-28 11:35:15 +02:00
|
|
|
<Root>
|
|
|
|
<StyleProvider style={this.state.currentTheme}>
|
|
|
|
|
2019-06-27 10:17:51 +02:00
|
|
|
<AppNavigator/>
|
2019-06-28 11:35:15 +02:00
|
|
|
|
|
|
|
</StyleProvider>
|
|
|
|
</Root>
|
|
|
|
);
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|
|
|
|
}
|