Skip to content

Commit

Permalink
Add ReactPackage.getModule method (facebook#39336)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#39336

We are introducing the new getModule method into the ReactPackage interface following the "Registration of Native Modules" design

This method defaults to true with the goal to avoid compatibility breakage

changelog: [Android][Changed] Introducing getModule method into ReactPackage interface, defaulting to null. This method will be used in the Stable API of React Native

Reviewed By: cortinico

Differential Revision: D48992720

fbshipit-source-id: 5a44b795b2e8032c8b865acc12325616ece060ee
  • Loading branch information
mdvacca committed Sep 13, 2023
1 parent 514243c commit 81b15be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewManager;
import java.util.List;
import javax.annotation.Nullable;

/**
* Main interface for providing additional capabilities to the catalyst framework by couple of
Expand Down Expand Up @@ -44,4 +45,16 @@ public interface ReactPackage {
/** @return a list of view managers that should be registered with {@link UIManagerModule} */
@NonNull
List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext);

/**
* Given a module name, it returns an instance of {@link NativeModule} for the name
*
* @param name name of the Native Module
* @param reactContext {@link ReactApplicationContext} context for this
*/
@Nullable
default NativeModule getModule(
@NonNull String name, @NonNull ReactApplicationContext reactContext) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.facebook.react;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ModuleHolder;
import com.facebook.react.bridge.ModuleSpec;
Expand Down Expand Up @@ -41,8 +42,9 @@ public List<NativeModule> createNativeModules(ReactApplicationContext reactConte
* @param name name of the Native Module
* @param reactContext {@link ReactApplicationContext} context for this
*/
@Override
public abstract @Nullable NativeModule getModule(
String name, final ReactApplicationContext reactContext);
@NonNull String name, @NonNull ReactApplicationContext reactContext);

/**
* This is a temporary method till we implement TurboModules. Once we implement TurboModules, we
Expand Down

0 comments on commit 81b15be

Please sign in to comment.