mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add example for dispatchViewManagerCommand on Fabric Interop (#36725)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36725 This diff adds an example of using `dispatchViewManagerCommand` for the Fabric Intreop on Android. Changelog: [Android] [Added] - Add example for dispatchViewManagerCommand on Fabric Interop Reviewed By: cipolleschi Differential Revision: D44540951 fbshipit-source-id: 85bc65ad0eb3a951fbb37d61ca26532ec3cc53b7
This commit is contained in:
committed by
Riccardo Cipolleschi
parent
5299c60bdc
commit
cb30323f04
+17
@@ -11,6 +11,7 @@ import android.graphics.Color;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
import com.facebook.react.uimanager.SimpleViewManager;
|
||||
@@ -26,6 +27,7 @@ import java.util.Map;
|
||||
public class MyLegacyViewManager extends SimpleViewManager<MyNativeView> {
|
||||
|
||||
public static final String REACT_CLASS = "RNTMyLegacyNativeView";
|
||||
private static final Integer COMMAND_CHANGE_BACKGROUND_COLOR = 42;
|
||||
private final ReactApplicationContext mCallerContext;
|
||||
|
||||
public MyLegacyViewManager(ReactApplicationContext reactContext) {
|
||||
@@ -76,4 +78,19 @@ public class MyLegacyViewManager extends SimpleViewManager<MyNativeView> {
|
||||
.build());
|
||||
return eventTypeConstants;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveCommand(
|
||||
@NonNull MyNativeView view, String commandId, @Nullable ReadableArray args) {
|
||||
if (commandId.contentEquals(COMMAND_CHANGE_BACKGROUND_COLOR.toString())) {
|
||||
int sentColor = Color.parseColor(args.getString(0));
|
||||
view.setBackgroundColor(sentColor);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Map<String, Integer> getCommandsMap() {
|
||||
return MapBuilder.of("changeBackgroundColor", COMMAND_CHANGE_BACKGROUND_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user