Created
June 26, 2021 03:57
-
-
Save atommarvel/30606a92a5652051212ee265d111be5f to your computer and use it in GitHub Desktop.
Wiggle Wiggle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun WiggleWiggle() { | |
val targetDegrees by flippyFloats() | |
val degrees by animateFloatAsState(targetValue = targetDegrees) | |
Icon( | |
imageVector = Icons.Default.Notifications, | |
contentDescription = "Ding!", | |
modifier = Modifier.rotate(degrees) | |
) | |
} | |
@Composable | |
fun flippyFloats(initialValue: Float = 30f, intervalMs: Long = 300L): State<Float> { | |
return produceState(initialValue = initialValue) { | |
while (isActive) { | |
delay(intervalMs) | |
value *= -1 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment