/* eslint-disable react/no-unstable-nested-components */ /* eslint-disable react-native/no-inline-styles */ import React, {useState} from 'react'; import {StyleSheet, Text, View, TouchableOpacity, Image} from 'react-native'; import TestConsole from './TestConsole'; import _updateConfig from './update.json'; import {PushyProvider, Pushy, usePushy} from 'react-native-update'; const {appKey} = _updateConfig.android; function Home() { const { client, checkUpdate, downloadUpdate, switchVersionLater, switchVersion, updateInfo, packageVersion, currentHash, progress: {received, total} = {}, } = usePushy(); const [useDefaultAlert, setUseDefaultAlert] = useState(false); const [showTestConsole, setShowTestConsole] = useState(false); const [showUpdateBanner, setShowUpdateBanner] = useState(false); const [showUpdateSnackbar, setShowUpdateSnackbar] = useState(false); // if (updateInfo) { // updateInfo!.name = 'name'; // updateInfo!.update = true; // } const snackbarVisible = !useDefaultAlert && showUpdateSnackbar && updateInfo?.update; if (showTestConsole) { return ( setShowTestConsole(false)} /> ); } return ( 欢迎使用Pushy热更新服务 {/* 😁hdiffFromAPP更新成功!!! */} {/* 😁hdiffFromPPk更新成功!!! */} { client?.setOptions({ updateStrategy: !useDefaultAlert ? null : 'alwaysAlert', }); setShowUpdateSnackbar(useDefaultAlert); setUseDefaultAlert(!useDefaultAlert); }} style={{ flexDirection: 'row', alignItems: 'center', }}> {useDefaultAlert && } {' '} {useDefaultAlert ? '当前使用' : '当前不使用'}默认的alert更新提示 这是版本一 {'\n'} 当前原生包版本号: {packageVersion} {'\n'} 当前热更新版本Hash: {currentHash || '(空)'} {'\n'} 下载进度:{received} / {total} { checkUpdate(); setShowUpdateSnackbar(true); }}> 点击这里检查更新 { setShowTestConsole(true); }}> react-native-update版本:{client?.version} {snackbarVisible && ( 有新版本({updateInfo.name})可用,是否更新? setShowUpdateSnackbar(false)} style={{marginRight: 10}}> 取消 { setShowUpdateSnackbar(false); await downloadUpdate(); setShowUpdateBanner(true); }}> 更新 )} {showUpdateBanner && ( 更新已完成,是否立即重启? { switchVersionLater(); setShowUpdateBanner(false); }} style={{marginRight: 20}}> 下次再说 立即重启 )} ); } const styles = StyleSheet.create({ overlay: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: 'rgba(0, 0, 0, 0.5)', justifyContent: 'center', alignItems: 'center', }, container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: { fontSize: 20, textAlign: 'center', margin: 10, }, instructions: { textAlign: 'center', color: '#333333', marginBottom: 5, }, image: {}, }); const pushyClient = new Pushy({ appKey, debug: true, }); export default function HomeScreen() { return ( ); }