App.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import React, { PureComponent } from 'react'
  2. import { View, StatusBar, StyleSheet } from 'react-native'
  3. import { StorageService, } from './src/others'
  4. import { store, } from './src/redux/store'
  5. import { AppGlobalAC, } from './src/redux/actionCreators'
  6. import Colors from './src/constants/Colors'
  7. export default class App extends PureComponent
  8. {
  9. constructor(props)
  10. {
  11. super(props)
  12. this.initialMethodsForStartApp = this.initialMethodsForStartApp.bind(this)
  13. this.state = {
  14. MainComponent : null,
  15. isAppReady : false
  16. }
  17. }
  18. componentDidMount()
  19. {
  20. this.initialMethodsForStartApp()
  21. }
  22. async initialMethodsForStartApp()
  23. {
  24. try {
  25. await this.fillGlobalStates()
  26. this.setState({
  27. MainComponent : (await import('./AppStart.js')).default,
  28. isAppReady: true,
  29. })
  30. }
  31. catch(err)
  32. {
  33. this.setState({
  34. isAppReady: false,
  35. })
  36. }
  37. }
  38. async fillGlobalStates()
  39. {
  40. let voicePrankCategory = await StorageService.getVoicePrankCategory()
  41. store.dispatch(AppGlobalAC.changeVoicePrankCategory(voicePrankCategory))
  42. }
  43. render()
  44. {
  45. if(!this.state.isAppReady)
  46. return null // <LaunchPage/>
  47. return (
  48. <>
  49. <StatusBar
  50. barStyle = 'dark-content'
  51. backgroundColor = { Colors.d_Header }
  52. />
  53. <View style={ styles.appView }>
  54. <this.state.MainComponent/>
  55. </View>
  56. </>
  57. )
  58. }
  59. }
  60. const styles = StyleSheet.create({
  61. appView: {
  62. flex: 1,
  63. },
  64. })