Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,28 @@ public void run() {
});
}

private Field findBundleLoaderField(Class<?> delegateClass) {
Class<?> currentClass = delegateClass;
while (currentClass != null) {
try {
return currentClass.getDeclaredField("jsBundleLoader");
} catch (NoSuchFieldException ignored) {
// Continue searching the class hierarchy and alternate field names.
}

try {
return currentClass.getDeclaredField("_jsBundleLoader");
} catch (NoSuchFieldException ignored) {
currentClass = currentClass.getSuperclass();
}
}

return null;
}

// Use reflection to find and set the appropriate fields on ReactHostDelegate. See #556 for a proposal for a less brittle way
// to approach this.
private void setJSBundle(ReactHostDelegate reactHostDelegate, String latestJSBundleFile) throws IllegalAccessException {

try {
JSBundleLoader latestJSBundleLoader;
if (latestJSBundleFile.toLowerCase().startsWith("assets://")) {
Expand All @@ -130,7 +148,10 @@ private void setJSBundle(ReactHostDelegate reactHostDelegate, String latestJSBun
latestJSBundleLoader = JSBundleLoader.createFileLoader(latestJSBundleFile);
}

Field bundleLoaderField = reactHostDelegate.getClass().getDeclaredField("jsBundleLoader");
Field bundleLoaderField = findBundleLoaderField(reactHostDelegate.getClass());
if (bundleLoaderField == null) {
throw new NoSuchFieldException("jsBundleLoader");
}
bundleLoaderField.setAccessible(true);
bundleLoaderField.set(reactHostDelegate, latestJSBundleLoader);

Expand Down
Loading