From 345403f042b9703f4fbd39bf48007707999f2ae3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Fri, 21 Mar 2025 09:43:49 -0700 Subject: [PATCH] Migrate `ReactTextInputKeyPressEvent` to Kotlin (#50184) Summary: Migrate com.facebook.react.views.textinput.ReactTextInputKeyPressEvent to Kotlin. ## Changelog: [INTERNAL] - Migrate com.facebook.react.views.textinput.ReactTextInputKeyPressEvent to Kotlin Pull Request resolved: https://github.com/facebook/react-native/pull/50184 Test Plan: ```bash yarn test-android yarn android ``` Reviewed By: javache Differential Revision: D71588770 Pulled By: arushikesarwani94 fbshipit-source-id: 53354d9cd8cc24b9ec6f84de689ea4b2839e49ce --- .../ReactTextInputKeyPressEvent.java | 51 ------------------- .../textinput/ReactTextInputKeyPressEvent.kt | 35 +++++++++++++ 2 files changed, 35 insertions(+), 51 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputKeyPressEvent.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputKeyPressEvent.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputKeyPressEvent.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputKeyPressEvent.java deleted file mode 100644 index 9973b6ec2a5..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputKeyPressEvent.java +++ /dev/null @@ -1,51 +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 key pressed */ -/* package */ class ReactTextInputKeyPressEvent extends Event { - - public static final String EVENT_NAME = "topKeyPress"; - - private String mKey; - - @Deprecated - ReactTextInputKeyPressEvent(int viewId, final String key) { - this(ViewUtil.NO_SURFACE_ID, viewId, key); - } - - ReactTextInputKeyPressEvent(int surfaceId, int viewId, final String key) { - super(surfaceId, viewId); - mKey = key; - } - - @Override - public String getEventName() { - return EVENT_NAME; - } - - @Nullable - @Override - protected WritableMap getEventData() { - WritableMap eventData = Arguments.createMap(); - eventData.putString("key", mKey); - return eventData; - } - - @Override - public boolean canCoalesce() { - // We don't want to miss any textinput event, as event data is incremental. - return false; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputKeyPressEvent.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputKeyPressEvent.kt new file mode 100644 index 00000000000..4aa4e6bc0c6 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputKeyPressEvent.kt @@ -0,0 +1,35 @@ +/* + * 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 key pressed. */ +internal class ReactTextInputKeyPressEvent(surfaceId: Int, viewId: Int, private val key: String) : + Event(surfaceId, viewId) { + @Deprecated( + "Use the constructor with surfaceId instead", + ReplaceWith("ReactTextInputKeyPressEvent(surfaceId, viewId, key)")) + constructor(viewId: Int, key: String) : this(ViewUtil.NO_SURFACE_ID, viewId, key) + + override fun getEventName(): String = EVENT_NAME + + override fun getEventData(): WritableMap? { + return Arguments.createMap().apply { putString("key", key) } + } + + // We don't want to miss any textinput event, as event data is incremental. + override fun canCoalesce(): Boolean = false + + companion object { + const val EVENT_NAME: String = "topKeyPress" + } +}