From d9876d8dc90627f0adb960a55a5874423e5ebef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Fri, 21 Mar 2025 09:43:45 -0700 Subject: [PATCH] Migrate `ReactTextInputFocusEvent` to Kotlin (#50185) Summary: Migrate com.facebook.react.views.textinput.ReactTextInputFocusEvent to Kotlin. ## Changelog: [INTERNAL] - Migrate com.facebook.react.views.textinput.ReactTextInputFocusEvent to Kotlin Pull Request resolved: https://github.com/facebook/react-native/pull/50185 Test Plan: ```bash yarn test-android yarn android ``` Reviewed By: javache Differential Revision: D71588274 Pulled By: arushikesarwani94 fbshipit-source-id: cbdabca31c5bfc6b2b5e4b6bf40dda4c591db1f2 --- .../textinput/ReactTextInputFocusEvent.java | 47 ------------------- .../textinput/ReactTextInputFocusEvent.kt | 34 ++++++++++++++ 2 files changed, 34 insertions(+), 47 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputFocusEvent.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputFocusEvent.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputFocusEvent.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputFocusEvent.java deleted file mode 100644 index 1689ca369a6..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputFocusEvent.java +++ /dev/null @@ -1,47 +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 it receives focus. */ -/* package */ class ReactTextInputFocusEvent extends Event { - - private static final String EVENT_NAME = "topFocus"; - - @Deprecated - public ReactTextInputFocusEvent(int viewId) { - this(ViewUtil.NO_SURFACE_ID, viewId); - } - - public ReactTextInputFocusEvent(int surfaceId, int viewId) { - super(surfaceId, viewId); - } - - @Override - public String getEventName() { - return EVENT_NAME; - } - - @Nullable - @Override - protected WritableMap getEventData() { - WritableMap eventData = Arguments.createMap(); - eventData.putInt("target", getViewTag()); - return eventData; - } - - @Override - public boolean canCoalesce() { - return false; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputFocusEvent.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputFocusEvent.kt new file mode 100644 index 00000000000..f40fb1e3375 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputFocusEvent.kt @@ -0,0 +1,34 @@ +/* + * 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 it receives focus. */ +internal class ReactTextInputFocusEvent(surfaceId: Int, viewId: Int) : + Event(surfaceId, viewId) { + @Deprecated( + "Use the constructor with surfaceId instead", + ReplaceWith("ReactTextInputFocusEvent(surfaceId, viewId)")) + constructor(viewId: Int) : this(ViewUtil.NO_SURFACE_ID, viewId) + + override fun getEventName(): String = EVENT_NAME + + override fun getEventData(): WritableMap? { + return Arguments.createMap().apply { putInt("target", viewTag) } + } + + override fun canCoalesce(): Boolean = false + + companion object { + private const val EVENT_NAME = "topFocus" + } +}