From a670c9aeb31d556d4f91d82ad4e29ec3db8487c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Fri, 21 Mar 2025 09:39:55 -0700 Subject: [PATCH] Migrate `ReactTextInputSelectionEvent` to Kotlin (#50182) Summary: Migrate com.facebook.react.views.textinput.ReactTextInputSelectionEvent to Kotlin. ## Changelog: [INTERNAL] - Migrate com.facebook.react.views.textinput.ReactTextInputSelectionEvent to Kotlin Pull Request resolved: https://github.com/facebook/react-native/pull/50182 Test Plan: ```bash yarn test-android yarn android ``` Reviewed By: javache Differential Revision: D71589613 Pulled By: arushikesarwani94 fbshipit-source-id: 5a93834b8e450e63629f409cd7711b7b0850e288 --- .../ReactTextInputSelectionEvent.java | 53 ------------------- .../textinput/ReactTextInputSelectionEvent.kt | 46 ++++++++++++++++ 2 files changed, 46 insertions(+), 53 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputSelectionEvent.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputSelectionEvent.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputSelectionEvent.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputSelectionEvent.java deleted file mode 100644 index ede96cd369f..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputSelectionEvent.java +++ /dev/null @@ -1,53 +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 the text selection changes. */ -/* package */ class ReactTextInputSelectionEvent extends Event { - - private static final String EVENT_NAME = "topSelectionChange"; - - private int mSelectionStart; - private int mSelectionEnd; - - @Deprecated - public ReactTextInputSelectionEvent(int viewId, int selectionStart, int selectionEnd) { - this(ViewUtil.NO_SURFACE_ID, viewId, selectionStart, selectionEnd); - } - - public ReactTextInputSelectionEvent( - int surfaceId, int viewId, int selectionStart, int selectionEnd) { - super(surfaceId, viewId); - mSelectionStart = selectionStart; - mSelectionEnd = selectionEnd; - } - - @Override - public String getEventName() { - return EVENT_NAME; - } - - @Nullable - @Override - protected WritableMap getEventData() { - WritableMap eventData = Arguments.createMap(); - - WritableMap selectionData = Arguments.createMap(); - selectionData.putInt("end", mSelectionEnd); - selectionData.putInt("start", mSelectionStart); - - eventData.putMap("selection", selectionData); - return eventData; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputSelectionEvent.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputSelectionEvent.kt new file mode 100644 index 00000000000..375cfd0ea5a --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputSelectionEvent.kt @@ -0,0 +1,46 @@ +/* + * 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 the text selection changes. */ +internal class ReactTextInputSelectionEvent( + surfaceId: Int, + viewId: Int, + private val selectionStart: Int, + private val selectionEnd: Int +) : Event(surfaceId, viewId) { + @Deprecated( + "Use the constructor with surfaceId instead", + ReplaceWith("ReactTextInputSelectionEvent(surfaceId, viewId, selectionStart, selectionEnd)")) + constructor( + viewId: Int, + selectionStart: Int, + selectionEnd: Int + ) : this(ViewUtil.NO_SURFACE_ID, viewId, selectionStart, selectionEnd) + + override fun getEventName(): String = EVENT_NAME + + override fun getEventData(): WritableMap? { + val selectionData = + Arguments.createMap().apply { + putInt("end", selectionEnd) + putInt("start", selectionStart) + } + + return Arguments.createMap().apply { putMap("selection", selectionData) } + } + + companion object { + private const val EVENT_NAME = "topSelectionChange" + } +}