eygraber
01/15/2023, 10:06 AMkey
function, but my use case doesn't guarantee that the keys will be unique.
I'm trying to solve this with movableContentOf
that I got/modified from here but when I use that, all of my items are immediately disposed. I'm not sure why they're disposing, but I'm also not sure why this would work in the first place.
val entries by entriesUpdateFlow.collectAsState(
// it's weird but effective way of getting initial value in this case
initial = entriesUpdateFlow().value.map(Entry.Companion::fromBaseEntry)
)
val movableEntries = entries.map { entry ->
movableContentOf {
Renderer(entry)
}
}
entries.forEachIndexed { index, _ ->
movableEntries[index]()
}
Filip Wiesner
01/15/2023, 11:05 AMmy use case doesn't guarantee that the keys will be uniqueWhat is this usecase? Can't you just "make up" unique IDs? Or maybe use a compound key with multiple properties.
eygraber
01/15/2023, 11:15 AMobject
.Filip Wiesner
01/15/2023, 11:24 AMentry.key
is more of a "type" of entry rather than identification of entry. Is that correct?Filip Wiesner
01/15/2023, 11:31 AMFilip Wiesner
01/15/2023, 11:36 AMval movableEntries = entries.map { entry ->
movableContentOf {
Renderer(entry)
}
}
This will be "immediately disposed" because you have to remember the movableContentOf
or store it outside of the composition.eygraber
01/15/2023, 11:48 AMmovableContentOf
, thanks!Filip Wiesner
01/15/2023, 11:49 AMentry.key
and pass the uniqueness contract to the user.eygraber
01/15/2023, 4:13 PMeygraber
01/15/2023, 10:09 PMyou have to remember theFor the sake of understanding I've been trying to makeor store it outside of the composition.movableContentOf
movableContentOf
work for me, but I think I'm missing something.
In the example I linked above it doesn't look like the movableContentOf
is remembered or stored outside of the composition.
I was able to get my use case to work by using a Map
approach where I store the movableContentOf
outside of the composition keyed by my Key
. But to me that seems functionally the same (and much more complex) than using the key
function.
I'm trying to do something similar to the linked example. This was the closest I could get (still stuck using my key), but when removing the first entry in the list, all the other entries get disposed.
I changed my Renderer
function to take the entry's composable as a param (wrapped in the movableContentOf
) because the Renderer
is also responsible for indirectly mutating the list, which seemed to cause several state issues.
val entries by entriesUpdateFlow.collectAsState()
val movableEntries = entries.map { entry ->
remember(it.key) { movableContentOf { it.Render() } }
}
entries.forEachIndexed { index, entry ->
RenderEntry(entry, movableEntries[index])
}
Maybe @Jorge Castillo has some ideas? The example came from his blog post.