Skip to content

Commit

Permalink
Fix TextInput's initial layout measurements
Browse files Browse the repository at this point in the history
Reviewed By: mdvacca

Differential Revision: D7732819

fbshipit-source-id: 0ca4e5643d2cfefe304d7f189474a671c4bcb31e
  • Loading branch information
ayc1 authored and facebook-github-bot committed May 30, 2018
1 parent 5fc42f3 commit c6b4f9f
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@

import android.os.Build;
import android.text.Layout;
import android.util.TypedValue;
import android.view.ViewGroup;
import android.widget.EditText;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.uimanager.LayoutShadowNode;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.ReactShadowNodeImpl;
import com.facebook.react.uimanager.Spacing;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIViewOperationQueue;
import com.facebook.react.uimanager.ViewDefaults;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.views.text.ReactBaseTextShadowNode;
import com.facebook.react.views.text.ReactTextUpdate;
Expand Down Expand Up @@ -127,12 +130,24 @@ public long measure(
// measure() should never be called before setThemedContext()
EditText editText = Assertions.assertNotNull(mDummyEditText);

if (mLocalData == null) {
// No local data, no intrinsic size.
return YogaMeasureOutput.make(0, 0);
if (mLocalData != null) {
mLocalData.apply(editText);
} else {
editText.setTextSize(
TypedValue.COMPLEX_UNIT_PX,
mFontSize == UNSET ?
(int) Math.ceil(PixelUtil.toPixelFromSP(ViewDefaults.FONT_SIZE_SP)) : mFontSize);

if (mNumberOfLines != UNSET) {
editText.setLines(mNumberOfLines);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
editText.getBreakStrategy() != mTextBreakStrategy) {
editText.setBreakStrategy(mTextBreakStrategy);
}
}

mLocalData.apply(editText);

editText.measure(
MeasureUtil.getMeasureSpec(width, widthMode),
Expand Down

0 comments on commit c6b4f9f

Please sign in to comment.