Closed Martmists-GH closed 7 months ago
Hey @Martmists-GH, does this issue happen only with the desktop and web? If I'm correct, we can't use LookaheadLayout
with the LazyColumn
yet, and it will be supported in the future Compose. Let me keep you updated on this if I get any news.
Android is also affected, and regular Column
s and Row
s are also affected by this.
Hey @Martmists-GH, the new release (0.3.2) introduced new functions to achieve this. Please check out the documentation: https://github.com/skydoves/orbital#shared-element-transition-with-lazylist
Hmm, I haven't quite gotten it to work with that. Here's my new code:
@Composable
fun CardGrid(cards: List<OwnedCardGraphQL>) {
val itemWidth = 256
val padding = 5
var width by remember { mutableStateOf(1) }
var selected by remember { mutableStateOf(-1) }
val cardIsSelected by derivedStateOf { selected >= 0 }
val cardRenders = remember {
// No longer scoped to OrbitalScope
Array<@Composable () -> Unit>(cards.size) { { } }
}
Orbital {
// Remember cards in Orbital scope
cards.forEachIndexed { i, it ->
val item = rememberMovableContentOf {
CardRender(
modifier = Modifier
.animateBounds() // replaces animateSharedElementTransition(this)
.clickable(!cardIsSelected) {
selected = i
},
card = it
)
}
cardRenders[i] = item
}
// Row/Grid of cards
Row {
cards.forEachIndexed { i, it ->
Box {
CardRender()
if (!cardIsSelected) {
Orbital { // Now in new Orbital, mirroring the example
cardRenders[i]()
}
}
}
}
}
// Fullscreen preview (overlay) of selected card
if (cardIsSelected) {
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.End,
modifier = Modifier
.clickable {
selected = -1
}
.fillMaxSize()
) {
if (cardIsSelected) {
Orbital { // Now in new Orbital, mirroring the example
cardRenders[selected]()
}
}
}
}
}
}
It seems to be caused by nested elements, here is a reproducer
@Composable
fun Example() {
var expanded by rememberSaveable { mutableStateOf(false) }
val content = rememberContentWithOrbitalScope {
Text("Sample Text", modifier=Modifier.animateSharedElementTransition(this))
}
Orbital {
if (expanded) {
Column(modifier = Modifier.fillMaxSize()) {
content()
Button(onClick = {
expanded = false
}) {
Text("Toggle")
}
}
} else {
Row(modifier = Modifier.fillMaxSize(), verticalAlignment = Alignment.CenterVertically) {
// Column { // Uncomment this to make orbital animations stop working
content()
Button(onClick = {
expanded = true
}) {
Text("Toggle")
}
// }
}
}
}
}
Please complete the following information:
Describe the Bug: All entries become invisible and the first location is used as the source location.
Expected Behavior:
Only the selected entry moves
Code snippet