अगर आपको बॉटम शीट को लागू करना है, तो
ModalBottomSheet
कंपोज़ेबल.
content
स्लॉट का इस्तेमाल किया जा सकता है. इसमें लेआउट शीट के लिए ColumnScope
का इस्तेमाल किया जाता है
किसी कॉलम में कंपोज़ेबल:
ModalBottomSheet(onDismissRequest = { /* Executed when the sheet is dismissed */ }) { // Sheet content }
प्रोग्राम के हिसाब से शीट को बड़ा और छोटा किया जाता है. इसके लिए,
SheetState
. इंस्टेंस बनाने के लिए, rememberSheetState
का इस्तेमाल किया जा सकता है
SheetState
का है, जिसे ModalBottomSheet
को
sheetState
पैरामीटर. SheetState
, show
का ऐक्सेस देता है और
hide
फ़ंक्शन और मौजूदा शीट से जुड़ी प्रॉपर्टी
state. इन निलंबित फ़ंक्शन के लिए, CoroutineScope
की ज़रूरत होती है — उदाहरण के लिए,
rememberCoroutineScope
का इस्तेमाल किया जा रहा है — और यूज़र इंटरफ़ेस (यूआई) के जवाब में कॉल किया जा सकता है
इवेंट. छिपाए जाने पर ModalBottomSheet
को कंपोज़िशन से निकालना न भूलें
बॉटम शीट है.
val sheetState = rememberModalBottomSheetState() val scope = rememberCoroutineScope() var showBottomSheet by remember { mutableStateOf(false) } Scaffold( floatingActionButton = { ExtendedFloatingActionButton( text = { Text("Show bottom sheet") }, icon = { Icon(Icons.Filled.Add, contentDescription = "") }, onClick = { showBottomSheet = true } ) } ) { contentPadding -> // Screen content if (showBottomSheet) { ModalBottomSheet( onDismissRequest = { showBottomSheet = false }, sheetState = sheetState ) { // Sheet content Button(onClick = { scope.launch { sheetState.hide() }.invokeOnCompletion { if (!sheetState.isVisible) { showBottomSheet = false } } }) { Text("Hide bottom sheet") } } } }