Created
May 7, 2024 08:13
-
-
Save KlassenKonstantin/b29723ff6403efa657400fbcc948f6ae to your computer and use it in GitHub Desktop.
animateItem not fading out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
enableEdgeToEdge() | |
super.onCreate(savedInstanceState) | |
setContent { | |
TheTheme { | |
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> | |
val items = remember { | |
mutableStateListOf( | |
"Works fine", | |
"AnimatedVisibility doesn't work", | |
"graphicsLayer doesn't work", | |
"Works fine 2", | |
"AnimatedVisibility doesn't work 2", | |
"graphicsLayer doesn't work 2", | |
"Works fine 3", | |
"AnimatedVisibility doesn't work 3", | |
"graphicsLayer doesn't work 3", | |
"AnimatedVisibility doesn't work 4", | |
) | |
} | |
LazyColumn( | |
modifier = Modifier | |
.fillMaxSize() | |
.padding(horizontal = 16.dp), | |
contentPadding = innerPadding, | |
verticalArrangement = Arrangement.spacedBy(8.dp) | |
) { | |
items(items, key = {it }) { item -> | |
when { | |
item.contains("Works fine") -> Item(item, Modifier.animateItem()) { | |
items.remove(item) | |
} | |
item.contains("AnimatedVisibility") -> ItemInAnimatedVisibility(item, Modifier.animateItem()) { | |
items.remove(item) | |
} | |
else -> ItemWithGraphicsLayer(text = item, modifier = Modifier.animateItem()) { | |
items.remove(item) | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
@Composable | |
fun Item( | |
text: String, | |
modifier: Modifier, | |
onClick: () -> Unit, | |
) { | |
Text(text = text, modifier = modifier | |
.fillMaxWidth() | |
.clickable { onClick() } | |
.padding(16.dp)) | |
} | |
@Composable | |
fun ItemInAnimatedVisibility( | |
text: String, | |
modifier: Modifier, | |
onClick: () -> Unit, | |
) { | |
AnimatedVisibility(visible = true, modifier = modifier) { | |
Item(text, Modifier, onClick) | |
} | |
} | |
@Composable | |
fun ItemWithGraphicsLayer( | |
text: String, | |
modifier: Modifier, | |
onClick: () -> Unit, | |
) { | |
Box(modifier = modifier.graphicsLayer { }) { | |
Item(text, Modifier, onClick) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment