Skip to content

Instantly share code, notes, and snippets.

@atommarvel
Created June 26, 2021 03:57
Show Gist options
  • Save atommarvel/30606a92a5652051212ee265d111be5f to your computer and use it in GitHub Desktop.
Save atommarvel/30606a92a5652051212ee265d111be5f to your computer and use it in GitHub Desktop.
Wiggle Wiggle
@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