From cd04aae1a33608cc5d9ebd3a8a7bb726ca8d74a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Mon, 24 Mar 2025 10:37:59 -0700 Subject: [PATCH] Migrate `ReactTextChangedEvent` to Kotlin (#50203) Summary: Migrate com.facebook.react.views.textinput.ReactTextChangedEvent to Kotlin. ## Changelog: [INTERNAL] - Migrate com.facebook.react.views.textinput.ReactTextChangedEvent to Kotlin Pull Request resolved: https://github.com/facebook/react-native/pull/50203 Test Plan: ```bash yarn test-android yarn android ``` Reviewed By: javache, Abbondanzo Differential Revision: D71681502 Pulled By: arushikesarwani94 fbshipit-source-id: 9639740a41bbebf943bc716c495c3593461346a6 --- .../ReactAndroid/api/ReactAndroid.api | 7 ++- .../textinput/ReactTextChangedEvent.java | 52 ------------------- .../views/textinput/ReactTextChangedEvent.kt | 47 +++++++++++++++++ 3 files changed, 52 insertions(+), 54 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextChangedEvent.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextChangedEvent.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 17a99a3cb22..ed94ab49fb7 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -7121,14 +7121,17 @@ public class com/facebook/react/views/textinput/ReactEditText : androidx/appcomp protected fun verifyDrawable (Landroid/graphics/drawable/Drawable;)Z } -public class com/facebook/react/views/textinput/ReactTextChangedEvent : com/facebook/react/uimanager/events/Event { +public final class com/facebook/react/views/textinput/ReactTextChangedEvent : com/facebook/react/uimanager/events/Event { + public static final field Companion Lcom/facebook/react/views/textinput/ReactTextChangedEvent$Companion; public static final field EVENT_NAME Ljava/lang/String; public fun (IILjava/lang/String;I)V public fun (ILjava/lang/String;I)V - protected fun getEventData ()Lcom/facebook/react/bridge/WritableMap; public fun getEventName ()Ljava/lang/String; } +public final class com/facebook/react/views/textinput/ReactTextChangedEvent$Companion { +} + public final class com/facebook/react/views/textinput/ReactTextInputLocalData { public fun (Landroid/widget/EditText;)V public final fun apply (Landroid/widget/EditText;)V diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextChangedEvent.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextChangedEvent.java deleted file mode 100644 index 4540b90abc2..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextChangedEvent.java +++ /dev/null @@ -1,52 +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 androidx.annotation.Nullable; -import com.facebook.react.bridge.Arguments; -import com.facebook.react.bridge.WritableMap; -import com.facebook.react.uimanager.common.ViewUtil; -import com.facebook.react.uimanager.events.Event; - -/** - * Event emitted by EditText native view when text changes. VisibleForTesting from {@link - * TextInputEventsTestCase}. - */ -public class ReactTextChangedEvent extends Event { - - public static final String EVENT_NAME = "topChange"; - - private String mText; - private int mEventCount; - - @Deprecated - public ReactTextChangedEvent(int viewId, String text, int eventCount) { - this(ViewUtil.NO_SURFACE_ID, viewId, text, eventCount); - } - - public ReactTextChangedEvent(int surfaceId, int viewId, String text, int eventCount) { - super(surfaceId, viewId); - mText = text; - mEventCount = eventCount; - } - - @Override - public String getEventName() { - return EVENT_NAME; - } - - @Nullable - @Override - protected WritableMap getEventData() { - WritableMap eventData = Arguments.createMap(); - eventData.putString("text", mText); - eventData.putInt("eventCount", mEventCount); - eventData.putInt("target", getViewTag()); - return eventData; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextChangedEvent.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextChangedEvent.kt new file mode 100644 index 00000000000..969efcf45e5 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextChangedEvent.kt @@ -0,0 +1,47 @@ +/* + * 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 com.facebook.react.bridge.Arguments +import com.facebook.react.bridge.WritableMap +import com.facebook.react.uimanager.common.ViewUtil +import com.facebook.react.uimanager.events.Event + +/** + * Event emitted by EditText native view when text changes. VisibleForTesting from + * [TextInputEventsTestCase]. + */ +public class ReactTextChangedEvent( + surfaceId: Int, + viewId: Int, + private val text: String, + private val eventCount: Int +) : Event(surfaceId, viewId) { + @Deprecated( + "Use the constructor with surfaceId instead", + ReplaceWith("ReactTextChangedEvent(surfaceId, viewId, text, eventCount)")) + public constructor( + viewId: Int, + text: String, + eventCount: Int + ) : this(ViewUtil.NO_SURFACE_ID, viewId, text, eventCount) + + override fun getEventName(): String = EVENT_NAME + + override fun getEventData(): WritableMap? { + return Arguments.createMap().apply { + putString("text", text) + putInt("eventCount", eventCount) + putInt("target", viewTag) + } + } + + public companion object { + public const val EVENT_NAME: String = "topChange" + } +}