Skip to main content

rememberMovableContentOf

Function rememberMovableContentOf 

Source
pub fn rememberMovableContentOf(content: impl Fn() + 'static) -> MovableContent
Expand description

Core runtime helpers commonly used by applications. Content written once that keeps its identity wherever it is shown.

movable names content by a key, which means writing the content out at every parent that might show it and trusting the keys to match. When the parents are alternatives – a pane docked in a stack or pulled out into a window of its own, a tab in a strip or torn into its own window – that is the same body written twice, and two bodies that must be kept in step by hand are two bodies that drift.

This hands back the content as a value instead. Write the body once, remember it, and call MovableContent::show from whichever parent is showing it this pass:

ⓘ
let pane = rememberMovableContentOf(move || PaneBody(state));
if docked {
    Box(Modifier::empty().offset(0.0, y), BoxSpec::default(), || pane.show());
} else {
    Box(Modifier::empty().window(config), BoxSpec::default(), || pane.show());
}

The identity comes from the remember, so two of these at one call site – one per row of a list – are two pieces of content, and the same one survives recomposition. Everything movable says about ordering, showing content at most once, and releasing it still holds; release this one with MovableContent::forget.

Content that has to be recognised from somewhere this value cannot reach – another composable that shows the same pane in another arrangement – wants movableContentOf instead, which takes the identity as a key.

Mirrors Jetpack Compose’s movableContentOf.