Skip to content

Commit

Permalink
refactor: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
duguyihou committed Apr 16, 2024
1 parent bd36946 commit 66948c0
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions android/src/main/java/com/gradient/GradientViewManager.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.gradient

import android.content.Context
import android.view.View
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
Expand All @@ -21,21 +21,22 @@ class GradientViewManager : SimpleViewManager<View>() {
private var colors: List<Color>? = null

override fun createViewInstance(reactContext: ThemedReactContext): View {
return createComposeView(reactContext)
}

private fun createComposeView(context: Context): View {
return ComposeView(context).apply {
return ComposeView(reactContext).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
colors?.let {
val brush = Brush.verticalGradient(it)
Box(modifier = Modifier.background(brush))
}
GradientView()
}
}
}

@Composable
fun GradientView() {
colors?.let {
val brush = Brush.verticalGradient(it)
Box(modifier = Modifier.background(brush))
}
}

@ReactProp(name = "colors")
fun setColors(view: View, colors: ReadableArray) {
this.colors = colors.toArrayList().map {
Expand Down

0 comments on commit 66948c0

Please sign in to comment.