mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-11 22:40:37 +08:00
Android textTransform style support (#20572)
Summary: Issue https://github.com/facebook/react-native/issues/2088 (closed, but a bit pre-emptively imo, since Android support was skipped) Related (merged) iOS PR https://github.com/facebook/react-native/pull/18387 Related documentation PR https://github.com/facebook/react-native-website/pull/500 The basic desire is to have a declarative mechanism to transform text content to uppercase or lowercase or titlecase ("capitalized"). Pull Request resolved: https://github.com/facebook/react-native/pull/20572 Differential Revision: D9311716 Pulled By: hramos fbshipit-source-id: dfbb855117196958e7ae5e980700d31be07a448d
This commit is contained in:
committed by
Facebook Github Bot
parent
1081560d86
commit
22cf5dc566
@@ -36,6 +36,7 @@ import com.facebook.react.uimanager.ViewManager;
|
||||
import com.facebook.react.uimanager.ViewProps;
|
||||
import com.facebook.react.views.text.ReactRawTextShadowNode;
|
||||
import com.facebook.react.views.view.ReactViewBackgroundDrawable;
|
||||
import com.facebook.react.views.text.CustomTextTransformSpan;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -341,6 +342,70 @@ public class ReactTextTest {
|
||||
assertThat(((ReactViewBackgroundDrawable) backgroundDrawable).getColor()).isEqualTo(Color.BLUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextTransformNoneApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
String testTextEntered = ".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd ";
|
||||
String testTextTransformed = testTextEntered;
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of("textTransform", "none"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered));
|
||||
|
||||
TextView textView = (TextView) rootView.getChildAt(0);
|
||||
assertThat(textView.getText().toString()).isEqualTo(testTextTransformed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextTransformUppercaseApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
String testTextEntered = ".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd ";
|
||||
String testTextTransformed = ".AA\tBB\t\tCC DD EE \r\nZZ I LIKE TO EAT APPLES. \n中文ÉÉ 我喜欢吃苹果。AWDAWD ";
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of("textTransform", "uppercase"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered));
|
||||
|
||||
TextView textView = (TextView) rootView.getChildAt(0);
|
||||
assertThat(textView.getText().toString()).isEqualTo(testTextTransformed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextTransformLowercaseApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
String testTextEntered = ".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd ";
|
||||
String testTextTransformed = ".aa\tbb\t\tcc dd ee \r\nzz i like to eat apples. \n中文éé 我喜欢吃苹果。awdawd ";
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of("textTransform", "lowercase"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered));
|
||||
|
||||
TextView textView = (TextView) rootView.getChildAt(0);
|
||||
assertThat(textView.getText().toString()).isEqualTo(testTextTransformed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextTransformCapitalizeApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
String testTextEntered = ".aa\tbb\t\tcc dd EE \r\nZZ I like to eat apples. \n中文éé 我喜欢吃苹果。awdawd ";
|
||||
String testTextTransformed = ".Aa\tBb\t\tCc Dd Ee \r\nZz I Like To Eat Apples. \n中文Éé 我喜欢吃苹果。Awdawd ";
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of("textTransform", "capitalize"),
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, testTextEntered));
|
||||
|
||||
TextView textView = (TextView) rootView.getChildAt(0);
|
||||
assertThat(textView.getText().toString()).isEqualTo(testTextTransformed);
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
Reference in New Issue
Block a user