Skip to content

Commit

Permalink
Fix crash on ReactEditText with AppCompat 1.4.0
Browse files Browse the repository at this point in the history
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 facebook#31572

Changelog:
[Android] [Fixed] - Fix crash on ReactEditText with AppCompat 1.4.0

Reviewed By: ShikaSD

Differential Revision: D32674975

fbshipit-source-id: efa413f5e33527a29fbcfa729e8b006ecb235978
  • Loading branch information
cortinico authored and nawbc committed Dec 7, 2021
1 parent 4f9a5f2 commit e2812b3
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e2812b3

Please sign in to comment.