Skip to content

Commit

Permalink
Fix broken Fabric Interop example (#40942)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
cortinico authored and huntie committed Oct 19, 2023
1 parent 5cacb4f commit bfa19cb
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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())
Expand All @@ -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)
Expand Down

0 comments on commit bfa19cb

Please sign in to comment.