预览
Composable
@OptIn(ExperimentalMaterialApi::class)
@Composable
@Preview
fun ImageSheetDialogExample() {var sheetState = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden)var coroutineScope = rememberCoroutineScope()Column(modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {Button(modifier = Modifier.padding(top = 10.dp), onClick = {coroutineScope.launch {sheetState.show()}}) {Text(text = "照片添加")}}ImageSheetDialog(sheetState, onTake = {}, onAlbum = {}, onCancel = {coroutineScope.launch {sheetState.hide()}})
}
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun ImageSheetDialog(sheetState: ModalBottomSheetState,onTake: () -> Unit,onAlbum: () -> Unit,onCancel: () -> Unit,color: Color = Color(0xFFF9F9F9),textColor: Color = Color(0xFF2D85FF),fontSize: TextUnit = TextUnit(16f, TextUnitType.Sp),
) {ModalBottomSheetLayout(sheetContent = {Column(modifier = Modifier.padding(horizontal = 10.dp).background(color = Color.Transparent,).fillMaxWidth()) {Column(modifier = Modifier.background(color = color,shape = RoundedCornerShape(8.dp))) {TextButton(modifier = Modifier.fillMaxWidth(),shape = RoundedCornerShape(topStart = 8.dp, topEnd = 8.dp),onClick = {onTake()}) {Text(modifier = Modifier.padding(vertical = 5.dp),text = "拍照",color = textColor,fontSize = fontSize)}Divider(color = Color(0xffD4D4D4))TextButton(modifier = Modifier.fillMaxWidth(),shape = RoundedCornerShape(bottomStart = 8.dp, bottomEnd = 8.dp),onClick = {onAlbum()}) {Text(modifier = Modifier.padding(vertical = 5.dp),text = "相册",color = textColor,fontSize = fontSize)}}TextButton(modifier = Modifier.fillMaxWidth().padding(top = 5.dp, bottom = 10.dp),shape = RoundedCornerShape(8.dp),colors = ButtonDefaults.textButtonColors(containerColor = color),onClick = {onCancel()}) {Text(modifier = Modifier.padding(vertical = 5.dp),text = "取消",color = textColor,fontSize = fontSize)}}}, sheetState = sheetState, sheetBackgroundColor = Color.Transparent, sheetElevation = 0.dp){}
}