Skip to content

Commit 175788c

Browse files
committed
update modifier when color, intensity, solidShape
1 parent 74ac0c4 commit 175788c

1 file changed

Lines changed: 30 additions & 8 deletions

File tree

gooey/src/main/java/com/doool/gooey/GooeyScope.kt

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.compose.foundation.clickable
55
import androidx.compose.foundation.layout.BoxScope
66
import androidx.compose.foundation.layout.LayoutScopeMarker
77
import androidx.compose.runtime.Immutable
8+
import androidx.compose.runtime.LaunchedEffect
89
import androidx.compose.runtime.remember
910
import androidx.compose.ui.Modifier
1011
import androidx.compose.ui.composed
@@ -45,11 +46,18 @@ internal class GooeyScopeImpl(boxScope: BoxScope, override val intensity: Float)
4546
val layoutDirection = LocalLayoutDirection.current
4647
val density = LocalDensity.current
4748

48-
val gooeyModifier =
49-
remember(color, intensity, solidShape) { GooeyModifier(color, intensity, solidShape) }
49+
val gooeyModifier = remember { GooeyModifier(color, intensity, solidShape) }
50+
51+
LaunchedEffect(key1 = color, block = {
52+
gooeyModifier.updateColor(color)
53+
})
54+
55+
LaunchedEffect(key1 = shape,key2= solidShape){
56+
gooeyModifier.updateBlur(intensity, solidShape)
57+
}
5058

5159
val sizeAndClickModifier =
52-
remember {
60+
remember(gooeyModifier) {
5361
Modifier
5462
.onSizeChanged { size ->
5563
gooeyModifier.updatePath(Path().apply {
@@ -70,18 +78,21 @@ internal class GooeyScopeImpl(boxScope: BoxScope, override val intensity: Float)
7078
}
7179

7280
internal class GooeyModifier(
73-
private val color: Color,
81+
color: Color,
7482
intensity: Float,
7583
solidShape: Boolean = false
7684
) : DrawModifier {
7785

86+
init {
87+
updateBlur(intensity, solidShape)
88+
updateColor(color)
89+
}
90+
7891
private var path = Path()
79-
private val blurPaint = createBlurPaint(
92+
private var blurPaint = createBlurPaint(
8093
intensity,
8194
if (solidShape) BlurMaskFilter.Blur.SOLID else BlurMaskFilter.Blur.NORMAL
82-
).apply {
83-
this.color = this@GooeyModifier.color
84-
}
95+
)
8596

8697
override fun ContentDrawScope.draw() {
8798
drawIntoCanvas { canvas ->
@@ -93,4 +104,15 @@ internal class GooeyModifier(
93104
fun updatePath(path: Path) {
94105
this.path = path
95106
}
107+
108+
fun updateColor(color: Color) {
109+
blurPaint.color = color
110+
}
111+
112+
fun updateBlur(intensity: Float, solidShape: Boolean) {
113+
blurPaint = createBlurPaint(
114+
intensity,
115+
if (solidShape) BlurMaskFilter.Blur.SOLID else BlurMaskFilter.Blur.NORMAL
116+
)
117+
}
96118
}

0 commit comments

Comments
 (0)