Skip to content

Instantly share code, notes, and snippets.

@hyoban
Created November 21, 2021 13:04
Show Gist options
  • Save hyoban/f4bd608cb1a36a021a25cfdae2d696e6 to your computer and use it in GitHub Desktop.
Save hyoban/f4bd608cb1a36a021a25cfdae2d696e6 to your computer and use it in GitHub Desktop.

animateContentSize

接收 animationSpec 和 finishedListener 两个参数

import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
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.graphics.Color
import androidx.compose.ui.unit.dp
@Composable
fun AnimateContentSizeExample() {
Box(
modifier = Modifier.fillMaxSize()
) {
var size by remember { mutableStateOf(50.dp) }
Box(
modifier = Modifier
.align(Alignment.Center)
.animateContentSize()
.size(size)
.background(Color.Blue)
.clickable {
size += 50.dp
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment