mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Refactor UIManagerHelper.getUIManager
Summary: This diff refactors the UIManagerHelper.getUIManager to allow the caller determine if it should return null when catalyst Istance is not active. This is necessary in order to keep backward compatibility for the getEventDispatcher method. changelog: [internal] Reviewed By: makovkastar Differential Revision: D19383063 fbshipit-source-id: 8a46b61d212480be91ea78929bbfa7248d5f3ad9
This commit is contained in:
committed by
Facebook Github Bot
parent
a69abb419a
commit
7fff4679d2
@@ -34,14 +34,34 @@ 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) {
|
||||
return getUIManager(context, uiManagerType, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static UIManager getUIManager(
|
||||
ReactContext context,
|
||||
@UIManagerType int uiManagerType,
|
||||
boolean returnNullIfCatalystIsInactive) {
|
||||
if (context.isBridgeless()) {
|
||||
return (UIManager) context.getJSIModule(JSIModuleType.UIManager);
|
||||
} else {
|
||||
if (!context.hasCatalystInstance()) {
|
||||
ReactSoftException.logSoftException(
|
||||
"UIManagerHelper",
|
||||
new IllegalStateException(
|
||||
"Cannot get UIManager because the context doesn't contain a CatalystInstance."));
|
||||
return null;
|
||||
}
|
||||
// TODO T60461551: add tests to verify emission of events when the ReactContext is being turn
|
||||
// down.
|
||||
if (!context.hasActiveCatalystInstance()) {
|
||||
ReactSoftException.logSoftException(
|
||||
"UIManagerHelper",
|
||||
new RuntimeException("Cannot get UIManager: no active Catalyst instance"));
|
||||
return null;
|
||||
new IllegalStateException(
|
||||
"Cannot get UIManager because the context doesn't contain an active CatalystInstance."));
|
||||
if (returnNullIfCatalystIsInactive) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
CatalystInstance catalystInstance = context.getCatalystInstance();
|
||||
return uiManagerType == FABRIC
|
||||
@@ -66,7 +86,7 @@ public class UIManagerHelper {
|
||||
@Nullable
|
||||
public static EventDispatcher getEventDispatcher(
|
||||
ReactContext context, @UIManagerType int uiManagerType) {
|
||||
UIManager uiManager = getUIManager(context, uiManagerType);
|
||||
UIManager uiManager = getUIManager(context, uiManagerType, false);
|
||||
return uiManager == null ? null : (EventDispatcher) uiManager.getEventDispatcher();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user