react-native-update 10.9.0 → 10.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.9.0",
3
+ "version": "10.10.1",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/context.ts CHANGED
@@ -14,6 +14,7 @@ export const defaultContext = {
14
14
  downloadUpdate: asyncNoop,
15
15
  downloadAndInstallApk: asyncNoop,
16
16
  getCurrentVersionInfo: () => Promise.resolve({}),
17
+ parseTestPayload: () => Promise.resolve(false),
17
18
  currentHash: '',
18
19
  packageVersion: '',
19
20
  };
@@ -31,6 +32,7 @@ export const PushyContext = createContext<{
31
32
  description?: string;
32
33
  metaInfo?: string;
33
34
  }>;
35
+ parseTestPayload: (code: string) => Promise<boolean>;
34
36
  currentHash: string;
35
37
  packageVersion: string;
36
38
  client?: Pushy;
package/src/provider.tsx CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  packageVersion,
20
20
  getCurrentVersionInfo,
21
21
  } from './core';
22
- import { CheckResult, ProgressData } from './type';
22
+ import { CheckResult, ProgressData, PushyTestPayload } from './type';
23
23
  import { PushyContext } from './context';
24
24
 
25
25
  export const PushyProvider = ({
@@ -262,6 +262,31 @@ export const PushyProvider = ({
262
262
  };
263
263
  }, [checkUpdate, options, dismissError, markSuccess]);
264
264
 
265
+ const parseTestPayload = useCallback(
266
+ async (code: string) => {
267
+ let payload: PushyTestPayload;
268
+ try {
269
+ payload = JSON.parse(code);
270
+ } catch {
271
+ return false;
272
+ }
273
+ if (payload && payload.type) {
274
+ if (payload.type === '__rnPushyVersionHash') {
275
+ await checkUpdate({ toHash: payload.data });
276
+ if (updateInfoRef.current && updateInfoRef.current.upToDate) {
277
+ Alert.alert(
278
+ '提示',
279
+ '当前尚未检测到更新版本,如果是首次扫码,请等待服务器端生成补丁包后再试(约10秒)',
280
+ );
281
+ }
282
+ return true;
283
+ }
284
+ }
285
+ return false;
286
+ },
287
+ [checkUpdate],
288
+ );
289
+
265
290
  return (
266
291
  <PushyContext.Provider
267
292
  value={{
@@ -279,6 +304,7 @@ export const PushyProvider = ({
279
304
  progress,
280
305
  downloadAndInstallApk,
281
306
  getCurrentVersionInfo,
307
+ parseTestPayload,
282
308
  }}>
283
309
  {children}
284
310
  </PushyContext.Provider>
package/src/type.ts CHANGED
@@ -81,3 +81,8 @@ export interface PushyOptions {
81
81
  debug?: boolean;
82
82
  throwError?: boolean;
83
83
  }
84
+
85
+ export interface PushyTestPayload {
86
+ type: '__rnPushyVersionHash';
87
+ data: any;
88
+ }