From 66948c09f6cf19dedd272d8d339632eb43517bab Mon Sep 17 00:00:00 2001 From: duguyihou Date: Tue, 16 Apr 2024 18:42:50 +1000 Subject: [PATCH] refactor: wip --- .../java/com/gradient/GradientViewManager.kt | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/android/src/main/java/com/gradient/GradientViewManager.kt b/android/src/main/java/com/gradient/GradientViewManager.kt index 1ef9bbe..af421d2 100644 --- a/android/src/main/java/com/gradient/GradientViewManager.kt +++ b/android/src/main/java/com/gradient/GradientViewManager.kt @@ -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 @@ -21,21 +21,22 @@ class GradientViewManager : SimpleViewManager() { private var colors: List? = 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 {