Skip to content

Commit 14ab142

Browse files
committed
Expect ModalBottomSheet in common
1 parent fb7bb8b commit 14ab142

File tree

3 files changed

+440
-25
lines changed

3 files changed

+440
-25
lines changed

compose/material3/material3/src/androidMain/kotlin/androidx/compose/material3/ModalBottomSheet.android.kt

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,17 @@ import kotlinx.coroutines.launch
120120
*/
121121
@Composable
122122
@ExperimentalMaterial3Api
123-
fun ModalBottomSheet(
123+
actual fun ModalBottomSheet(
124124
onDismissRequest: () -> Unit,
125-
modifier: Modifier = Modifier,
126-
sheetState: SheetState = rememberModalBottomSheetState(),
127-
shape: Shape = BottomSheetDefaults.ExpandedShape,
128-
containerColor: Color = BottomSheetDefaults.ContainerColor,
129-
contentColor: Color = contentColorFor(containerColor),
130-
tonalElevation: Dp = BottomSheetDefaults.Elevation,
131-
scrimColor: Color = BottomSheetDefaults.ScrimColor,
132-
dragHandle: @Composable (() -> Unit)? = { BottomSheetDefaults.DragHandle() },
133-
windowInsets: WindowInsets = BottomSheetDefaults.windowInsets,
125+
modifier: Modifier,
126+
sheetState: SheetState,
127+
shape: Shape,
128+
containerColor: Color,
129+
contentColor: Color,
130+
tonalElevation: Dp,
131+
scrimColor: Color,
132+
dragHandle: @Composable (() -> Unit)?,
133+
windowInsets: WindowInsets,
134134
content: @Composable ColumnScope.() -> Unit,
135135
) {
136136
val scope = rememberCoroutineScope()
@@ -303,21 +303,6 @@ fun ModalBottomSheet(
303303
content = content,
304304
)
305305

306-
/**
307-
* Create and [remember] a [SheetState] for [ModalBottomSheet].
308-
*
309-
* @param skipPartiallyExpanded Whether the partially expanded state, if the sheet is tall enough,
310-
* should be skipped. If true, the sheet will always expand to the [Expanded] state and move to the
311-
* [Hidden] state when hiding the sheet, either programmatically or by user interaction.
312-
* @param confirmValueChange Optional callback invoked to confirm or veto a pending state change.
313-
*/
314-
@Composable
315-
@ExperimentalMaterial3Api
316-
fun rememberModalBottomSheetState(
317-
skipPartiallyExpanded: Boolean = false,
318-
confirmValueChange: (SheetValue) -> Boolean = { true },
319-
) = rememberSheetState(skipPartiallyExpanded, confirmValueChange, Hidden)
320-
321306
@Composable
322307
private fun Scrim(
323308
color: Color,
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
* ![Bottom sheet image](https://developer.android.com/images/reference/androidx/compose/material3/bottom_sheet.png)
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

Comments
 (0)