Skip to content

Commit

Permalink
Refactor UIManagerHelper.getUIManager
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mdvacca authored and facebook-github-bot committed Jan 23, 2020
1 parent a69abb4 commit 7fff467
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,35 @@ public static UIManager getUIManagerForReactTag(ReactContext context, int reactT
/** @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.hasActiveCatalystInstance()) {
if (!context.hasCatalystInstance()) {
ReactSoftException.logSoftException(
"UIManagerHelper",
new RuntimeException("Cannot get UIManager: no active Catalyst instance"));
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 IllegalStateException(
"Cannot get UIManager because the context doesn't contain an active CatalystInstance."));
if (returnNullIfCatalystIsInactive) {
return null;
}
}
CatalystInstance catalystInstance = context.getCatalystInstance();
return uiManagerType == FABRIC
? (UIManager) catalystInstance.getJSIModule(JSIModuleType.UIManager)
Expand All @@ -66,7 +86,7 @@ public static EventDispatcher getEventDispatcherForReactTag(ReactContext context
@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();
}

Expand Down

0 comments on commit 7fff467

Please sign in to comment.