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 #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 facebook-github-bot committed Nov 29, 2021
1 parent e89d494 commit e21f8ec
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

6 comments on commit e21f8ec

@aretesoftware
Copy link

@aretesoftware aretesoftware commented on e21f8ec Feb 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cortinico

This seems to fix the following error:

Attempt to invoke virtual method'boolean com.facebook.react.uimanager.FabricViewStateManager.hasStateWrappper()' on a null object reference

However, TextInput may need some further work to support appcompat >= 1.4.0. This issue continues to occur:

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.facebook.react.views.textinput.ReactEditText$InternalKeyListener.setInputType(int)' on a null object reference
at com.facebook.react.views.textinput.ReactEditText.setInputType(ReactEditText.java:454)
at androidx.appcompat.widget.AppCompatEmojiEditTextHelper.initKeyListener(AppCompatEmojiEditTextHelper.java:92)

#31572

@cortinico
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aretesoftware Have you tried the 0.68 RC? Or how can I reproduce this?

@RaghavRhythm
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I make the above changes to my current project.
My current React Native Project version is 0.67.2 (react-native@0.67.2)

@cortinico
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can try React Native 0.68.0-rc1 or wait for the stable release which will be out in some weeks

@RaghavRhythm
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Worked !..Thank U..

@tamdvyounetgroup
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to edit and rebuild file .jar lib react native ?. help me

Please sign in to comment.