From 3422dcf55cce233dd4e6eb89778e3eb7e8e4142f Mon Sep 17 00:00:00 2001 From: Alan Lee Date: Mon, 8 Apr 2024 11:58:39 -0700 Subject: [PATCH] Convert ReactSwitchEvent to Kotlin (#43881) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43881 convert Java to Kotlin: `/react/views/switchview/ReactSwitchEvent.java` Changelog: [Internal] internal Reviewed By: cortinico Differential Revision: D55770377 fbshipit-source-id: e285d7e0c8b55745e05b0e0b1258c12fd02faa19 --- .../views/switchview/ReactSwitchEvent.java | 52 ------------------- .../views/switchview/ReactSwitchEvent.kt | 35 +++++++++++++ 2 files changed, 35 insertions(+), 52 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchEvent.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchEvent.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchEvent.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchEvent.java deleted file mode 100644 index f3073c928f3..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchEvent.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.switchview; - -import androidx.annotation.Nullable; -import com.facebook.infer.annotation.Nullsafe; -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 a ReactSwitchManager once a switch is fully switched on/off */ -/*package*/ @Nullsafe(Nullsafe.Mode.LOCAL) -class ReactSwitchEvent extends Event { - - public static final String EVENT_NAME = "topChange"; - - private final boolean mIsChecked; - - @Deprecated - public ReactSwitchEvent(int viewId, boolean isChecked) { - this(ViewUtil.NO_SURFACE_ID, viewId, isChecked); - } - - public ReactSwitchEvent(int surfaceId, int viewId, boolean isChecked) { - super(surfaceId, viewId); - mIsChecked = isChecked; - } - - public boolean getIsChecked() { - return mIsChecked; - } - - @Override - public String getEventName() { - return EVENT_NAME; - } - - @Nullable - @Override - protected WritableMap getEventData() { - WritableMap eventData = Arguments.createMap(); - eventData.putInt("target", getViewTag()); - eventData.putBoolean("value", getIsChecked()); - return eventData; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchEvent.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchEvent.kt new file mode 100644 index 00000000000..2fdf54b9ef2 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchEvent.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.switchview + +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 a ReactSwitchManager once a switch is fully switched on/off */ +internal class ReactSwitchEvent(surfaceId: Int, viewId: Int, private val isChecked: Boolean) : + Event(surfaceId, viewId) { + + @Deprecated( + "Use the constructor with surfaceId, viewId and isChecked parameters.", + replaceWith = ReplaceWith("ReactSwitchEvent(surfaceId, viewId, isChecked)")) + constructor(viewId: Int, isChecked: Boolean) : this(ViewUtil.NO_SURFACE_ID, viewId, isChecked) + + public override fun getEventName(): String = EVENT_NAME + + public override fun getEventData(): WritableMap? = + Arguments.createMap().apply { + putInt("target", viewTag) + putBoolean("value", isChecked) + } + + private companion object { + private const val EVENT_NAME = "topChange" + } +}