AppStart.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import React, { PureComponent, } from 'react'
  2. import { NavigationContainer } from '@react-navigation/native'
  3. import * as RootNavigation from './src/navigations/RootNavigation'
  4. import { navigationRef } from './src/navigations/RootNavigation'
  5. import analytics from '@react-native-firebase/analytics'
  6. import { checkMultiple, requestMultiple, requestNotifications, PERMISSIONS } from 'react-native-permissions'
  7. import { ModalPortal } from 'react-native-modals'
  8. import { Provider } from 'react-redux'
  9. import { store } from './src/redux/store'
  10. import GlobalModals from './src/components/globalModals/GlobalModals'
  11. import t, { languageConfig, } from './src/translator/translator'
  12. export let appStartInstance: AppStart = null
  13. export default class AppStart extends PureComponent
  14. {
  15. navigationContainer: NavigationContainer = { }
  16. routeName: String = ''
  17. defaultCoreUri = null
  18. constructor(props)
  19. {
  20. super(props)
  21. this.initialMethodsForMainView = this.initialMethodsForMainView.bind(this)
  22. this.state = {
  23. content: null,
  24. }
  25. appStartInstance = this
  26. }
  27. async componentDidMount()
  28. {
  29. await this.initialMethodsForMainView()
  30. }
  31. async initialMethodsForMainView()
  32. {
  33. await languageConfig.init()
  34. await this.askAllPermissions()
  35. // if(__DEV__)
  36. // {
  37. // globalData.setCoreIdentityApiUri('https://identity-test.novbem.az')
  38. // globalData.setCoreApiUri('https://business-api-test.novbem.az')
  39. // }
  40. // else
  41. // {
  42. // globalData.setCoreIdentityApiUri('https://identity.novbem.az')
  43. // globalData.setCoreApiUri('https://business-api.novbem.az/v2.2.0')
  44. // }
  45. // let isAuthorized = await storageService.getIsAuthorized()
  46. // if(isAuthorized)
  47. this.mainNavInit()
  48. // else
  49. // this.loginNavInit()
  50. }
  51. async askAllPermissions()
  52. {
  53. requestMultiple([
  54. PERMISSIONS.ANDROID.CAMERA,
  55. PERMISSIONS.ANDROID.RECORD_AUDIO,
  56. PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE,
  57. PERMISSIONS.ANDROID.WRITE_EXTERNAL_STORAGE,
  58. PERMISSIONS.IOS.CAMERA,
  59. PERMISSIONS.IOS.MICROPHONE,
  60. ])
  61. // .then(statuses => console.log('--- request statutes', statuses))
  62. requestNotifications([
  63. 'alert',
  64. 'badge',
  65. 'carPlay',
  66. 'criticalAlert',
  67. 'provisional',
  68. 'sound',
  69. ]).then(obj => console.log('--- obj', obj))
  70. }
  71. async loginNavInit()
  72. {
  73. this.setState({
  74. content: (await import('./src/navigations/LoginNavigation')).default,
  75. })
  76. }
  77. async mainNavInit()
  78. {
  79. // let currAuth = await storageService.getCurrentAuth()
  80. // globalData.setCurrentAuth(currAuth)
  81. // console.log('---- current auth', currAuth)
  82. // let currUser = await storageService.getCurrentUser()
  83. // globalData.setCurrentUser(currUser)
  84. this.setState({
  85. content: (await import('./src/navigations/MainNavigation')).default,
  86. // content: (await im/port('./src/navigations/LoginNavigation')).default,
  87. })
  88. }
  89. updateAllComponent()
  90. {
  91. this.forceUpdate()
  92. navigationRef?.current?.setParams()
  93. }
  94. render()
  95. {
  96. if(!this.state.content)
  97. return null
  98. return (
  99. <Provider store={ store }>
  100. <NavigationContainer
  101. ref = { ref => { navigationRef; this.navigationContainer = ref } }
  102. onReady = { () => {
  103. if(this.navigationContainer)
  104. this.routeName = this.navigationContainer.getCurrentRoute().name;
  105. }}
  106. onStateChange = { async () => {
  107. const previousRouteName = this.routeName;
  108. const currentRouteName = this.navigationContainer.getCurrentRoute().name;
  109. if (previousRouteName !== currentRouteName)
  110. await analytics().logScreenView({
  111. screen_name: currentRouteName,
  112. screen_class: currentRouteName,
  113. })
  114. this.routeName = currentRouteName;
  115. }}
  116. >
  117. <this.state.content/>
  118. </NavigationContainer>
  119. <ModalPortal/>
  120. <GlobalModals/>
  121. </Provider>
  122. )
  123. }
  124. async onLogined()
  125. {
  126. this.setState({
  127. content: (await import('./src/navigations/MainNavigation')).default,
  128. })
  129. this.notificationConfig()
  130. // this.initialMethodsForMainView()
  131. }
  132. async onLogOut()
  133. {
  134. // this.initialMethodsForMainView()
  135. // this.setState({
  136. // content: (await import('./src/navigations/LoginNavigation')).default,
  137. // })
  138. }
  139. }