private static int getMaxLines(TextView view) { int maxLines = -1; TransformationMethod method = view.getTransformationMethod(); if (method != null && method instanceof SingleLineTransformationMethod) { maxLines = 1; } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { maxLines = view.getMaxLines(); } return maxLines; }
// JELLY_BEAN is needed for TextView#getMaxLines(), which is OK, because in the actual code we // only use TextView#setMaxLines() which exists since API Level 1. @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Test public void testMaxLinesApplied() { UIManagerModule uiManager = getUIManagerModule(); ReactRootView rootView = createText( uiManager, JavaOnlyMap.of(ViewProps.NUMBER_OF_LINES, 2), JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text")); TextView textView = (TextView) rootView.getChildAt(0); assertThat(textView.getText().toString()).isEqualTo("test text"); assertThat(textView.getMaxLines()).isEqualTo(2); assertThat(textView.getEllipsize()).isEqualTo(TextUtils.TruncateAt.END); }