App.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. *
  5. * @format
  6. * @flow
  7. */
  8. import React, { Fragment } from 'react';
  9. import { StatusBar, SafeAreaView, Modal, View, Text, ActivityIndicator, AppState, Image } from 'react-native';
  10. import Navigator from '~/Screens/Navigator';
  11. import { Provider } from 'react-redux';
  12. import configureStore from '~/configureStore';
  13. import * as Font from 'expo-font';
  14. import { SelectboxListProvider } from './Components/UIControls/Selectbox';
  15. import { DateTimePickerProvider } from './Components/UIControls/DateTimePicker';
  16. import { Util } from './Utils/utils';
  17. import { SearchProvider } from './Components/Listing/Search';
  18. import { PopupProvider } from './Components/UIControls/Popup/Provider';
  19. import { PromptProvider, showMessage, confirm, MessageProvider, alert } from './Components/UIControls/Message';
  20. import session from './Utils/session';
  21. import { Updates, SplashScreen } from 'expo';
  22. import { SplashProvider } from './Components/Splash';
  23. import { MonthPickerProvider } from './Components/UIControls/MonthPicker';
  24. import { UploadFileProvider } from './Components/UIControls/UploadFile';
  25. import { CameraProvider } from './Components/UIControls/CameraProvider';
  26. import { PhoneProvider } from './Components/UIControls/Phone';
  27. import { DownloadProvider } from './Components/UIControls/Download';
  28. import * as Notifications from 'expo-notifications';
  29. const preloadedState = {};
  30. export const store = configureStore(preloadedState);
  31. Notifications.setNotificationHandler({
  32. handleNotification: async () => ({
  33. shouldShowAlert: true,
  34. shouldPlaySound: false,
  35. shouldSetBadge: false,
  36. }),
  37. });
  38. class App extends React.Component {
  39. state = {
  40. fontLoaded: false,
  41. updating: false,
  42. appState: AppState.currentState,
  43. expoPushToken: '',
  44. };
  45. checkForUpdates = async () => {
  46. try {
  47. const update = await Updates.checkForUpdateAsync();
  48. if(update.isAvailable) {
  49. confirm('업데이트 알림', '새로운 버젼이 있습니다. 업데이트 하시겠습니까?', () => {
  50. this.runUpdate();
  51. });
  52. }
  53. } catch (error) {
  54. showMessage(error.message);
  55. }
  56. }
  57. runUpdate = async () => {
  58. this.setState({ ...this.state, updating: true });
  59. await Updates.fetchUpdateAsync();
  60. Updates.reloadFromCache();
  61. this.setState({ ...this.state, updating: false });
  62. }
  63. handleAppStateChange = (nextAppState) => {
  64. if(this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
  65. // onresume
  66. if(!__DEV__) {
  67. this.checkForUpdates();
  68. }
  69. }
  70. this.setState({...this.state, appState:nextAppState});
  71. }
  72. handleNotification = (notification) => {
  73. console.log(notification);
  74. }
  75. handleNotificationResponse = (response) => {
  76. console.log(response);
  77. }
  78. componentDidMount = async () => {
  79. SplashScreen.preventAutoHide();
  80. if(!__DEV__) {
  81. this.checkForUpdates();
  82. }
  83. AppState.addEventListener('change', this.handleAppStateChange);
  84. /*
  85. Notifications.addNotificationReceivedListener(this.handleNotification);
  86. Notifications.addNotificationResponseReceivedListener(this.handleNotificationResponse);
  87. */
  88. await Font.loadAsync({
  89. 'NotoSansCJKkr-Black': require('~/Assets/Fonts/NotoSansKR-Black.otf'),
  90. 'NotoSansCJKkr-Bold': require('~/Assets/Fonts/NotoSansKR-Bold.otf'),
  91. 'NotoSansCJKkr-DemiLight': require('~/Assets/Fonts/NotoSansKR-DemiLight.otf'),
  92. 'NotoSansCJKkr-Light': require('~/Assets/Fonts/NotoSansKR-Light.otf'),
  93. 'NotoSansCJKkr-Medium': require('~/Assets/Fonts/NotoSansKR-Medium.otf'),
  94. 'NotoSansCJKkr-Regular': require('~/Assets/Fonts/NotoSansKR-Regular.otf'),
  95. 'NotoSansCJKkr-Thin': require('~/Assets/Fonts/NotoSansKR-Thin.otf'),
  96. 'Roboto-Black': require('~/Assets/Fonts/Roboto-Black.ttf'),
  97. 'Roboto-Bold': require('~/Assets/Fonts/Roboto-Bold.ttf'),
  98. 'Roboto-Light': require('~/Assets/Fonts/Roboto-Light.ttf'),
  99. 'Roboto-Medium': require('~/Assets/Fonts/Roboto-Medium.ttf'),
  100. 'Roboto-Regular': require('~/Assets/Fonts/Roboto-Regular.ttf'),
  101. 'Roboto-Thin': require('~/Assets/Fonts/Roboto-Thin.ttf'),
  102. 'Roboto-Black-Italic': require('~/Assets/Fonts/Roboto-BlackItalic.ttf'),
  103. 'Roboto-Bold-Italic': require('~/Assets/Fonts/Roboto-BoldItalic.ttf'),
  104. 'Roboto-Light-Italic': require('~/Assets/Fonts/Roboto-LightItalic.ttf'),
  105. 'Roboto-Medium-Italic': require('~/Assets/Fonts/Roboto-MediumItalic.ttf'),
  106. 'Roboto-Regular-Italic': require('~/Assets/Fonts/Roboto-Italic.ttf'),
  107. 'Roboto-Thin-Italic': require('~/Assets/Fonts/Roboto-ThinItalic.ttf'),
  108. });
  109. await session.load();
  110. this.setState({ ...this.state, fontLoaded: true });
  111. }
  112. componentWillUnmount = () => {
  113. AppState.removeEventListener('change', this.handleAppStateChange);
  114. }
  115. render = () => {
  116. console.log('appState : ', this.state.appState);
  117. return (
  118. <Fragment>
  119. <SplashProvider>
  120. {this.state.fontLoaded ? (
  121. <Provider store={store}>
  122. <StatusBar translucent={true} barStyle={Platform.OS == 'android' ? 'default' : 'dark-content'} />
  123. <SafeAreaView style={{ flex: 1, marginTop: Util.getStatusBarHeight(), backgroundColor:'#ffffff' }}>
  124. <SearchProvider>
  125. <PopupProvider>
  126. <Navigator />
  127. </PopupProvider>
  128. </SearchProvider>
  129. </SafeAreaView>
  130. <SelectboxListProvider />
  131. <DateTimePickerProvider />
  132. <MonthPickerProvider />
  133. <PromptProvider />
  134. <MessageProvider />
  135. <UploadFileProvider />
  136. <CameraProvider />
  137. <PhoneProvider />
  138. <DownloadProvider />
  139. </Provider>
  140. ) : null}
  141. </SplashProvider>
  142. {this.state.appState.match(/inactive|background/) ? (
  143. <View
  144. style={{
  145. position:'absolute', left:0, right:0, top:0, bottom:0, backgroundColor:'black'
  146. }}
  147. >
  148. <Image
  149. style={{width:'100%', height:'100%'}}
  150. source={require('./../assets/splash.png')}
  151. resizeMode="cover"
  152. onLoadEnd={() => {}}
  153. fadeDuration={0}
  154. />
  155. </View>
  156. ) : null}
  157. <Modal visible={this.state.updating} transparent={true} animationType="fade">
  158. <View style={{
  159. position:'absolute', flexDirection:"column",
  160. left:'10%', top:'35%', right:'10%', bottom:'35%',
  161. alignItems:'center', justifyContent:'space-between',
  162. borderRadius:10, backgroundColor:'#0b83e6', overflow:'hidden'
  163. }}>
  164. <View style={{width:'100%', height:50, backgroundColor:'#0543a6', alignItems:'center', justifyContent:'center'}}>
  165. <Text style={{ fontSize:20, letterSpacing:-1.2, color:'white' }}>업데이트</Text>
  166. </View>
  167. <View style={{ flex:1, alignItems:'center', justifyContent:'center' }}>
  168. <ActivityIndicator size="large" color="white" style={{marginBottom:30}} />
  169. <View style={{ flexDirection:'column', alignItems:'center', justifyContent:'center' }}>
  170. <Text style={{ fontSize:20, letterSpacing:-1.2, color:'white'}}>업데이트 중입니다.</Text>
  171. <Text style={{ fontSize:20, letterSpacing:-1.2, color:'white'}}>잠시만 기다려주세요.</Text>
  172. </View>
  173. </View>
  174. </View>
  175. </Modal>
  176. </Fragment>
  177. );
  178. }
  179. }
  180. export default App;