Skip to content

Instantly share code, notes, and snippets.

@theapache64
Created March 30, 2021 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theapache64/9dfa23d9f688112b9a51c1fe36de1271 to your computer and use it in GitHub Desktop.
Save theapache64/9dfa23d9f688112b9a51c1fe36de1271 to your computer and use it in GitHub Desktop.
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.desktop.Window
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.unit.sp
// Preview
fun main() {
Window {
var enabled by remember { mutableStateOf(true) }
val targetValue = if (enabled) {
0f
} else {
180f
}
val animatedValue by animateFloatAsState(
targetValue = targetValue,
animationSpec = tween(2000),
finishedListener = {
enabled = !enabled
}
)
Box(
modifier = Modifier
.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Text(
modifier = Modifier.rotate(animatedValue),
text = "Test",
fontSize = 30.sp
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment