react-native-ota-hot-update 1.0.0 → 1.0.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/README.md +7 -6
- package/package.json +1 -1
- package/src/Utils.ts +6 -1
- package/src/index.tsx +2 -1
package/README.md
CHANGED
|
@@ -88,12 +88,13 @@ The important thing: this library will control `version` by it self, need always
|
|
|
88
88
|
|
|
89
89
|
## UpdateOption
|
|
90
90
|
|
|
91
|
-
| Option | Required | Type | Description
|
|
92
|
-
|
|
93
|
-
| headers | No | Object | The header to down load your uri bundle file if need token/authentication...
|
|
94
|
-
| updateSuccess | No | Callback | Will trigger when install update success
|
|
95
|
-
| updateFail(message: string) | No | Callback
|
|
96
|
-
| restartAfterInstall | No | boolean
|
|
91
|
+
| Option | Required | Type | Description |
|
|
92
|
+
|-------------------------|----------|----------|--------------------------------------------------------------------------------------------------|
|
|
93
|
+
| headers | No | Object | The header to down load your uri bundle file if need token/authentication... |
|
|
94
|
+
| updateSuccess | No | Callback | Will trigger when install update success |
|
|
95
|
+
| updateFail(message: string) | No | Callback | Will trigger when install update failed |
|
|
96
|
+
| restartAfterInstall | No | boolean | default is `false`, if `true` will restart the app after install success to apply the new change |
|
|
97
|
+
| progress | No | void | A callback to show progress when downloading bundle |
|
|
97
98
|
|
|
98
99
|
|
|
99
100
|
|
package/package.json
CHANGED
package/src/Utils.ts
CHANGED
|
@@ -2,13 +2,18 @@ import {
|
|
|
2
2
|
Platform,
|
|
3
3
|
} from 'react-native';
|
|
4
4
|
import ReactNativeBlobUtil from 'react-native-blob-util';
|
|
5
|
-
export const downloadBundleFile = async (uri: string, headers?: object) => {
|
|
5
|
+
export const downloadBundleFile = async (uri: string, headers?: object, callback?: (received: string, total: string) => void) => {
|
|
6
6
|
const res = await ReactNativeBlobUtil
|
|
7
7
|
.config({
|
|
8
8
|
fileCache: Platform.OS === 'android',
|
|
9
9
|
})
|
|
10
10
|
.fetch('GET', uri, {
|
|
11
11
|
...headers,
|
|
12
|
+
})
|
|
13
|
+
.progress((received, total) => {
|
|
14
|
+
if (callback) {
|
|
15
|
+
callback(received, total)
|
|
16
|
+
}
|
|
12
17
|
});
|
|
13
18
|
return res.path();
|
|
14
19
|
};
|
package/src/index.tsx
CHANGED
|
@@ -8,6 +8,7 @@ const LINKING_ERROR =
|
|
|
8
8
|
|
|
9
9
|
export interface UpdateOption {
|
|
10
10
|
headers?: object
|
|
11
|
+
progress?(received: string, total: string): void
|
|
11
12
|
updateSuccess?(): void
|
|
12
13
|
updateFail?(message?: string): void
|
|
13
14
|
restartAfterInstall?: boolean
|
|
@@ -73,7 +74,7 @@ async function downloadBundleUri(uri: string, version: number, option?: UpdateOp
|
|
|
73
74
|
return;
|
|
74
75
|
}
|
|
75
76
|
try {
|
|
76
|
-
const path = await downloadBundleFile(uri, option?.headers);
|
|
77
|
+
const path = await downloadBundleFile(uri, option?.headers, option?.progress);
|
|
77
78
|
if (path) {
|
|
78
79
|
setupBundlePath(path).then(success => {
|
|
79
80
|
if (success) {
|