From f1b5fe1d3ea49294d8c89accfa27d76a1a97ccea Mon Sep 17 00:00:00 2001 From: Lulu Wu Date: Sun, 17 Oct 2021 02:53:44 -0700 Subject: [PATCH] Prevent NPE on ThemedReactContext Summary: When pre-prerendering a surface without rendering it, "SurfaceMountingManager.getContext()" will return null since no ThemedReactContext is passed into it: https://www.internalfb.com/code/fbsource/[0f4812c8039d975b3651dfa756d60a882bf8e193]/xplat/js/react-native-github/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java?lines=298-317 Changelog: [Android][Fixed] - Prevent NPE on ThemedReactContext Reviewed By: ShikaSD Differential Revision: D31691022 fbshipit-source-id: 4cca6c4550a77075f8fd754dbf21fe5bf5da77e6 --- .../main/java/com/facebook/react/fabric/FabricUIManager.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index 270b9466b0d387..a161270395222b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -559,6 +559,11 @@ public boolean getThemeData(int surfaceId, float[] defaultTextInputPadding) { SurfaceMountingManager surfaceMountingManager = mMountingManager.getSurfaceManagerEnforced(surfaceId, "getThemeData"); ThemedReactContext themedReactContext = surfaceMountingManager.getContext(); + + if (themedReactContext == null) { + FLog.w(TAG, "\"themedReactContext\" is null when call \"getThemeData\""); + return false; + } float[] defaultTextInputPaddingForTheme = UIManagerHelper.getDefaultTextInputPadding(themedReactContext); defaultTextInputPadding[0] = defaultTextInputPaddingForTheme[PADDING_START_INDEX];