index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. import Analytics from 'appcenter-analytics';
  19. const Index = () => {
  20. useEffect(() => {
  21. Analytics.trackEvent("IntoApp", {versionName: app.versionName, versionCode: app.versionCode});
  22. if (isIos) {
  23. checkUpdate();
  24. }
  25. })
  26. return (
  27. <RootSiblingParent>
  28. <StatusBar barStyle={themeStatusBar} backgroundColor={colorPrimaryDark}/>
  29. { isIOS
  30. ? <KeyboardAvoidingView style={ui.flex1} behavior="padding">
  31. <Router />
  32. </KeyboardAvoidingView>
  33. : <Router />
  34. }
  35. <ModalPortal />
  36. <SafeAreaView style={{flex: 0, backgroundColor: colorLight}}></SafeAreaView>
  37. </RootSiblingParent>
  38. );
  39. };
  40. const checkUpdate = () => {
  41. console.log("[CodePush]", "Checking Update");
  42. Analytics.trackEvent('checkUpdate', { versionName: app.versionName, versionCode: app.versionCode });
  43. //codePush.disallowRestart();
  44. codePush.sync({
  45. updateDialog: app.debug,
  46. installMode: codePush.InstallMode.IMMEDIATE
  47. }, status => {
  48. //Analytics.trackEvent('checkUpdate-status', status);
  49. switch(status) {
  50. case codePush.SyncStatus.DOWNLOADING_PACKAGE:
  51. if (app.debug) {
  52. toastShort("Downloading update...")
  53. }
  54. console.log("[CodePush]", "Downloading update");
  55. break;
  56. case codePush.SyncStatus.INSTALLING_UPDATE:
  57. if (app.debug) {
  58. toastShort("Installing update")
  59. }
  60. console.log("[CodePush]", "Installing update");
  61. break;
  62. case codePush.SyncStatus.UP_TO_DATE:
  63. if (app.debug) {
  64. toastShort("App is up to date")
  65. }
  66. console.log("[CodePush]", "App is up to date");
  67. codePush.notifyAppReady();
  68. break;
  69. case codePush.SyncStatus.UPDATE_INSTALLED:
  70. if (app.debug) {
  71. toastShort("Update installed")
  72. }
  73. console.log("[CodePush]", "Update installed");
  74. codePush.notifyAppReady();
  75. //codePush.restartApp(true);
  76. break;
  77. }
  78. }, process => {
  79. });
  80. }
  81. //热更新配置
  82. let codePushIos = {
  83. updateDialog: true,
  84. //实时检测更新并下载
  85. checkFrequency: codePush.CheckFrequency.MANUAL,
  86. //下载完成后立即安装
  87. //installMode: codePush.InstallMode.IMMEDIATE
  88. //下次进入安装
  89. //installMode: codePush.InstallMode.ON_NEXT_RESTART
  90. };
  91. let codePushAndroid = {
  92. updateDialog: true,
  93. //实时检测更新并下载
  94. checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
  95. //下载完成后立即安装
  96. installMode: codePush.InstallMode.IMMEDIATE
  97. //下次进入安装
  98. //installMode: codePush.InstallMode.ON_NEXT_RESTART
  99. }
  100. AppRegistry.registerComponent(app.name, () => codePush(isIOS ? codePushIos : codePushAndroid)(Index));
  101. //AppRegistry.registerComponent(appName, () => Index);