From 7358fcf10fffb5ba7aa4d00af103ebf6f558e388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Fri, 21 Mar 2025 09:40:39 -0700 Subject: [PATCH] Migrate `ReactTextInputLocalData` to Kotlin (#50183) Summary: Migrate com.facebook.react.views.textinput.ReactTextInputLocalData to Kotlin. ## Changelog: [INTERNAL] - Migrate com.facebook.react.views.textinput.ReactTextInputLocalData to Kotlin Pull Request resolved: https://github.com/facebook/react-native/pull/50183 Test Plan: ```bash yarn test-android yarn android ``` Reviewed By: javache Differential Revision: D71589108 Pulled By: arushikesarwani94 fbshipit-source-id: e460518ffca43346f32ea0742ef656d72f5ed2d5 --- .../ReactAndroid/api/ReactAndroid.api | 2 +- .../textinput/ReactTextInputLocalData.java | 44 ------------------- .../textinput/ReactTextInputLocalData.kt | 33 ++++++++++++++ 3 files changed, 34 insertions(+), 45 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputLocalData.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputLocalData.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index f05ddfe6a95..17a99a3cb22 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -7131,7 +7131,7 @@ public class com/facebook/react/views/textinput/ReactTextChangedEvent : com/face public final class com/facebook/react/views/textinput/ReactTextInputLocalData { public fun (Landroid/widget/EditText;)V - public fun apply (Landroid/widget/EditText;)V + public final fun apply (Landroid/widget/EditText;)V } public class com/facebook/react/views/textinput/ReactTextInputManager : com/facebook/react/uimanager/BaseViewManager { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputLocalData.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputLocalData.java deleted file mode 100644 index d8b60b38d1c..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputLocalData.java +++ /dev/null @@ -1,44 +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.textinput; - -import android.text.SpannableStringBuilder; -import android.util.TypedValue; -import android.widget.EditText; - -/** Local state bearer for EditText instance. */ -public final class ReactTextInputLocalData { - - private final SpannableStringBuilder mText; - private final float mTextSize; - private final int mMinLines; - private final int mMaxLines; - private final int mInputType; - private final int mBreakStrategy; - private final CharSequence mPlaceholder; - - public ReactTextInputLocalData(EditText editText) { - mText = new SpannableStringBuilder(editText.getText()); - mTextSize = editText.getTextSize(); - mInputType = editText.getInputType(); - mPlaceholder = editText.getHint(); - mMinLines = editText.getMinLines(); - mMaxLines = editText.getMaxLines(); - mBreakStrategy = editText.getBreakStrategy(); - } - - public void apply(EditText editText) { - editText.setText(mText); - editText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); - editText.setMinLines(mMinLines); - editText.setMaxLines(mMaxLines); - editText.setInputType(mInputType); - editText.setHint(mPlaceholder); - editText.setBreakStrategy(mBreakStrategy); - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputLocalData.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputLocalData.kt new file mode 100644 index 00000000000..a7891e60528 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputLocalData.kt @@ -0,0 +1,33 @@ +/* + * 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.textinput + +import android.text.SpannableStringBuilder +import android.util.TypedValue +import android.widget.EditText + +/** Local state bearer for EditText instance. */ +public class ReactTextInputLocalData(editText: EditText) { + private val text = SpannableStringBuilder(editText.text) + private val textSize = editText.textSize + private val minLines = editText.minLines + private val maxLines = editText.maxLines + private val inputType = editText.inputType + private val breakStrategy = editText.breakStrategy + private val placeholder: CharSequence? = editText.hint + + public fun apply(editText: EditText) { + editText.text = text + editText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize) + editText.minLines = minLines + editText.maxLines = maxLines + editText.inputType = inputType + editText.hint = placeholder + editText.breakStrategy = breakStrategy + } +}