/** * @format */ import React, { useEffect } from 'react'; import {AppRegistry, KeyboardAvoidingView, StatusBar} from 'react-native'; import codePush from "react-native-code-push"; import 'react-native-gesture-handler'; import './app/utils/themes' import './app/utils/constant'; import './app/utils/notification'; import './app/utils/vector_icon'; import Router from './app/pages/Router'; import app from './app.json'; //import {ModalPortal} from 'react-native-modals'; import ModalPortal from './app/components/ModalPortal'; import {RootSiblingParent} from 'react-native-root-siblings'; import { SafeAreaView } from 'react-native-safe-area-context'; import Analytics from 'appcenter-analytics'; const Index = () => { useEffect(() => { checkUpdate(); }) return ( { isIOS ? : } ); }; const checkUpdate = () => { console.log("[CodePush]", "Checking Update"); Analytics.trackEvent('checkUpdate', { versionName: app.versionName, versionCode: app.versionCode }); //codePush.disallowRestart(); codePush.sync({ updateDialog: app.debug, installMode: codePush.InstallMode.IMMEDIATE }, status => { //Analytics.trackEvent('checkUpdate-status', status); switch(status) { case codePush.SyncStatus.DOWNLOADING_PACKAGE: if (app.debug) { toastShort("Downloading update...") } console.log("[CodePush]", "Downloading update"); break; case codePush.SyncStatus.INSTALLING_UPDATE: if (app.debug) { toastShort("Installing update") } console.log("[CodePush]", "Installing update"); break; case codePush.SyncStatus.UP_TO_DATE: if (app.debug) { toastShort("App is up to date") } console.log("[CodePush]", "App is up to date"); codePush.notifyAppReady(); break; case codePush.SyncStatus.UPDATE_INSTALLED: if (app.debug) { toastShort("Update installed") } console.log("[CodePush]", "Update installed"); //codePush.notifyAppReady(); //codePush.restartApp(true); break; } }, process => { }); } //热更新配置 let codePushOptions = { updateDialog: isIOS, //实时检测更新并下载 checkFrequency: codePush.CheckFrequency.MANUAL, //下载完成后立即安装 installMode: codePush.InstallMode.IMMEDIATE //下次进入安装 //installMode: codePush.InstallMode.ON_NEXT_RESTART }; AppRegistry.registerComponent(app.name, () => codePush(codePushOptions)(Index)); //AppRegistry.registerComponent(appName, () => Index);