Fix broken Fabric Interop example (#40942)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/40942

The Fabric Interop example for Android is broken. This is due to the Kotlin conversion which moved the `Color.colorToHSV(color, hsv)` statement *after* the HSV array is read so the array is always [0,0,0].

I'm fixing it here.

Changelog:
[Internal] [Changed] - Fix broken Fabric Interop example

Reviewed By: cipolleschi

Differential Revision: D50264766

fbshipit-source-id: 27ae5289408c7c23c667d6d7112437fa7ebe36d5
This commit is contained in:
Nicola Corti
2023-10-16 10:17:46 -07:00
committed by Alex Hunt
parent dbef1d90d1
commit 8cae2e75e7
@@ -22,7 +22,7 @@ import com.facebook.react.uimanager.events.RCTEventEmitter
class MyNativeView(context: ThemedReactContext) : View(context) {
private var currentColor = 0
private var background: GradientDrawable = GradientDrawable()
private var reactContext: ReactContext = context.getReactApplicationContext()
private var reactContext: ReactContext = context.reactApplicationContext
override fun setBackgroundColor(color: Int) {
if (color != currentColor) {
@@ -34,13 +34,14 @@ class MyNativeView(context: ThemedReactContext) : View(context) {
}
fun setCornerRadius(cornerRadius: Float) {
background.setCornerRadius(cornerRadius)
background.cornerRadius = cornerRadius
setBackground(background)
}
private fun emitNativeEvent(color: Int) {
val event = Arguments.createMap()
val hsv = FloatArray(3)
Color.colorToHSV(color, hsv)
val backgroundColor =
Arguments.createMap().apply {
putDouble("hue", hsv[0].toDouble())
@@ -49,7 +50,6 @@ class MyNativeView(context: ThemedReactContext) : View(context) {
putDouble("alpha", Color.alpha(color).toDouble())
}
Color.colorToHSV(color, hsv)
event.putMap("backgroundColor", backgroundColor)
reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, "onColorChanged", event)