diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java index eeda18dedf5cba..f722bf6a163ad9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java @@ -37,7 +37,7 @@ public class ReactTextInputShadowNode extends ReactBaseTextShadowNode implements YogaMeasureFunction { private int mMostRecentEventCount = UNSET; - private @Nullable EditText mDummyEditText; + private @Nullable EditText mInternalEditText; private @Nullable ReactTextInputLocalData mLocalData; @VisibleForTesting public static final String PROP_TEXT = "text"; @@ -75,20 +75,20 @@ public void setThemedContext(ThemedReactContext themedContext) { // of Android), and it cannot be changed. // So, we have to enforce it as a default padding. // TODO #7120264: Cache this stuff better. - EditText editText = new EditText(getThemedContext()); + EditText editText = createInternalEditText(); setDefaultPadding(Spacing.START, ViewCompat.getPaddingStart(editText)); setDefaultPadding(Spacing.TOP, editText.getPaddingTop()); setDefaultPadding(Spacing.END, ViewCompat.getPaddingEnd(editText)); setDefaultPadding(Spacing.BOTTOM, editText.getPaddingBottom()); - mDummyEditText = editText; + mInternalEditText = editText; // We must measure the EditText without paddings, so we have to reset them. - mDummyEditText.setPadding(0, 0, 0, 0); + mInternalEditText.setPadding(0, 0, 0, 0); // This is needed to fix an android bug since 4.4.3 which will throw an NPE in measure, // setting the layoutParams fixes it: https://code.google.com/p/android/issues/detail?id=75877 - mDummyEditText.setLayoutParams( + mInternalEditText.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } @@ -101,7 +101,7 @@ public long measure( float height, YogaMeasureMode heightMode) { // measure() should never be called before setThemedContext() - EditText editText = Assertions.assertNotNull(mDummyEditText); + EditText editText = Assertions.assertNotNull(mInternalEditText); if (mLocalData != null) { mLocalData.apply(editText); @@ -249,4 +249,12 @@ public void setPadding(int spacingType, float padding) { super.setPadding(spacingType, padding); markUpdated(); } + + /** + * May be overriden by subclasses that would like to provide their own instance of the internal + * {@code EditText} this class uses to determine the expected size of the view. + */ + protected EditText createInternalEditText() { + return new EditText(getThemedContext()); + } }