Skip to content

Commit 0815717

Browse files
EvanBacongabrieldonadel
authored andcommitted
[ReactAndroid] Support extending core modules
1 parent 8476920 commit 0815717

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/JavaModuleWrapper.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,20 @@ private void findMethods() {
7272
Class<? extends NativeModule> superClass =
7373
(Class<? extends NativeModule>) classForMethods.getSuperclass();
7474
if (TurboModule.class.isAssignableFrom(superClass)) {
75-
// For java module that is based on generated flow-type spec, inspect the
76-
// spec abstract class instead, which is the super class of the given java
77-
// module.
78-
classForMethods = superClass;
75+
// Check if the parent class also conforms to ReactModuleWithSpec
76+
// this accounts for cases when a module is extended i.e. Expo's sandbox AsyncStorage and Intent module.
77+
Class<? extends NativeModule> superSuperClass =
78+
(Class<? extends NativeModule>) superClass.getSuperclass();
79+
if (TurboModule.class.isAssignableFrom(superSuperClass)) {
80+
classForMethods = superSuperClass;
81+
} else {
82+
// For java module that is based on generated flow-type spec, inspect the
83+
// spec abstract class instead, which is the super class of the given java
84+
// module.
85+
classForMethods = superClass;
86+
}
7987
}
88+
8089
Method[] targetMethods = classForMethods.getDeclaredMethods();
8190

8291
for (Method targetMethod : targetMethods) {

0 commit comments

Comments
 (0)