Skip to content

Instantly share code, notes, and snippets.

@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 }
transition {
rotation using repeatable {
animation = tween { duration = 1000 }
iterations = Infinite
animation = tween {
duration = 1000
easing = LinearEasing
}
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
@Composable
private fun RotatingPokeBall() {
RotateIndefinitely(durationPerRotation = 4000) {
Opacity(opacity = 0.75f) {
DrawImage(
image = +imageResource(R.drawable.pokeball),
tint = +colorResource(R.color.poke_red)
)
}
}
@Composable
private fun RotatingText() {
RotateIndefinitely(durationPerRotation = 4000) {
Text("Rotating text!")
}
}
@Composable
fun Square(isDarkSquare: Boolean) {
Canvas(modifier = Modifier.fillMaxSize(1f)) {
drawRect(color = if (isDarkSquare) darkSquareColor else lightSquareColor)
}
}
@Composable
fun Board() {
Box(Modifier.fillMaxSize().aspectRatio(1f)) {
Column {
for (rank in 8 downTo 1) {
Row(modifier = Modifier.weight(1f)) {
for (file in 1..8) {
Square(Modifier.weight(1f).fillMaxSize(), /* other params */)
}
}
@Composable
fun Piece(pieceModel: Piece) {
Text(
text = pieceModel.symbol,
fontSize = 28.sp
)
}
@Composable
fun Piece(pieceModel: Piece) {
Icon(
painter = painterResource(id = pieceModel.asset),
tint = Color.Unspecified
)
}