Skip to content

Commit

Permalink
Fix broken Fabric Interop example (facebook#40942)
Browse files Browse the repository at this point in the history
Summary:

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
  • Loading branch information
cortinico authored and facebook-github-bot committed Oct 16, 2023
1 parent 071f610 commit 25b9e06
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 25b9e06

Please sign in to comment.