Extend UIManagerHelper class to retrieve EventDispatcher associated with a ReactContext
Summary: This diff extends the UIManagerHelper class to expose the EventDispatcher associated to a tag / UImanagerType Changelog: [internal] Reviewed By: JoshuaGross Differential Revision: D18862863 fbshipit-source-id: 14ce7a6a33f20a94a6296320924dbe3544eadd85
This commit is contained in:
Родитель
c5efc63663
Коммит
4ef3fafa7c
|
@ -9,14 +9,14 @@ package com.facebook.react.uimanager;
|
|||
|
||||
import static com.facebook.react.uimanager.common.UIManagerType.FABRIC;
|
||||
import static com.facebook.react.uimanager.common.ViewUtil.getUIManagerType;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.CatalystInstance;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.JSIModuleType;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.ReactSoftException;
|
||||
import com.facebook.react.bridge.UIManager;
|
||||
import com.facebook.react.uimanager.common.UIManagerType;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
|
||||
/** Helper class for {@link UIManager}. */
|
||||
public class UIManagerHelper {
|
||||
|
@ -30,15 +30,39 @@ public class UIManagerHelper {
|
|||
/** @return a {@link UIManager} that can handle the react tag received by parameter. */
|
||||
@Nullable
|
||||
public static UIManager getUIManager(ReactContext context, @UIManagerType int uiManagerType) {
|
||||
if (!context.hasActiveCatalystInstance()) {
|
||||
ReactSoftException.logSoftException(
|
||||
"UIManagerHelper",
|
||||
new RuntimeException("Cannot get UIManager: no active Catalyst instance"));
|
||||
return null;
|
||||
if (context.isBridgeless()) {
|
||||
return (UIManager) context.getJSIModule(JSIModuleType.UIManager);
|
||||
} else {
|
||||
if (!context.hasActiveCatalystInstance()) {
|
||||
ReactSoftException.logSoftException(
|
||||
"UIManagerHelper",
|
||||
new RuntimeException("Cannot get UIManager: no active Catalyst instance"));
|
||||
return null;
|
||||
}
|
||||
CatalystInstance catalystInstance = context.getCatalystInstance();
|
||||
return uiManagerType == FABRIC
|
||||
? (UIManager) catalystInstance.getJSIModule(JSIModuleType.UIManager)
|
||||
: catalystInstance.getNativeModule(UIManagerModule.class);
|
||||
}
|
||||
CatalystInstance catalystInstance = context.getCatalystInstance();
|
||||
return uiManagerType == FABRIC
|
||||
? (UIManager) catalystInstance.getJSIModule(JSIModuleType.UIManager)
|
||||
: catalystInstance.getNativeModule(UIManagerModule.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link EventDispatcher} that handles events for the reactTag received as a
|
||||
* parameter.
|
||||
*/
|
||||
@Nullable
|
||||
public static EventDispatcher getEventDispatcherForReactTag(ReactContext context, int reactTag) {
|
||||
return getEventDispatcher(context, getUIManagerType(reactTag));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link EventDispatcher} that handles events for the {@link UIManagerType} received
|
||||
* as a parameter.
|
||||
*/
|
||||
@Nullable
|
||||
public static EventDispatcher getEventDispatcher(
|
||||
ReactContext context, @UIManagerType int uiManagerType) {
|
||||
UIManager uiManager = getUIManager(context, uiManagerType);
|
||||
return uiManager == null ? null : (EventDispatcher) uiManager.getEventDispatcher();
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче