I have the following compose component:
@Composable
fun ProductDetails(viewModel: ProductDetailsViewModel) {
val productInstalmentsByOcrName by viewModel.productInstalmentsByOcrName.collectAsStateWithLifecycle()
val product by viewModel.product.collectAsStateWithLifecycle()
val scope = rememberCoroutineScope()
val drawerState = rememberBottomDrawerState(BottomDrawerValue.Closed)
BottomDrawer(
drawerState = drawerState,
drawerContent = {
ReportModalContent(ocrProductNames = productInstalmentsByOcrName?.map { it.first }
?: emptyList(), onReport = { ocrProductName ->
viewModel.onReport(ocrProductName)
scope.launch {
drawerState.close()
}
})
},
) {
// .... Rest of the code...
IconButton(
onClick = { scope.launch { drawerState.open() } },
modifier = Modifier.align(Alignment.TopEnd)
) {
// ... Rest of the code
At no other point do I access drawerState in this code. However, as soon as the component gets rendered, it rerenders and sets the drawerState to Opened.
I assumed it had something to do with the Navigation component, since this component represents a screen, but not the initial one. But even when rendering as initial destination, the drawer opens on its own.
The first destination screen also has a BottomDrawer that looks just like this, so i thought that might somehow interfere. But after comenting the code from the other component regarding the bottom sheet the problem still persisted.
Since the other component has an identical looking BottomDrawer I don't know what the problem with this one is.
Any suggestions? Thanks in advance a lot
from Jetpack Compose Bottom Sheet Drawer opens on its own
No comments:
Post a Comment