Skip to content

Commit cb30323

Browse files
cortinicoRiccardo Cipolleschi
authored andcommitted
Add example for dispatchViewManagerCommand on Fabric Interop (facebook#36725)
Summary: Pull Request resolved: facebook#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
1 parent 5299c60 commit cb30323

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/component/MyLegacyViewManager.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import androidx.annotation.NonNull;
1212
import androidx.annotation.Nullable;
1313
import com.facebook.react.bridge.ReactApplicationContext;
14+
import com.facebook.react.bridge.ReadableArray;
1415
import com.facebook.react.common.MapBuilder;
1516
import com.facebook.react.module.annotations.ReactModule;
1617
import com.facebook.react.uimanager.SimpleViewManager;
@@ -26,6 +27,7 @@
2627
public class MyLegacyViewManager extends SimpleViewManager<MyNativeView> {
2728

2829
public static final String REACT_CLASS = "RNTMyLegacyNativeView";
30+
private static final Integer COMMAND_CHANGE_BACKGROUND_COLOR = 42;
2931
private final ReactApplicationContext mCallerContext;
3032

3133
public MyLegacyViewManager(ReactApplicationContext reactContext) {
@@ -76,4 +78,19 @@ public final Map<String, Object> getExportedCustomBubblingEventTypeConstants() {
7678
.build());
7779
return eventTypeConstants;
7880
}
81+
82+
@Override
83+
public void receiveCommand(
84+
@NonNull MyNativeView view, String commandId, @Nullable ReadableArray args) {
85+
if (commandId.contentEquals(COMMAND_CHANGE_BACKGROUND_COLOR.toString())) {
86+
int sentColor = Color.parseColor(args.getString(0));
87+
view.setBackgroundColor(sentColor);
88+
}
89+
}
90+
91+
@Nullable
92+
@Override
93+
public Map<String, Integer> getCommandsMap() {
94+
return MapBuilder.of("changeBackgroundColor", COMMAND_CHANGE_BACKGROUND_COLOR);
95+
}
7996
}

0 commit comments

Comments
 (0)