Would movableContentOf be useful in cases like thi...
# compose-android
z
Would movableContentOf be useful in cases like this?
Copy code
IconButton(onClick = onClickFullscreen) {
    if (isFullscreen) {
        Icon(
            imageVector = Icons.Default.FullscreenExit,
            contentDescription = stringResource(R.string.close_fullscreen)
        )
    } else {
        Icon(
            imageVector = Icons.Default.Fullscreen,
            contentDescription = stringResource(R.string.open_fullscreen)
        )
    }
}
f
Nope, it's useful when you move something that's the same in more than 1 place
z
oh I see, thank you
f
I believe that whether it's the same or not is not the accurate answer, you can have the same composable in 2 places and you simply call the composable function in one place or the other and that's fine. What matters is if your composable is stateful, by having distinct composables in the
if
and
else
they have separate states and the state is lost when switching from the
if
to the
else
or vice versa (though you can save it with
rememberSaveable
). But the main difference is that, with
moveableContentOf
you can have the 2 composables be the same and have the same state when moving from one location to another.
z
ive seen it mainly used for landscape / portrait
f
if it's stateless, you don't gain anything from
moveableContentOf
though
z
i thought i might be able to use it in my app somewhere, but doesnt seem like theres anywhere suitable for it
f
this applies, for instance, to the navigation controller when you switch from portrait to landscape and want to have the same state with tabs (portrait) or rail (landscape)
i.e., you want to remember what nav destination was selected and retain that on rotation
z
ohh thats interesting
i kinda get it now