index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * @format
  3. */
  4. import React, { useEffect } from 'react';
  5. import {AppRegistry, KeyboardAvoidingView, StatusBar} from 'react-native';
  6. import codePush from "react-native-code-push";
  7. import 'react-native-gesture-handler';
  8. import './app/utils/themes'
  9. import './app/utils/constant';
  10. import './app/utils/notification';
  11. import './app/utils/vector_icon';
  12. import Router from './app/pages/Router';
  13. import app from './app.json';
  14. //import {ModalPortal} from 'react-native-modals';
  15. import ModalPortal from './app/components/ModalPortal';
  16. import {RootSiblingParent} from 'react-native-root-siblings';
  17. import { SafeAreaView } from 'react-native-safe-area-context';
  18. const Index = () => {
  19. useEffect(() => {
  20. //Analytics.trackEvent("IntoApp", {versionName: app.versionName, versionCode: app.versionCode});
  21. if (isIOS) {
  22. checkUpdate();
  23. }
  24. })
  25. return (
  26. <RootSiblingParent>
  27. <StatusBar barStyle={themeStatusBar} backgroundColor={colorPrimaryDark}/>
  28. { isIOS
  29. ? <KeyboardAvoidingView style={ui.flex1} behavior="padding">
  30. <Router />
  31. </KeyboardAvoidingView>
  32. : <Router />
  33. }
  34. <ModalPortal />
  35. <SafeAreaView style={{flex: 0, backgroundColor: colorLight}}></SafeAreaView>
  36. </RootSiblingParent>
  37. );
  38. };
  39. const checkUpdate = () => {
  40. console.log("[CodePush-iOS]", "Checking Update");
  41. //Analytics.trackEvent('checkUpdate', { versionName: app.versionName, versionCode: app.versionCode });
  42. //codePush.disallowRestart();
  43. codePush.sync({
  44. updateDialog: app.debug,
  45. installMode: codePush.InstallMode.IMMEDIATE
  46. }, status => {
  47. //Analytics.trackEvent('checkUpdate-status', status);
  48. switch(status) {
  49. case codePush.SyncStatus.DOWNLOADING_PACKAGE:
  50. if (app.debug) {
  51. toastShort("Downloading update...")
  52. }
  53. console.log("[CodePush-iOS]", "Downloading update");
  54. break;
  55. case codePush.SyncStatus.INSTALLING_UPDATE:
  56. if (app.debug) {
  57. toastShort("Installing update")
  58. }
  59. console.log("[CodePush-iOS]", "Installing update");
  60. break;
  61. case codePush.SyncStatus.UP_TO_DATE:
  62. if (app.debug) {
  63. toastShort("App is up to date")
  64. }
  65. console.log("[CodePush-iOS]", "App is up to date");
  66. codePush.notifyAppReady();
  67. break;
  68. case codePush.SyncStatus.UPDATE_INSTALLED:
  69. if (app.debug) {
  70. toastShort("Update installed")
  71. }
  72. console.log("[CodePush-iOS]", "Update installed");
  73. codePush.notifyAppReady();
  74. //codePush.restartApp(true);
  75. break;
  76. }
  77. }, process => {
  78. });
  79. }
  80. //热更新配置
  81. let codePushIos = {
  82. updateDialog: true,
  83. //实时检测更新并下载
  84. checkFrequency: codePush.CheckFrequency.MANUAL,
  85. //下载完成后立即安装
  86. //installMode: codePush.InstallMode.IMMEDIATE
  87. //下次进入安装
  88. //installMode: codePush.InstallMode.ON_NEXT_RESTART
  89. };
  90. let codePushAndroid = {
  91. updateDialog: false,
  92. //实时检测更新并下载
  93. checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
  94. //下载完成后立即安装
  95. installMode: codePush.InstallMode.IMMEDIATE
  96. //下次进入安装
  97. //installMode: codePush.InstallMode.ON_NEXT_RESTART
  98. }
  99. AppRegistry.registerComponent(app.name, () => codePush(isIOS ? codePushIos : codePushAndroid)(Index));
  100. //AppRegistry.registerComponent(appName, () => Index);