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
This commit is contained in:
Alan Lee
2024-04-08 11:58:39 -07:00
committed by Facebook GitHub Bot
parent f77d028294
commit 3422dcf55c
2 changed files with 35 additions and 52 deletions
@@ -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<ReactSwitchEvent> {
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;
}
}
@@ -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<ReactSwitchEvent>(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"
}
}