@turbopush/react-native-code-push 10.2.6 → 10.3.0
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.
|
@@ -150,12 +150,20 @@ public class CodePushNativeModule extends BaseJavaModule {
|
|
|
150
150
|
latestJSBundleLoader = JSBundleLoader.createFileLoader(latestJSBundleFile);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
// ExpoReactHostDelegate (Kotlin) exposes jsBundleLoader as a computed property whose
|
|
154
|
+
// backing field is named "_jsBundleLoader". Setting it makes the getter return the new
|
|
155
|
+
// loader on the next reload. Fall back to the non-prefixed name for other delegates.
|
|
156
|
+
Field bundleLoaderField;
|
|
157
|
+
try {
|
|
158
|
+
bundleLoaderField = reactHostDelegate.getClass().getDeclaredField("_jsBundleLoader");
|
|
159
|
+
} catch (NoSuchFieldException ignored) {
|
|
160
|
+
bundleLoaderField = reactHostDelegate.getClass().getDeclaredField("jsBundleLoader");
|
|
161
|
+
}
|
|
154
162
|
bundleLoaderField.setAccessible(true);
|
|
155
163
|
bundleLoaderField.set(reactHostDelegate, latestJSBundleLoader);
|
|
156
164
|
|
|
157
165
|
} catch (NoSuchFieldException nsfe) {
|
|
158
|
-
CodePushUtils.log("
|
|
166
|
+
CodePushUtils.log("Neither '_jsBundleLoader' nor 'jsBundleLoader' field found on " + (reactHostDelegate != null ? reactHostDelegate.getClass().getName() : "null") + ". Unable to update JS bundle for reload.");
|
|
159
167
|
// DO NOT THROW for NoSuchFieldException.
|
|
160
168
|
}catch (Exception e) {
|
|
161
169
|
CodePushUtils.log("Unable to set JSBundle of ReactHostDelegate - CodePush may not support this version of React Native");
|
|
@@ -197,31 +205,26 @@ public class CodePushNativeModule extends BaseJavaModule {
|
|
|
197
205
|
|
|
198
206
|
|
|
199
207
|
try {
|
|
200
|
-
if (reactHost instanceof ReactHostImpl) {
|
|
201
|
-
ReactHostDelegate delegate = getReactHostDelegate((ReactHostImpl) reactHost);
|
|
208
|
+
if (reactHost instanceof ReactHostImpl) {
|
|
209
|
+
ReactHostDelegate delegate = getReactHostDelegate((ReactHostImpl) reactHost);
|
|
202
210
|
if (delegate != null) {
|
|
203
|
-
// #2) Update the
|
|
204
|
-
setJSBundle(delegate, latestJSBundleFile);
|
|
211
|
+
// #2) Update the bundle loader on the delegate so the next reload uses it
|
|
212
|
+
setJSBundle(delegate, latestJSBundleFile);
|
|
205
213
|
} else {
|
|
206
214
|
CodePushUtils.log("Could not get ReactHostDelegate from ReactHostImpl.");
|
|
207
215
|
}
|
|
208
216
|
} else {
|
|
209
|
-
CodePushUtils.log("ReactHost is not
|
|
217
|
+
CodePushUtils.log("ReactHost is not ReactHostImpl (" + reactHost.getClass().getName() + ")");
|
|
210
218
|
}
|
|
211
|
-
} catch (
|
|
212
|
-
CodePushUtils.log(
|
|
213
|
-
}catch (Exception e) {
|
|
214
|
-
// Catch any unexpected errors from the attempt to call setJSBundle, e.g., if getReactHostDelegate itself fails
|
|
215
|
-
CodePushUtils.log("Exception during the reflective setJSBundle block: " + e.getMessage());
|
|
219
|
+
} catch (Exception e) {
|
|
220
|
+
CodePushUtils.log("Exception during setJSBundle: " + e.getMessage());
|
|
216
221
|
}
|
|
217
222
|
|
|
218
|
-
// #3)
|
|
223
|
+
// #3) Trigger reload and initialize update state
|
|
219
224
|
try {
|
|
220
225
|
reactHost.reload("CodePush triggers reload");
|
|
221
226
|
mCodePush.initializeUpdateAfterRestart();
|
|
222
227
|
} catch (Exception e) {
|
|
223
|
-
// The recreation method threw an unknown exception
|
|
224
|
-
// so just simply fallback to restarting the Activity (if it exists)
|
|
225
228
|
loadBundleLegacy();
|
|
226
229
|
}
|
|
227
230
|
|
|
@@ -856,14 +859,23 @@ public class CodePushNativeModule extends BaseJavaModule {
|
|
|
856
859
|
}
|
|
857
860
|
|
|
858
861
|
public ReactHostDelegate getReactHostDelegate(ReactHostImpl reactHostImpl) {
|
|
862
|
+
// RN 0.76+ (used in Expo SDK 55+) names the field "reactHostDelegate" (Kotlin constructor
|
|
863
|
+
// property, no "m" prefix). Older versions used "mReactHostDelegate".
|
|
864
|
+
String[] candidateFields = {"reactHostDelegate", "mReactHostDelegate"};
|
|
859
865
|
try {
|
|
860
866
|
Class<?> clazz = reactHostImpl.getClass();
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
+
for (String fieldName : candidateFields) {
|
|
868
|
+
try {
|
|
869
|
+
Field field = clazz.getDeclaredField(fieldName);
|
|
870
|
+
field.setAccessible(true);
|
|
871
|
+
return (ReactHostDelegate) field.get(reactHostImpl);
|
|
872
|
+
} catch (NoSuchFieldException ignored) {
|
|
873
|
+
// try next candidate
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
CodePushUtils.log("Could not find reactHostDelegate field on " + clazz.getName());
|
|
877
|
+
return null;
|
|
878
|
+
} catch (IllegalAccessException e) {
|
|
867
879
|
e.printStackTrace();
|
|
868
880
|
return null;
|
|
869
881
|
}
|
package/package.json
CHANGED
package/request-fetch-adapter.js
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
const packageJson = require("./package.json");
|
|
2
|
+
const { Platform } = require("react-native");
|
|
3
|
+
|
|
4
|
+
const { major, minor, patch } = Platform.constants.reactNativeVersion;
|
|
5
|
+
const rnVersion = `${major}.${minor}.${patch}`;
|
|
6
|
+
|
|
7
|
+
let expoVersion;
|
|
8
|
+
try {
|
|
9
|
+
expoVersion = require("expo/package.json").version;
|
|
10
|
+
} catch (_) { }
|
|
11
|
+
|
|
12
|
+
let turbopushExpoPluginVersion;
|
|
13
|
+
try {
|
|
14
|
+
turbopushExpoPluginVersion = require("@turbopush/turbopush-expo-plugin/package.json").version;
|
|
15
|
+
} catch (_) { }
|
|
2
16
|
|
|
3
17
|
module.exports = {
|
|
4
|
-
|
|
18
|
+
request(verb, url, requestBody, callback) {
|
|
5
19
|
if (typeof requestBody === "function") {
|
|
6
20
|
callback = requestBody;
|
|
7
21
|
requestBody = null;
|
|
@@ -12,26 +26,32 @@ module.exports = {
|
|
|
12
26
|
"Content-Type": "application/json",
|
|
13
27
|
"X-CodePush-Plugin-Name": packageJson.name,
|
|
14
28
|
"X-CodePush-Plugin-Version": packageJson.version,
|
|
15
|
-
"X-CodePush-SDK-Version": packageJson.dependencies["code-push"]
|
|
29
|
+
"X-CodePush-SDK-Version": packageJson.dependencies["code-push"],
|
|
30
|
+
"X-React-Native-Version": rnVersion,
|
|
31
|
+
...(expoVersion && { "X-Expo-Version": expoVersion }),
|
|
32
|
+
...(turbopushExpoPluginVersion && { "X-Turbopush-Expo-Plugin-Version": turbopushExpoPluginVersion }),
|
|
16
33
|
};
|
|
17
34
|
|
|
18
35
|
if (requestBody && typeof requestBody === "object") {
|
|
19
36
|
requestBody = JSON.stringify(requestBody);
|
|
20
37
|
}
|
|
21
38
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
const xhr = new XMLHttpRequest();
|
|
40
|
+
xhr.open(getHttpMethodName(verb), url, true);
|
|
41
|
+
|
|
42
|
+
Object.entries(headers).forEach(([key, value]) => {
|
|
43
|
+
xhr.setRequestHeader(key, value);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
xhr.onload = () => {
|
|
47
|
+
callback(null, { statusCode: xhr.status, body: xhr.responseText });
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
xhr.onerror = () => {
|
|
51
|
+
callback(new Error(`Network request failed for url ${url}`));
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
xhr.send(requestBody || null);
|
|
35
55
|
}
|
|
36
56
|
};
|
|
37
57
|
|