| 
 | 1 | +/*  | 
 | 2 | + * Copyright 2023 The Android Open Source Project  | 
 | 3 | + *  | 
 | 4 | + * Licensed under the Apache License, Version 2.0 (the "License");  | 
 | 5 | + * you may not use this file except in compliance with the License.  | 
 | 6 | + * You may obtain a copy of the License at  | 
 | 7 | + *  | 
 | 8 | + * http://www.apache.org/licenses/LICENSE-2.0  | 
 | 9 | + *  | 
 | 10 | + * Unless required by applicable law or agreed to in writing, software  | 
 | 11 | + * distributed under the License is distributed on an "AS IS" BASIS,  | 
 | 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
 | 13 | + * See the License for the specific language governing permissions and  | 
 | 14 | + * limitations under the License.  | 
 | 15 | + */  | 
 | 16 | + | 
 | 17 | +package androidx.compose.material3  | 
 | 18 | + | 
 | 19 | +import androidx.compose.foundation.layout.ColumnScope  | 
 | 20 | +import androidx.compose.foundation.layout.PaddingValues  | 
 | 21 | +import androidx.compose.foundation.layout.WindowInsets  | 
 | 22 | +import androidx.compose.material3.SheetValue.Expanded  | 
 | 23 | +import androidx.compose.material3.SheetValue.Hidden  | 
 | 24 | +import androidx.compose.runtime.Composable  | 
 | 25 | +import androidx.compose.runtime.remember  | 
 | 26 | +import androidx.compose.ui.Modifier  | 
 | 27 | +import androidx.compose.ui.graphics.Color  | 
 | 28 | +import androidx.compose.ui.graphics.Shape  | 
 | 29 | +import androidx.compose.ui.unit.Dp  | 
 | 30 | + | 
 | 31 | + | 
 | 32 | +/**  | 
 | 33 | + * <a href="https://m3.material.io/components/bottom-sheets/overview" class="external" target="_blank">Material Design modal bottom sheet</a>.  | 
 | 34 | + *  | 
 | 35 | + * Modal bottom sheets are used as an alternative to inline menus or simple dialogs on mobile,  | 
 | 36 | + * especially when offering a long list of action items, or when items require longer descriptions  | 
 | 37 | + * and icons. Like dialogs, modal bottom sheets appear in front of app content, disabling all other  | 
 | 38 | + * app functionality when they appear, and remaining on screen until confirmed, dismissed, or a  | 
 | 39 | + * required action has been taken.  | 
 | 40 | + *  | 
 | 41 | + *   | 
 | 42 | + *  | 
 | 43 | + * A simple example of a modal bottom sheet looks like this:  | 
 | 44 | + *  | 
 | 45 | + * @sample androidx.compose.material3.samples.ModalBottomSheetSample  | 
 | 46 | + *  | 
 | 47 | + * @param onDismissRequest Executes when the user clicks outside of the bottom sheet, after sheet  | 
 | 48 | + * animates to [Hidden].  | 
 | 49 | + * @param modifier Optional [Modifier] for the bottom sheet.  | 
 | 50 | + * @param sheetState The state of the bottom sheet.  | 
 | 51 | + * @param shape The shape of the bottom sheet.  | 
 | 52 | + * @param containerColor The color used for the background of this bottom sheet  | 
 | 53 | + * @param contentColor The preferred color for content inside this bottom sheet. Defaults to either  | 
 | 54 | + * the matching content color for [containerColor], or to the current [LocalContentColor] if  | 
 | 55 | + * [containerColor] is not a color from the theme.  | 
 | 56 | + * @param tonalElevation The tonal elevation of this bottom sheet.  | 
 | 57 | + * @param scrimColor Color of the scrim that obscures content when the bottom sheet is open.  | 
 | 58 | + * @param dragHandle Optional visual marker to swipe the bottom sheet.  | 
 | 59 | + * @param windowInsets window insets to be passed to the bottom sheet window via [PaddingValues]  | 
 | 60 | + * params.  | 
 | 61 | + * @param content The content to be displayed inside the bottom sheet.  | 
 | 62 | + */  | 
 | 63 | +@Composable  | 
 | 64 | +@ExperimentalMaterial3Api  | 
 | 65 | +expect fun ModalBottomSheet(  | 
 | 66 | + onDismissRequest: () -> Unit,  | 
 | 67 | + modifier: Modifier = Modifier,  | 
 | 68 | + sheetState: SheetState = rememberModalBottomSheetState(),  | 
 | 69 | + shape: Shape = BottomSheetDefaults.ExpandedShape,  | 
 | 70 | + containerColor: Color = BottomSheetDefaults.ContainerColor,  | 
 | 71 | + contentColor: Color = contentColorFor(containerColor),  | 
 | 72 | + tonalElevation: Dp = BottomSheetDefaults.Elevation,  | 
 | 73 | + scrimColor: Color = BottomSheetDefaults.ScrimColor,  | 
 | 74 | + dragHandle: @Composable (() -> Unit)? = { BottomSheetDefaults.DragHandle() },  | 
 | 75 | + windowInsets: WindowInsets = BottomSheetDefaults.windowInsets,  | 
 | 76 | + content: @Composable ColumnScope.() -> Unit,  | 
 | 77 | +)  | 
 | 78 | + | 
 | 79 | +/**  | 
 | 80 | + * Create and [remember] a [SheetState] for [ModalBottomSheet].  | 
 | 81 | + *  | 
 | 82 | + * @param skipPartiallyExpanded Whether the partially expanded state, if the sheet is tall enough,  | 
 | 83 | + * should be skipped. If true, the sheet will always expand to the [Expanded] state and move to the  | 
 | 84 | + * [Hidden] state when hiding the sheet, either programmatically or by user interaction.  | 
 | 85 | + * @param confirmValueChange Optional callback invoked to confirm or veto a pending state change.  | 
 | 86 | + */  | 
 | 87 | +@Composable  | 
 | 88 | +@ExperimentalMaterial3Api  | 
 | 89 | +fun rememberModalBottomSheetState(  | 
 | 90 | + skipPartiallyExpanded: Boolean = false,  | 
 | 91 | + confirmValueChange: (SheetValue) -> Boolean = { true },  | 
 | 92 | +) = rememberSheetState(skipPartiallyExpanded, confirmValueChange, Hidden)  | 
0 commit comments