Skip to content

Instantly share code, notes, and snippets.

private val rotation = FloatPropKey()
private fun createDefinition(duration: Int) = transitionDefinition {
state(0) { this[rotation] = 0f }
state(1) { this[rotation] = 360f }
transition {
rotation using repeatable {
animation = tween {
easing = LinearEasing
animation = tween {
duration = 1000
easing = LinearEasing
}
private val rotation = FloatPropKey()
private val definition = transitionDefinition {
state(0) { this[rotation] = 0f }
state(1) { this[rotation] = 360f }
transition {
rotation using repeatable {
animation = tween { duration = 1000 }
iterations = Infinite
@Composable
fun RotatingPokeball() {
val children: @Composable() () -> Unit = {
Opacity(opacity = 0.75f) {
DrawImage(
image = +imageResource(R.drawable.pokeball),
tint = +colorResource(R.color.poke_red)
)
}
}
private val rotation = FloatPropKey()
private val definition = transitionDefinition {
state(0) { this[rotation] = 0f }
state(1) { this[rotation] = 360f }
}
I/System.out: Transition: 20.0
I/System.out: Transition: 68.80052
I/System.out: Transition: 153.58815
I/System.out: Transition: 234.93356
I/System.out: Transition: 292.17978
I/System.out: Transition: 331.75845
I/System.out: Transition: 359.05087
I/System.out: Transition: 375.11713
I/System.out: Transition: 385.07782
I/System.out: Transition: 391.43237
private val myFloatKey = FloatPropKey()
enum class MyState {
STATE_A, STATE_B
}
val definition = transitionDefinition {
state(STATE_A) {
this[myFloatKey] = 20f
}
@Composable
fun RotateAroundCenter() {
/* remainder omitted */
Draw(children = children) { canvas, parent ->
val halfWidth = parent.width.value / 2
val halfHeight = parent.height.value / 2
canvas.save()
canvas.translate(halfWidth, halfHeight)
@Composable
fun VisualDebug() {
// Wrapping it here for a visual clue
Surface(color = Color.LightGray) {
// From here on it's the same
Container(width = 200.dp, height = 200.dp) {
/* remainder omitted */
}
}
}
@Composable
fun Pokeball() {
Container(width = 200.dp, height = 200.dp) {
val children: @Composable() () -> Unit = {
Opacity(opacity = 0.75f) {
DrawImage(
image = +imageResource(R.drawable.pokeball),
tint = +colorResource(R.color.poke_red)
)
}