Elye
Elye

Reputation: 60081

How to use Modifier.contentSize in Jetpack Compose?

In https://developer.android.com/jetpack/compose/animation

If you are animating changes to content size:
Use Modifier.contentSize.

However, I cannot find how to access Modifier.contentSize and use it. Any guide?

Upvotes: 5

Views: 5734

Answers (1)

Wilson Tran
Wilson Tran

Reputation: 4801

I think you are talking about the animateContentSize function.

Here I have an example that might help

Column(
        modifier = Modifier
            .fillMaxWidth()
            .padding(16.dp)
            // This `Column` animates its size when its content changes.
            .animateContentSize()
    ) {
        Row {
            Icon(
                imageVector = Icons.Default.Info,
                contentDescription = null
            )
            // ...
        }
        if (expanded) { // If the expanded value is changed then the animateContentSize will be triggered
            Spacer(modifier = Modifier.height(8.dp))
            Text(
                text = stringResource(R.string.lorem_ipsum),
                textAlign = TextAlign.Justify
            )
        }
    }

enter image description here

From the Jetpack Compose Animation codelab:

Upvotes: 12

Related Questions