AG
07/18/2021, 7:48 AMSurface(color = MaterialTheme.colors.background) {
var state by remember {
mutableStateOf(false)
}
BottomSheetSample(
onExpandButtonClicked = { state = !state },
onMainButtonClicked = { /**TODO**/ },
expand = state
)
}
@ExperimentalMaterialApi
@Composable
fun BottomSheetSample(
onMainButtonClicked: () -> Unit,
onExpandButtonClicked: () -> Unit,
expand: Boolean
) {
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = BottomSheetState(BottomSheetValue.Collapsed)
)
LaunchedEffect(expand) {
if (expand) {
bottomSheetScaffoldState.bottomSheetState.expand()
} else {
bottomSheetScaffoldState.bottomSheetState.collapse()
}
}
BottomSheetScaffold(
scaffoldState = bottomSheetScaffoldState,
sheetContent = {
Box(
Modifier
.fillMaxWidth()
.fillMaxHeight(0.5f)
) {
Column(modifier = Modifier.matchParentSize()) {
Box(
modifier = Modifier
.fillMaxWidth()
.weight(1f)
) {
Text(
modifier = Modifier.align(Alignment.Center),
text = "Text",
style = TextStyle(fontSize = 26.sp)
)
}
Button(
onClick = { onMainButtonClicked() },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp)
.height(48.dp)
) {
Text("Main button")
}
}
}
}, sheetPeekHeight = 0.dp,
sheetShape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp)
) {
Button(onClick = {
onExpandButtonClicked()
}) {
Text(text = "Expand/Collapse Bottom Sheet")
}
}
}
LaunchedEffect(expand) {
if (expand) {
bottomSheetScaffoldState.bottomSheetState.expand()
} else {
bottomSheetScaffoldState.bottomSheetState.collapse()
}
}
so this code has no affect bottom sheet not expandingms
07/18/2021, 8:11 AMAG
07/18/2021, 8:22 AM