From c317f558f7e5549dffeda1950613ff9844f409e9 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Thu, 6 May 2021 12:12:10 -0700 Subject: [PATCH] Refactor UIManagerHelper.getUIManager to return null when there's no UIManager registered Summary: This diff refactors the UIManagerHelper.getUIManager method to return null when there's no UIManager registered for the uiManagerType received as a parameter. This is necessary to workaround: https://github.com/facebook/react-native/issues/31245 changelog: [changed] UIManagerHelper.getUIManager now returns null when there's no UIManager registered for the uiManagerType received as a parameter Reviewed By: fkgozali Differential Revision: D28242592 fbshipit-source-id: c3a4979bcf6e547d0f0060737e41bbf19860a984 --- .../facebook/react/uimanager/UIManagerHelper.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.java index b2b82aca343f29..d18ecb416627c7 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.java @@ -82,9 +82,18 @@ private static UIManager getUIManager( } } CatalystInstance catalystInstance = context.getCatalystInstance(); - return uiManagerType == FABRIC - ? (UIManager) catalystInstance.getJSIModule(JSIModuleType.UIManager) - : catalystInstance.getNativeModule(UIManagerModule.class); + try { + return uiManagerType == FABRIC + ? (UIManager) catalystInstance.getJSIModule(JSIModuleType.UIManager) + : catalystInstance.getNativeModule(UIManagerModule.class); + } catch (IllegalArgumentException ex) { + // TODO T67518514 Clean this up once we migrate everything over to bridgeless mode + ReactSoftException.logSoftException( + "UIManagerHelper", + new ReactNoCrashSoftException( + "Cannot get UIManager for UIManagerType: " + uiManagerType)); + return catalystInstance.getNativeModule(UIManagerModule.class); + } } /**