简体   繁体   中英

How i can implement bottomSheet in jetpack compose with three states?

i need to implement this three states bottom sheet layout with jetpack compose usage, how i can implement this by best practices?

https://i.stack.imgur.com/86FXs.png

ModalBottomSheetValue has a state HalfExpanded

The bottom sheet is partially visible at 50% of the screen height. This state is only enabled if the height of the bottom sheet is more than 50% of the screen height.

as a result yours ModalBottomSheetLayout should have a height of more than half of the screen

My example. Please pay attention to this code height(600.dp) . Try to play with this value

class ComposeActivity7 : ComponentActivity() {

    @ExperimentalMaterialApi
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            ComposeTutorialTheme {
                val modalBottomSheetState =
                    rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)
                val scope = rememberCoroutineScope()

                Scaffold(
                    floatingActionButton = {
                        FloatingActionButton(
                            onClick = {
                                scope.launch {
                                    modalBottomSheetState.show()
                                }
                            }) {
                            Icon(
                                Icons.Rounded.Add,
                                contentDescription = "add"
                            )
                        }
                    }) {
                    ModalBottomSheetLayout(
                        sheetState = modalBottomSheetState,
                        sheetContent = {
                            MySheet()

                        }
                    ) {
                        Text("hello")
                    }
                }
            }
        }
    }
}

@Composable
fun MySheet() {
    Column {
        Box(
            modifier = Modifier
                .fillMaxWidth()
                .height(600.dp)
        )
    }
}

RESULT

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM