Skip to content

Commit

Permalink
trigger codegenned reflection if module is a turbomodule (facebook#36672
Browse files Browse the repository at this point in the history
)

Summary:
Pull Request resolved: facebook#36672

Changelog: [Internal]

if we look at usages of ReactModuleWithSpec, we see that it's existence was to simply identify generated native modules since the inheritance graph of native modules was different if they were generated.

this was introduced before we created the TurboModule interface, which all codegenned native modules also conform to. since that exists now, there's no need for both of these. this is the only callsite in our code where ReactModuleWithSpec triggers any logic, so i'm updating it.

bypass-github-export-checks

Reviewed By: javache

Differential Revision: D44450687

fbshipit-source-id: f9c26fce8e360b6e319153aad83fc788079bac91
  • Loading branch information
philIip authored and jeongshin committed May 7, 2023
1 parent 85a1da0 commit 71a4a95
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import androidx.annotation.Nullable;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
import com.facebook.systrace.Systrace;
import com.facebook.systrace.SystraceMessage;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -71,7 +72,7 @@ private void findMethods() {
Class<? extends NativeModule> classForMethods = mModuleHolder.getModule().getClass();
Class<? extends NativeModule> superClass =
(Class<? extends NativeModule>) classForMethods.getSuperclass();
if (ReactModuleWithSpec.class.isAssignableFrom(superClass)) {
if (TurboModule.class.isAssignableFrom(superClass)) {
// For java module that is based on generated flow-type spec, inspect the
// spec abstract class instead, which is the super class of the given java
// module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReactModuleWithSpec;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -112,7 +112,7 @@ private static Method[] getMethodsFromModule(NativeModule module) {
Class<? extends NativeModule> classForMethods = module.getClass();
Class<? extends NativeModule> superClass =
(Class<? extends NativeModule>) classForMethods.getSuperclass();
if (ReactModuleWithSpec.class.isAssignableFrom(superClass)) {
if (TurboModule.class.isAssignableFrom(superClass)) {
// For java module that is based on generated flow-type spec, inspect the
// spec abstract class instead, which is the super class of the given java
// module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ rn_robolectric_test(
react_native_dep("third-party/java/junit:junit"),
react_native_target("java/com/facebook/react/bridge:bridge"),
react_native_target("java/com/facebook/react/common:common"),
react_native_target("java/com/facebook/react/turbomodule/core/interfaces:interfaces"),
react_native_target("java/com/facebook/react/uimanager:uimanager"),
react_native_tests_target("java/com/facebook/common/logging:logging"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.mockito.Mockito.when;

import android.content.Context;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
import com.facebook.soloader.SoLoader;
import java.util.List;
import org.junit.Before;
Expand Down Expand Up @@ -127,7 +128,7 @@ public int syncMethod(int a, int b) {
}

private abstract class NativeTestGeneratedModuleSpec extends BaseJavaModule
implements ReactModuleWithSpec {
implements TurboModule {
@ReactMethod
public abstract void generatedMethod(String a, int b);
}
Expand Down

0 comments on commit 71a4a95

Please sign in to comment.