react-native-update 10.0.0-beta.2 → 10.0.0-beta.3

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.0.0-beta.2",
3
+ "version": "10.0.0-beta.3",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
package/src/client.tsx CHANGED
@@ -261,6 +261,7 @@ export class Pushy {
261
261
  data: { newVersion: hash },
262
262
  });
263
263
  }
264
+ log('downloaded hash:', hash);
264
265
  setLocalHashInfo(hash, {
265
266
  name,
266
267
  description,
package/src/context.ts CHANGED
@@ -12,6 +12,7 @@ export const defaultContext = {
12
12
  markSuccess: noop,
13
13
  dismissError: noop,
14
14
  downloadUpdate: noop,
15
+ downloadAndInstallApk: noop,
15
16
  currentHash: '',
16
17
  packageVersion: '',
17
18
  };
@@ -23,6 +24,7 @@ export const PushyContext = createContext<{
23
24
  markSuccess: () => void;
24
25
  dismissError: () => void;
25
26
  downloadUpdate: () => void;
27
+ downloadAndInstallApk: (url: string) => void;
26
28
  currentHash: string;
27
29
  packageVersion: string;
28
30
  client?: Pushy;
package/src/provider.tsx CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  } from 'react-native';
15
15
  import { Pushy } from './client';
16
16
  import { currentVersion, isFirstTime, packageVersion } from './core';
17
- import { CheckResult } from './type';
17
+ import { CheckResult, ProgressData } from './type';
18
18
  import { PushyContext } from './context';
19
19
 
20
20
  export const PushyProvider = ({
@@ -24,9 +24,10 @@ export const PushyProvider = ({
24
24
  client: Pushy;
25
25
  children: ReactNode;
26
26
  }) => {
27
- const { strategy, useAlert } = client.options;
27
+ const { options } = client;
28
28
  const stateListener = useRef<NativeEventSubscription>();
29
29
  const [updateInfo, setUpdateInfo] = useState<CheckResult>();
30
+ const [progress, setProgress] = useState<ProgressData>();
30
31
  const [lastError, setLastError] = useState<Error>();
31
32
 
32
33
  const dismissError = useCallback(() => {
@@ -37,11 +38,11 @@ export const PushyProvider = ({
37
38
 
38
39
  const showAlert = useCallback(
39
40
  (...args: Parameters<typeof Alert.alert>) => {
40
- if (useAlert) {
41
+ if (options.useAlert) {
41
42
  Alert.alert(...args);
42
43
  }
43
44
  },
44
- [useAlert],
45
+ [options],
45
46
  );
46
47
 
47
48
  const switchVersion = useCallback(() => {
@@ -61,7 +62,7 @@ export const PushyProvider = ({
61
62
  return;
62
63
  }
63
64
  try {
64
- const hash = await client.downloadUpdate(updateInfo);
65
+ const hash = await client.downloadUpdate(updateInfo, setProgress);
65
66
  if (!hash) {
66
67
  return;
67
68
  }
@@ -88,6 +89,15 @@ export const PushyProvider = ({
88
89
  }
89
90
  }, [client, showAlert, updateInfo]);
90
91
 
92
+ const downloadAndInstallApk = useCallback(
93
+ (downloadUrl: string) => {
94
+ if (Platform.OS === 'android' && downloadUrl) {
95
+ client.downloadAndInstallApk(downloadUrl, setProgress);
96
+ }
97
+ },
98
+ [client],
99
+ );
100
+
91
101
  const checkUpdate = useCallback(async () => {
92
102
  let info: CheckResult;
93
103
  try {
@@ -106,7 +116,7 @@ export const PushyProvider = ({
106
116
  onPress: () => {
107
117
  if (downloadUrl) {
108
118
  if (Platform.OS === 'android' && downloadUrl.endsWith('.apk')) {
109
- client.downloadAndInstallApk(downloadUrl);
119
+ downloadAndInstallApk(downloadUrl);
110
120
  } else {
111
121
  Linking.openURL(downloadUrl);
112
122
  }
@@ -130,12 +140,13 @@ export const PushyProvider = ({
130
140
  ],
131
141
  );
132
142
  }
133
- }, [client, downloadUpdate, showAlert]);
143
+ }, [client, downloadAndInstallApk, downloadUpdate, showAlert]);
134
144
 
135
145
  const markSuccess = client.markSuccess;
136
146
 
137
147
  useEffect(() => {
138
- if (isFirstTime) {
148
+ const { strategy, dismissErrorAfter, autoMarkSuccess } = options;
149
+ if (isFirstTime && autoMarkSuccess) {
139
150
  markSuccess();
140
151
  }
141
152
  if (strategy === 'both' || strategy === 'onAppResume') {
@@ -152,7 +163,6 @@ export const PushyProvider = ({
152
163
  checkUpdate();
153
164
  }
154
165
  let dismissErrorTimer: ReturnType<typeof setTimeout>;
155
- const { dismissErrorAfter } = client.options;
156
166
  if (typeof dismissErrorAfter === 'number' && dismissErrorAfter > 0) {
157
167
  dismissErrorTimer = setTimeout(() => {
158
168
  dismissError();
@@ -162,7 +172,7 @@ export const PushyProvider = ({
162
172
  stateListener.current && stateListener.current.remove();
163
173
  clearTimeout(dismissErrorTimer);
164
174
  };
165
- }, [checkUpdate, client.options, dismissError, markSuccess, strategy]);
175
+ }, [checkUpdate, options, dismissError, markSuccess]);
166
176
 
167
177
  return (
168
178
  <PushyContext.Provider
@@ -178,6 +188,8 @@ export const PushyProvider = ({
178
188
  downloadUpdate,
179
189
  packageVersion,
180
190
  currentHash: currentVersion,
191
+ progress,
192
+ downloadAndInstallApk,
181
193
  }}
182
194
  >
183
195
  {children}