Atul Gupta
09/11/2024, 11:03 PManimateContentSize(tween())
when DropdownMenuItem
count changes as suggested in 5 Quick Animations to Make Your Compose App Stand Out
()
But the animation is stuttering or not that smooth(the video is attached for the release build). Code is mentioned in the 🧵
is there a way to make it more smoother?Atul Gupta
09/11/2024, 11:04 PMpackage com.example.composelistrecomposition
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.material3.Button
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
/**
* For animation in drop down
*/
class MainActivity3 : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AnimateDropDown()
}
}
}
@Composable
private fun AnimateDropDown() {
DropdownMenu(
modifier = Modifier.animateContentSize(tween()),
expanded = true,
onDismissRequest = { /*TODO*/ }
) {
val list = remember {
SnapshotStateList<String>()
}
var count by remember {
mutableIntStateOf(0)
}
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Text("Add/Remove")
Button(onClick = { count++; list.add("Item $count") }) {
Text(text = "+")
}
Button(enabled = count > 0, onClick = { count--; list.removeLast() }) {
Text(text = "-")
}
}
list.forEach {
DropdownMenuItem(text = { Text(it) }, onClick = { /*TODO*/ })
}
}
}
Atul Gupta
09/11/2024, 11:07 PMJonathan
09/12/2024, 3:11 AMAtul Gupta
09/12/2024, 6:25 AMLazyColumn
in DropdownMenu
see https://issuetracker.google.com/issues/242398344
But anyway even with normal column animation should be smooth and should not require LazyColoumnJonathan
09/12/2024, 1:38 PMAtul Gupta
09/12/2024, 6:26 PMDropdownMenu
is not working smoothly
I have attached the video for the same kind of UI using Popup as below. It suffers from the same problem
@Composable
private fun AnimateDropDownUsingCustomBlue() {
Popup {
Column(
modifier = Modifier
.background(color = Color.Blue)
.animateContentSize(tween())
) {
val list = remember {
SnapshotStateList<String>()
}
var count by remember {
mutableIntStateOf(0)
}
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Text("Add/Remove")
Button(onClick = { count++; list.add("Item $count") }) {
Text(text = "+")
}
Button(enabled = count > 0, onClick = { count--; list.removeLast() }) {
Text(text = "-")
}
}
LazyColumn {
items(list) {
Text(
modifier = Modifier
.height(64.dp)
.padding(8.dp),
text = it,
fontSize = 18.sp
)
}
}
}
}
}
Jonathan
09/12/2024, 7:41 PMJonathan
09/12/2024, 7:45 PMJonathan
09/12/2024, 7:48 PMJonathan
09/12/2024, 7:49 PMJonathan
09/12/2024, 7:50 PMAtul Gupta
09/12/2024, 7:54 PMJonathan
09/12/2024, 7:56 PMJonathan
09/12/2024, 7:56 PMAtul Gupta
09/12/2024, 8:04 PM