1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-09-17 20:56:10 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Compare commits

..

10 Commits

Author SHA1 Message Date
sunnylqm
4923aff184 v10.0.1 2024-02-19 09:37:31 +08:00
sunnylqm
f6a38c1f48 fix: default strategy 2024-02-19 09:36:53 +08:00
Sunny Luo
92cfbb3fdf Merge pull request #426 from reactnativecn/v10
V10
2024-02-08 22:07:46 +08:00
sunnylqm
64ef8e129d fix: update example 2024-02-08 22:06:59 +08:00
sunnylqm
ce51b2ca81 v10.0.0-beta.3 2024-02-08 21:50:54 +08:00
sunnylqm
6c1662fce1 feat: add progress 2024-02-08 21:50:17 +08:00
sunnylqm
d9e4575964 fix example 2024-02-05 22:50:46 +08:00
sunnylqm
190103687c fix: options 2024-02-05 22:22:11 +08:00
sunnylqm
f6f055be64 update update.json 2024-02-05 22:09:53 +08:00
sunnylqm
05e5c5a1a7 v10.0.0-beta.2 2024-01-25 22:09:35 +08:00
8 changed files with 54 additions and 29 deletions

View File

@@ -18,7 +18,7 @@
"react-native": "0.69.8",
"react-native-paper": "^5.12.1",
"react-native-safe-area-context": "^4.8.2",
"react-native-update": "10.0.0-beta.1",
"react-native-update": "^10.0.0-beta.3",
"react-native-vector-icons": "^10.0.3"
},
"devDependencies": {

View File

@@ -33,7 +33,8 @@ function App() {
const [showUpdateBanner, setShowUpdateBanner] = useState(false);
const [showUpdateSnackbar, setShowUpdateSnackbar] = useState(false);
const snackbarVisible =
showUpdateSnackbar && updateInfo?.update && !useDefaultAlert;
!useDefaultAlert && showUpdateSnackbar && updateInfo?.update;
return (
<View style={styles.container}>
<Text style={styles.welcome}>使Pushy热更新服务</Text>
@@ -48,6 +49,7 @@ function App() {
client?.setOptions({
useAlert: v,
});
setShowUpdateSnackbar(!v);
}}
/>
</View>
@@ -66,7 +68,11 @@ function App() {
<Text>
{received} / {total}
</Text>
<TouchableOpacity onPress={checkUpdate}>
<TouchableOpacity
onPress={() => {
checkUpdate();
setShowUpdateSnackbar(true);
}}>
<Text style={styles.instructions}></Text>
</TouchableOpacity>
@@ -83,7 +89,7 @@ function App() {
<TestConsole visible={showTestConsole} />
{snackbarVisible && (
<Snackbar
visible={true}
visible={snackbarVisible}
onDismiss={() => {
setShowUpdateSnackbar(false);
}}
@@ -95,10 +101,13 @@ function App() {
setShowUpdateBanner(true);
},
}}>
<Text>({updateInfo.version})</Text>
<Text style={{color: 'white'}}>
({updateInfo.name})
</Text>
</Snackbar>
)}
<Banner
style={{width: '100%', position: 'absolute', top: 0}}
visible={showUpdateBanner}
actions={[
{

View File

@@ -1,10 +1,10 @@
{
"ios": {
"appId": 24794,
"appKey": "SqShg4Klnj2hG6LAFMW2PdcgSSuniz0T"
},
"android": {
"appId": 10977,
"appKey": "bUYKfZgtC9VirZsQbAt8qken2Gq2uxe3"
}
}
"ios": {
"appId": 24794,
"appKey": "SqShg4Klnj2hG6LAFMW2PdcgSSuniz0T"
},
"android": {
"appId": 27509,
"appKey": "aQz3Uc2pA7gt_prDaQ4rbWRY"
}
}

View File

@@ -6231,10 +6231,10 @@ react-native-safe-area-context@^4.8.2:
resolved "https://registry.yarnpkg.com/react-native-safe-area-context/-/react-native-safe-area-context-4.8.2.tgz#e6b3d8acf3c6afcb4b5db03a97f9c37df7668f65"
integrity sha512-ffUOv8BJQ6RqO3nLml5gxJ6ab3EestPiyWekxdzO/1MQ7NF8fW1Mzh1C5QE9yq573Xefnc7FuzGXjtesZGv7cQ==
react-native-update@10.0.0-beta.1:
version "10.0.0-beta.1"
resolved "https://registry.yarnpkg.com/react-native-update/-/react-native-update-10.0.0-beta.1.tgz#bc49a7197dd19c16ba798ea13324b4b292edd052"
integrity sha512-PFTsut8SL+vqAPtBUzPg9KKU9mFgCktKttifzM8B4puSoburlSN2UnD+eDWxLkXyIWQtoQAqAmXPE1/zA/e7dw==
react-native-update@^10.0.0-beta.3:
version "10.0.0-beta.3"
resolved "https://registry.yarnpkg.com/react-native-update/-/react-native-update-10.0.0-beta.3.tgz#cad099ebb40ff04b31ba2df13930517039e4fae3"
integrity sha512-Ak1ylgHbOUeaNsq3ItZGRenqqAwYKSTlB6T4sBn4PPNGaMmIMt6uIKKWrQqcNyc9WEy9LlFM6kSqQXBQdaVatw==
dependencies:
nanoid "^3.3.3"

View File

@@ -1,6 +1,6 @@
{
"name": "react-native-update",
"version": "10.0.0-beta.2",
"version": "10.0.1",
"description": "react-native hot update",
"main": "src/index.ts",
"scripts": {

View File

@@ -31,6 +31,7 @@ export class Pushy {
server: defaultServer,
autoMarkSuccess: true,
useAlert: true,
strategy: 'both',
};
lastChecking: number;
@@ -261,6 +262,7 @@ export class Pushy {
data: { newVersion: hash },
});
}
log('downloaded hash:', hash);
setLocalHashInfo(hash, {
name,
description,

View File

@@ -12,6 +12,7 @@ export const defaultContext = {
markSuccess: noop,
dismissError: noop,
downloadUpdate: noop,
downloadAndInstallApk: noop,
currentHash: '',
packageVersion: '',
};
@@ -23,6 +24,7 @@ export const PushyContext = createContext<{
markSuccess: () => void;
dismissError: () => void;
downloadUpdate: () => void;
downloadAndInstallApk: (url: string) => void;
currentHash: string;
packageVersion: string;
client?: Pushy;

View File

@@ -14,7 +14,7 @@ import {
} from 'react-native';
import { Pushy } from './client';
import { currentVersion, isFirstTime, packageVersion } from './core';
import { CheckResult } from './type';
import { CheckResult, ProgressData } from './type';
import { PushyContext } from './context';
export const PushyProvider = ({
@@ -24,9 +24,10 @@ export const PushyProvider = ({
client: Pushy;
children: ReactNode;
}) => {
const { strategy, useAlert } = client.options;
const { options } = client;
const stateListener = useRef<NativeEventSubscription>();
const [updateInfo, setUpdateInfo] = useState<CheckResult>();
const [progress, setProgress] = useState<ProgressData>();
const [lastError, setLastError] = useState<Error>();
const dismissError = useCallback(() => {
@@ -37,11 +38,11 @@ export const PushyProvider = ({
const showAlert = useCallback(
(...args: Parameters<typeof Alert.alert>) => {
if (useAlert) {
if (options.useAlert) {
Alert.alert(...args);
}
},
[useAlert],
[options],
);
const switchVersion = useCallback(() => {
@@ -61,7 +62,7 @@ export const PushyProvider = ({
return;
}
try {
const hash = await client.downloadUpdate(updateInfo);
const hash = await client.downloadUpdate(updateInfo, setProgress);
if (!hash) {
return;
}
@@ -88,6 +89,15 @@ export const PushyProvider = ({
}
}, [client, showAlert, updateInfo]);
const downloadAndInstallApk = useCallback(
(downloadUrl: string) => {
if (Platform.OS === 'android' && downloadUrl) {
client.downloadAndInstallApk(downloadUrl, setProgress);
}
},
[client],
);
const checkUpdate = useCallback(async () => {
let info: CheckResult;
try {
@@ -106,7 +116,7 @@ export const PushyProvider = ({
onPress: () => {
if (downloadUrl) {
if (Platform.OS === 'android' && downloadUrl.endsWith('.apk')) {
client.downloadAndInstallApk(downloadUrl);
downloadAndInstallApk(downloadUrl);
} else {
Linking.openURL(downloadUrl);
}
@@ -130,12 +140,13 @@ export const PushyProvider = ({
],
);
}
}, [client, downloadUpdate, showAlert]);
}, [client, downloadAndInstallApk, downloadUpdate, showAlert]);
const markSuccess = client.markSuccess;
useEffect(() => {
if (isFirstTime) {
const { strategy, dismissErrorAfter, autoMarkSuccess } = options;
if (isFirstTime && autoMarkSuccess) {
markSuccess();
}
if (strategy === 'both' || strategy === 'onAppResume') {
@@ -152,7 +163,6 @@ export const PushyProvider = ({
checkUpdate();
}
let dismissErrorTimer: ReturnType<typeof setTimeout>;
const { dismissErrorAfter } = client.options;
if (typeof dismissErrorAfter === 'number' && dismissErrorAfter > 0) {
dismissErrorTimer = setTimeout(() => {
dismissError();
@@ -162,7 +172,7 @@ export const PushyProvider = ({
stateListener.current && stateListener.current.remove();
clearTimeout(dismissErrorTimer);
};
}, [checkUpdate, client.options, dismissError, markSuccess, strategy]);
}, [checkUpdate, options, dismissError, markSuccess]);
return (
<PushyContext.Provider
@@ -178,6 +188,8 @@ export const PushyProvider = ({
downloadUpdate,
packageVersion,
currentHash: currentVersion,
progress,
downloadAndInstallApk,
}}
>
{children}