react-native-update 10.40.0 → 10.40.2

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.
@@ -31,7 +31,8 @@ final class ReactReloadManager {
31
31
  Activity currentActivity = reactContext.getCurrentActivity();
32
32
  String updateBundlePath = updateContext.getBundleUrl();
33
33
 
34
- Object reactHost = getReactHost(currentActivity, application);
34
+ boolean newArchitectureEnabled = isNewArchitectureEnabled(application);
35
+ Object reactHost = newArchitectureEnabled ? getReactHost(currentActivity, application) : null;
35
36
  if (reactHost != null) {
36
37
  try {
37
38
  reloadReactHost(reactHost, createBundleLoader(application, updateBundlePath, true));
@@ -63,6 +64,9 @@ final class ReactReloadManager {
63
64
  }
64
65
 
65
66
  try {
67
+ if (!newArchitectureEnabled) {
68
+ throw err;
69
+ }
66
70
  Object currentReactHost = getReactHost(currentActivity, application);
67
71
  if (currentReactHost == null) {
68
72
  throw err;
@@ -180,6 +184,51 @@ final class ReactReloadManager {
180
184
  return null;
181
185
  }
182
186
 
187
+ private static boolean isNewArchitectureEnabled(Context application) {
188
+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
189
+ return true;
190
+ }
191
+
192
+ try {
193
+ Class<?> buildConfigClass = Class.forName(application.getPackageName() + ".BuildConfig");
194
+ Field newArchitectureField = buildConfigClass.getField("IS_NEW_ARCHITECTURE_ENABLED");
195
+ if (newArchitectureField.getBoolean(null)) {
196
+ return true;
197
+ }
198
+ } catch (Throwable ignored) {
199
+ }
200
+
201
+ if (application instanceof ReactApplication) {
202
+ try {
203
+ ReactNativeHost reactNativeHost = ((ReactApplication) application).getReactNativeHost();
204
+ Method isNewArchEnabledMethod = getDeclaredMethodInHierarchy(
205
+ reactNativeHost.getClass(),
206
+ "isNewArchEnabled"
207
+ );
208
+ isNewArchEnabledMethod.setAccessible(true);
209
+ Object result = isNewArchEnabledMethod.invoke(reactNativeHost);
210
+ return result instanceof Boolean && (Boolean) result;
211
+ } catch (Throwable ignored) {
212
+ }
213
+ }
214
+
215
+ return false;
216
+ }
217
+
218
+ private static Method getDeclaredMethodInHierarchy(Class<?> clazz, String methodName)
219
+ throws NoSuchMethodException {
220
+ Class<?> current = clazz;
221
+ while (current != null) {
222
+ try {
223
+ return current.getDeclaredMethod(methodName);
224
+ } catch (NoSuchMethodException ignored) {
225
+ current = current.getSuperclass();
226
+ }
227
+ }
228
+
229
+ throw new NoSuchMethodException(methodName);
230
+ }
231
+
183
232
  private static void reloadReactHost(Object reactHost, JSBundleLoader loader) throws Throwable {
184
233
  try {
185
234
  Field devSupportField = getCompatibleField(reactHost.getClass(), "useDevSupport");
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.40.0",
3
+ "version": "10.40.2",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
Binary file