Correctly implement measure callback with measure modes

Reviewed By: astreet

Differential Revision: D3330139

fbshipit-source-id: 2ea6e4b463817e9ccc5f2d9395736f68f8d972e4
This commit is contained in:
Emil Sjolander 2016-05-23 10:15:57 -07:00 committed by Facebook Github Bot 9
parent f7c4ed8926
commit 1767a0a828
1 changed files with 13 additions and 2 deletions

View File

@ -13,6 +13,7 @@ import javax.annotation.Nullable;
import android.text.Spannable;
import android.util.TypedValue;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
import android.widget.EditText;
@ -75,7 +76,6 @@ public class ReactTextInputShadowNode extends ReactTextShadowNode implements
// measure() should never be called before setThemedContext()
EditText editText = Assertions.assertNotNull(mEditText);
measureOutput.width = widthMode == CSSMeasureMode.UNDEFINED ? CSSConstants.UNDEFINED : width;
editText.setTextSize(
TypedValue.COMPLEX_UNIT_PX,
mFontSize == UNSET ?
@ -91,10 +91,21 @@ public class ReactTextInputShadowNode extends ReactTextShadowNode implements
editText.setLines(mNumberOfLines);
}
editText.measure(0 /* unspecified */, 0 /* unspecified */);
editText.measure(getMeasureSpec(width, widthMode), getMeasureSpec(height, heightMode));
measureOutput.width = editText.getMeasuredWidth();
measureOutput.height = editText.getMeasuredHeight();
}
private int getMeasureSpec(float size, CSSMeasureMode mode) {
if (mode == CSSMeasureMode.EXACTLY) {
return MeasureSpec.makeMeasureSpec((int) size, MeasureSpec.EXACTLY);
} else if (mode == CSSMeasureMode.AT_MOST) {
return MeasureSpec.makeMeasureSpec((int) size, MeasureSpec.AT_MOST);
} else {
return MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
}
}
@Override
public void onBeforeLayout() {
// We don't have to measure the text within the text input.