I tried the various methods I found as I am still learning and wish to update my previous question. I want a BottomSheetScaffold
to display a file MailView.kt
when a button
is clicked.
But, it is still not showing up though there are no problems displayed, please.
The code for BottomSheetScaffold
:
val scope = rememberCoroutineScope()
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState()
BottomSheetScaffold(
scaffoldState = bottomSheetScaffoldState,
sheetContent = {
MailView(scaffoldState = bottomSheetScaffoldState)
},
sheetPeekHeight = 0.dp, // Ensure the sheet is hidden initially
content = {
// Your main content
},
)
Code for button
:
Button(
onClick = {scope.launch {
bottomSheetScaffoldState.bottomSheetState.expand()
}
},
Code in MailView.kt
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MailView(scaffoldState: BottomSheetScaffoldState) {
val scope = rememberCoroutineScope()
Column(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.background(Color.White)
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
IconButton(onClick = {
scope.launch {
scaffoldState.bottomSheetState.hide()
}
}) {
Icon(
painter = painterResource(id = R.drawable.ic_close),
contentDescription = "Close",
tint = Color.Gray
)
}
Image(
painter = painterResource(id = R.drawable.logo_image),
contentDescription = "Logo",
modifier = Modifier.size(24.dp)
)
Text(
text = "SOME HEADER...",
fontFamily = customFontFamily,
fontWeight = FontWeight.Bold,
fontSize = 14.sp,
color = Color.Black
)
}
HorizontalDivider()
// Use the WebViewPage composable here
WebViewPage(url = "https://www.google.com")
}
}
New contributor
Mary Kay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.