https://kotlinlang.org logo
#compose
Title
# compose
o

Olivier Patry

03/07/2021, 11:37 AM
I had an unexpected behavior, I'd consider it as a bug, but maybe there is a reason for that. Using the
BackdropScaffold
with a nullable front content. The front content is well displayed when not null, then when state is updated to
null
previous state remains.
Copy code
@Composable
fun AppScreen() {
    val viewModel = viewModel()
    val state by viewModel.state.observeAsState(null)

    BackdropScaffold(
        appBar = { },
        backLayerContent = {
            Column(
                Modifier.fillMaxWidth()
            ) {
                //
                Text("BACK")
            }
        },
        frontLayerContent = {
            state?.let { uiState ->
                Text("FRONT")
            }
        }
    )
}
To workaround this, I had to add an empty box:
Copy code
state?.let { uiState ->
    Text("FRONT")
} ?: Box {}
Is it expected? When the state is null at the beginning nothing is displayed as expected without the workaround.
n

nglauber

03/07/2021, 1:57 PM
I found a workaround… You can set the
headerHeight
as `0.dp`…
Copy code
BackdropScaffold(
    appBar = {},
    backLayerContent = {
        // You content...
    },
    headerHeight = if (!shouldShow) 0.dp else BackdropScaffoldDefaults.HeaderHeight,
    frontLayerContent = {
        // Your header
    },
    scaffoldState = state,
    stickyFrontLayer = false
)
Hope to see a better solution…
3 Views