mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
RN Android: Support View Manager Commands that are strings
Summary:
Right now JS triggers a view manager command with the following code:
```
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(this),
UIManager.getViewManagerConfig('RCTView').Commands.hotspotUpdate,
[destX || 0, destY || 0],
);
```
As we want to get rid of calls to UIManager, we need to stop looking for the integer defined in native from JavaScript. We will be changing methods like this to be:
```
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(this),
'hotspotUpdate',
[destX || 0, destY || 0],
);
```
We need to support ints and Strings to be backwards compatible, but ints will be deprecated.
Reviewed By: shergin
Differential Revision: D15955444
fbshipit-source-id: d1c488975ae03404f8f851a7035b58a90ed34163
This commit is contained in:
committed by
Facebook Github Bot
parent
4b8d07ebf3
commit
3cae6fa950
@@ -22,6 +22,7 @@ import com.facebook.debug.holder.PrinterHolder;
|
||||
import com.facebook.debug.tags.ReactDebugOverlayTags;
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
import com.facebook.react.bridge.Dynamic;
|
||||
import com.facebook.react.bridge.GuardedRunnable;
|
||||
import com.facebook.react.bridge.LifecycleEventListener;
|
||||
import com.facebook.react.bridge.OnBatchCompleteListener;
|
||||
@@ -31,6 +32,7 @@ import com.facebook.react.bridge.ReactMarker;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.ReadableType;
|
||||
import com.facebook.react.bridge.UIManager;
|
||||
import com.facebook.react.bridge.UiThreadUtil;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
@@ -648,11 +650,19 @@ public class UIManagerModule extends ReactContextBaseJavaModule
|
||||
|
||||
@ReactMethod
|
||||
public void dispatchViewManagerCommand(
|
||||
int reactTag, int commandId, @Nullable ReadableArray commandArgs) {
|
||||
int reactTag, Dynamic commandId, @Nullable ReadableArray commandArgs) {
|
||||
// TODO: this is a temporary approach to support ViewManagerCommands in Fabric until
|
||||
// the dispatchViewManagerCommand() method is supported by Fabric JS API.
|
||||
UIManagerHelper.getUIManager(getReactApplicationContext(), ViewUtil.getUIManagerType(reactTag))
|
||||
.dispatchCommand(reactTag, commandId, commandArgs);
|
||||
if(commandId.getType() == ReadableType.Number) {
|
||||
final int commandIdNum = commandId.asInt();
|
||||
UIManagerHelper.getUIManager(getReactApplicationContext(), ViewUtil.getUIManagerType(reactTag))
|
||||
.dispatchCommand(reactTag, commandIdNum, commandArgs);
|
||||
} else if (commandId.getType() == ReadableType.String) {
|
||||
final String commandIdStr = commandId.asString();
|
||||
UIManagerHelper.getUIManager(getReactApplicationContext(), ViewUtil.getUIManagerType(reactTag))
|
||||
.dispatchCommand(reactTag, commandIdStr, commandArgs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -660,6 +670,11 @@ public class UIManagerModule extends ReactContextBaseJavaModule
|
||||
mUIImplementation.dispatchViewManagerCommand(reactTag, commandId, commandArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchCommand(int reactTag, String commandId, @Nullable ReadableArray commandArgs) {
|
||||
mUIImplementation.dispatchViewManagerCommand(reactTag, commandId, commandArgs);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void playTouchSound() {
|
||||
AudioManager audioManager =
|
||||
|
||||
Reference in New Issue
Block a user