|
36 | 36 | import com.facebook.react.uimanager.ViewProps;
|
37 | 37 | import com.facebook.react.views.text.ReactRawTextShadowNode;
|
38 | 38 | import com.facebook.react.views.view.ReactViewBackgroundDrawable;
|
| 39 | +import com.facebook.react.views.text.CustomTextTransformSpan; |
39 | 40 | import java.util.ArrayList;
|
40 | 41 | import java.util.Arrays;
|
41 | 42 | import java.util.List;
|
@@ -341,6 +342,70 @@ public void testBackgroundColorStyleApplied() {
|
341 | 342 | assertThat(((ReactViewBackgroundDrawable) backgroundDrawable).getColor()).isEqualTo(Color.BLUE);
|
342 | 343 | }
|
343 | 344 |
|
| 345 | + @Test |
| 346 | + public void testTextTransformNoneApplied() { |
| 347 | + UIManagerModule uiManager = getUIManagerModule(); |
| 348 | + |
| 349 | + String testTextEntered = ".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd "; |
| 350 | + String testTextTransformed = testTextEntered; |
| 351 | + |
| 352 | + ReactRootView rootView = createText( |
| 353 | + uiManager, |
| 354 | + JavaOnlyMap.of("textTransform", "none"), |
| 355 | + JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered)); |
| 356 | + |
| 357 | + TextView textView = (TextView) rootView.getChildAt(0); |
| 358 | + assertThat(textView.getText().toString()).isEqualTo(testTextTransformed); |
| 359 | + } |
| 360 | + |
| 361 | + @Test |
| 362 | + public void testTextTransformUppercaseApplied() { |
| 363 | + UIManagerModule uiManager = getUIManagerModule(); |
| 364 | + |
| 365 | + String testTextEntered = ".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd "; |
| 366 | + String testTextTransformed = ".AA\tBB\t\tCC DD EE \r\nZZ I LIKE TO EAT APPLES. \n中文ÉÉ 我喜欢吃苹果。AWDAWD "; |
| 367 | + |
| 368 | + ReactRootView rootView = createText( |
| 369 | + uiManager, |
| 370 | + JavaOnlyMap.of("textTransform", "uppercase"), |
| 371 | + JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered)); |
| 372 | + |
| 373 | + TextView textView = (TextView) rootView.getChildAt(0); |
| 374 | + assertThat(textView.getText().toString()).isEqualTo(testTextTransformed); |
| 375 | + } |
| 376 | + |
| 377 | + @Test |
| 378 | + public void testTextTransformLowercaseApplied() { |
| 379 | + UIManagerModule uiManager = getUIManagerModule(); |
| 380 | + |
| 381 | + String testTextEntered = ".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd "; |
| 382 | + String testTextTransformed = ".aa\tbb\t\tcc dd ee \r\nzz i like to eat apples. \n中文éé 我喜欢吃苹果。awdawd "; |
| 383 | + |
| 384 | + ReactRootView rootView = createText( |
| 385 | + uiManager, |
| 386 | + JavaOnlyMap.of("textTransform", "lowercase"), |
| 387 | + JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered)); |
| 388 | + |
| 389 | + TextView textView = (TextView) rootView.getChildAt(0); |
| 390 | + assertThat(textView.getText().toString()).isEqualTo(testTextTransformed); |
| 391 | + } |
| 392 | + |
| 393 | + @Test |
| 394 | + public void testTextTransformCapitalizeApplied() { |
| 395 | + UIManagerModule uiManager = getUIManagerModule(); |
| 396 | + |
| 397 | + String testTextEntered = ".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd "; |
| 398 | + String testTextTransformed = ".Aa\tBb\t\tCc Dd Ee \r\nZz I Like To Eat Apples. \n中文Éé 我喜欢吃苹果。Awdawd "; |
| 399 | + |
| 400 | + ReactRootView rootView = createText( |
| 401 | + uiManager, |
| 402 | + JavaOnlyMap.of("textTransform", "capitalize"), |
| 403 | + JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered)); |
| 404 | + |
| 405 | + TextView textView = (TextView) rootView.getChildAt(0); |
| 406 | + assertThat(textView.getText().toString()).isEqualTo(testTextTransformed); |
| 407 | + } |
| 408 | + |
344 | 409 | // JELLY_BEAN is needed for TextView#getMaxLines(), which is OK, because in the actual code we
|
345 | 410 | // only use TextView#setMaxLines() which exists since API Level 1.
|
346 | 411 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
|
1 commit comments
ziyafenn commentedon Nov 8, 2018
enabling textTransform on android with RN0.57.4 breaks the styling of the text and renders the text very weirdly.