mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix NullPointerException occurring when using Placeholder in TextInput
Summary: This diff is fixing a NullPointerException occuring when using Placeholder in TextInput. In some particular scenarios Placeholder is being updated before the TextInput is even layed out. In this diff I'm setting a defult LayoutParams to avoid NullPointerException to be thrown by android EditTextView. This change should not affect layout for TextInput components because layout will be overriden on the next Fabric commit. changelog: [internal] internal Reviewed By: fkgozali Differential Revision: D42078080 fbshipit-source-id: 294376e7f78d6ed58fc9f893553356553accba6c
This commit is contained in:
1 parent
1b7127bb05
commit
88da8d99ed
1 file changed
+8
+8
@@ -26,6 +26,7 @@ import android.text.TextWatcher;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -189,6 +190,13 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
||||
int inputType = editText.getInputType();
|
||||
editText.setInputType(inputType & (~InputType.TYPE_TEXT_FLAG_MULTI_LINE));
|
||||
editText.setReturnKeyType("done");
|
||||
// Set defult layoutParams to avoid NullPointerException to be thrown by Android EditTextView
|
||||
// when update props (PlaceHolder) is executed before the view is layout.
|
||||
// This change should not affect layout for TextInput components because layout will be
|
||||
// overriden on the first RN commit.
|
||||
editText.setLayoutParams(
|
||||
new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
return editText;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user