| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /**
- * @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(() => {
- Analytics.trackEvent("IntoApp", {versionName: app.versionName, versionCode: app.versionCode});
- if (isIos) {
- checkUpdate();
- }
- })
- return (
- <RootSiblingParent>
- <StatusBar barStyle={themeStatusBar} backgroundColor={colorPrimaryDark}/>
- { isIOS
- ? <KeyboardAvoidingView style={ui.flex1} behavior="padding">
- <Router />
- </KeyboardAvoidingView>
- : <Router />
- }
- <ModalPortal />
- <SafeAreaView style={{flex: 0, backgroundColor: colorLight}}></SafeAreaView>
- </RootSiblingParent>
- );
- };
- 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 codePushIos = {
- updateDialog: true,
- //实时检测更新并下载
- checkFrequency: codePush.CheckFrequency.MANUAL,
- //下载完成后立即安装
- //installMode: codePush.InstallMode.IMMEDIATE
- //下次进入安装
- //installMode: codePush.InstallMode.ON_NEXT_RESTART
- };
- let codePushAndroid = {
- updateDialog: true,
- //实时检测更新并下载
- checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
- //下载完成后立即安装
- installMode: codePush.InstallMode.IMMEDIATE
- //下次进入安装
- //installMode: codePush.InstallMode.ON_NEXT_RESTART
- }
- AppRegistry.registerComponent(app.name, () => codePush(isIOS ? codePushIos : codePushAndroid)(Index));
- //AppRegistry.registerComponent(appName, () => Index);
|