enighma
07/22/2025, 11:33 PMLookaheadScope
However, it doesn't seem to do anything. Am I required to use moveableContent
for this to work?
I thought (hoped) animateBounds
would do the trick. Here's the code with the LookaheadScope
.
LookaheadScope {
Row(
modifier
.fillMaxWidth()
.padding(paddingValues),
horizontalArrangement = Arrangement.SpaceBetween
) {
tableau.forEachIndexed { i, stack ->
CardStack(
onDropped = { suit, value, dropSource ->
viewModel.onDropped(suit, value, CardLocation.decode(dropSource), TableauLocation(i))
},
) {
if (stack.isEmpty()) {
EmptyCard()
}
stack.forEach {
PlayingCard(
modifier = Modifier.animateBounds(this@LookaheadScope),
model = it.toUiModel(),
withShadow = true,
disabled = isPaused,
onDoubleClick = {
viewModel.onDoubleClickCard(it, TableauLocation(i))
},
onGetDropSource = { TableauLocation(i) },
)
}
}
}
}
}
Nitesh Singh
07/23/2025, 8:45 AManimateBounds
works only if the composable remains in the same composition key / layout hierarchy — that is, it only animates layout bounds inside the same parent. In your case, when a card is moved from one column to another, Compose sees it as a removal from one column and insertion into another → which doesn't animate, because it's not the same element.Nitesh Singh
07/23/2025, 8:56 AMNitesh Singh
07/23/2025, 9:19 AM