diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 49e85c24c3a..60c865e204d 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -7667,15 +7667,21 @@ public class com/facebook/react/views/text/TextLayoutManager { public final class com/facebook/react/views/text/TextTransform : java/lang/Enum { public static final field CAPITALIZE Lcom/facebook/react/views/text/TextTransform; + public static final field Companion Lcom/facebook/react/views/text/TextTransform$Companion; public static final field LOWERCASE Lcom/facebook/react/views/text/TextTransform; public static final field NONE Lcom/facebook/react/views/text/TextTransform; public static final field UNSET Lcom/facebook/react/views/text/TextTransform; public static final field UPPERCASE Lcom/facebook/react/views/text/TextTransform; - public static fun apply (Ljava/lang/String;Lcom/facebook/react/views/text/TextTransform;)Ljava/lang/String; + public static final fun apply (Ljava/lang/String;Lcom/facebook/react/views/text/TextTransform;)Ljava/lang/String; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/views/text/TextTransform; public static fun values ()[Lcom/facebook/react/views/text/TextTransform; } +public final class com/facebook/react/views/text/TextTransform$Companion { + public final fun apply (Ljava/lang/String;Lcom/facebook/react/views/text/TextTransform;)Ljava/lang/String; +} + public class com/facebook/react/views/text/frescosupport/FrescoBasedReactTextInlineImageViewManager : com/facebook/react/uimanager/BaseViewManager { public static final field REACT_CLASS Ljava/lang/String; public fun ()V diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextTransform.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextTransform.java deleted file mode 100644 index 6670ec5247e..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextTransform.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.views.text; - -import androidx.annotation.Nullable; -import java.text.BreakIterator; - -/** Types of text transforms for CustomTextTransformSpan */ -public enum TextTransform { - NONE, - UPPERCASE, - LOWERCASE, - CAPITALIZE, - UNSET; - - public static String apply(@Nullable String text, TextTransform textTransform) { - if (text == null) { - return null; - } - - String transformed; - switch (textTransform) { - case UPPERCASE: - transformed = text.toUpperCase(); - break; - case LOWERCASE: - transformed = text.toLowerCase(); - break; - case CAPITALIZE: - transformed = capitalize(text); - break; - default: - transformed = text; - } - - return transformed; - } - - private static String capitalize(String text) { - BreakIterator wordIterator = BreakIterator.getWordInstance(); - wordIterator.setText(text); - - StringBuilder res = new StringBuilder(text.length()); - int start = wordIterator.first(); - for (int end = wordIterator.next(); end != BreakIterator.DONE; end = wordIterator.next()) { - res.append(Character.toUpperCase(text.charAt(start))); - res.append(text.substring(start + 1, end)); - start = end; - } - - return res.toString(); - } -}; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextTransform.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextTransform.kt new file mode 100644 index 00000000000..7da115539bb --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextTransform.kt @@ -0,0 +1,55 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.views.text + +import java.text.BreakIterator +import java.util.Locale + +/** Types of text transforms for CustomTextTransformSpan */ +public enum class TextTransform { + + NONE, + UPPERCASE, + LOWERCASE, + CAPITALIZE, + UNSET; + + public companion object { + @JvmStatic + public fun apply(text: String?, textTransform: TextTransform?): String? { + if (text == null) { + return null + } + val transformed: String = + when (textTransform) { + UPPERCASE -> text.uppercase(Locale.getDefault()) + LOWERCASE -> text.lowercase(Locale.getDefault()) + CAPITALIZE -> capitalize(text) + else -> text + } + return transformed + } + + private fun capitalize(text: String): String { + val wordIterator = BreakIterator.getWordInstance() + wordIterator.setText(text) + + val res = StringBuilder(text.length) + var start = wordIterator.first() + var end = wordIterator.next() + while (end != BreakIterator.DONE) { + res.append(text[start].uppercaseChar()) + res.append(text.substring(start + 1, end)) + start = end + end = wordIterator.next() + } + + return res.toString() + } + } +}