Skip to content

Commit 2753aef

Browse files
committed
Fix for #533 animated CircleNode modifier
This addresses #533 by recreating the Animatable when the node is attached.
1 parent 7f4c676 commit 2753aef

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

compose/snippets/src/main/java/com/example/compose/snippets/modifiers/CustomModifierSnippets.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.example.compose.snippets.modifiers
1818

1919
import android.annotation.SuppressLint
2020
import androidx.compose.animation.core.Animatable
21+
import androidx.compose.animation.core.AnimationVector1D
2122
import androidx.compose.animation.core.DecayAnimationSpec
2223
import androidx.compose.animation.core.RepeatMode
2324
import androidx.compose.animation.core.animateFloatAsState
@@ -259,14 +260,15 @@ class ScrollableNode :
259260
object CustomModifierSnippets14 {
260261
// [START android_compose_custom_modifiers_14]
261262
class CircleNode(var color: Color) : Modifier.Node(), DrawModifierNode {
262-
private val alpha = Animatable(1f)
263+
private lateinit var alpha: Animatable<Float, AnimationVector1D>
263264

264265
override fun ContentDrawScope.draw() {
265266
drawCircle(color = color, alpha = alpha.value)
266267
drawContent()
267268
}
268269

269270
override fun onAttach() {
271+
alpha = Animatable(1f)
270272
coroutineScope.launch {
271273
alpha.animateTo(
272274
0f,

0 commit comments

Comments
 (0)