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

Vincent tiensi

12/15/2020, 2:10 PM
Not sure if this is a bug or not but, when I create a scaffold, I have an event that triggers opening the drawer. However this only works once, once I fire more close events it doesn’t close the drawer.
Copy code
val state = viewModel.state.observeAsState().value ?: return
val scaffoldState = rememberScaffoldState()
when (state.drawerEvent?.consume()) {
    DrawerState.OPEN -> {
        scaffoldState.drawerState.open()
    }
    DrawerState.CLOSE -> {
        scaffoldState.drawerState.close()
    }
}
Scaffold(scaffoldState = scaffoldState)
d

Dominaezzz

12/15/2020, 6:56 PM
This seems a bit weirdly written and I think you have a side effect in there.
Try something like this.
Copy code
LaunchedEffect(Unit) {
    viewModel.state.collect {
        /* drawer open/close here */
    }
}
v

Vincent tiensi

12/16/2020, 1:00 AM
Nevermind it’s an issue on my end, thanks for the help, wasn’t aware of launchedEffect.
3 Views