From e21f8ec34984551f87a306672160cc88e67e4793 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Mon, 29 Nov 2021 02:54:37 -0800 Subject: [PATCH] Fix crash on ReactEditText with AppCompat 1.4.0 Summary: This Diff fixes a crash happening as the user uses AppCompat 1.4.0 as a dependency in their App and uses a `TextInput` component. The crash happens as `mFabricViewStateManager` is accessed during the ctor of the superclass, and is not yet initialized. Fixes #31572 Changelog: [Android] [Fixed] - Fix crash on ReactEditText with AppCompat 1.4.0 Reviewed By: ShikaSD Differential Revision: D32674975 fbshipit-source-id: efa413f5e33527a29fbcfa729e8b006ecb235978 --- .../facebook/react/views/textinput/ReactEditText.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java index 84d5942d2cfc1a..c3fd32dd896038 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java @@ -114,7 +114,8 @@ public class ReactEditText extends AppCompatEditText private ReactViewBackgroundManager mReactBackgroundManager; - private final FabricViewStateManager mFabricViewStateManager = new FabricViewStateManager(); + private final @Nullable FabricViewStateManager mFabricViewStateManager = + new FabricViewStateManager(); protected boolean mDisableTextDiffing = false; protected boolean mIsSettingTextFromState = false; @@ -746,7 +747,9 @@ private void setIntrinsicContentSize() { // view, we don't need to construct one or apply it at all - it provides no use in Fabric. ReactContext reactContext = getReactContext(this); - if (!mFabricViewStateManager.hasStateWrapper() && !reactContext.isBridgeless()) { + if (mFabricViewStateManager != null + && !mFabricViewStateManager.hasStateWrapper() + && !reactContext.isBridgeless()) { final ReactTextInputLocalData localData = new ReactTextInputLocalData(this); UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class); if (uiManager != null) { @@ -978,7 +981,7 @@ public FabricViewStateManager getFabricViewStateManager() { */ private void updateCachedSpannable(boolean resetStyles) { // Noops in non-Fabric - if (!mFabricViewStateManager.hasStateWrapper()) { + if (mFabricViewStateManager != null && !mFabricViewStateManager.hasStateWrapper()) { return; } // If this view doesn't have an ID yet, we don't have a cache key, so bail here