|
| 1 | +/* |
| 2 | + * Copyright 2024 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 | + * https://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 com.example.compose.snippets.components |
| 18 | + |
| 19 | +import androidx.compose.foundation.layout.Column |
| 20 | +import androidx.compose.foundation.layout.fillMaxHeight |
| 21 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 22 | +import androidx.compose.foundation.layout.padding |
| 23 | +import androidx.compose.material3.Button |
| 24 | +import androidx.compose.material3.ExperimentalMaterial3Api |
| 25 | +import androidx.compose.material3.ModalBottomSheet |
| 26 | +import androidx.compose.material3.Text |
| 27 | +import androidx.compose.material3.rememberModalBottomSheetState |
| 28 | +import androidx.compose.runtime.Composable |
| 29 | +import androidx.compose.runtime.getValue |
| 30 | +import androidx.compose.runtime.mutableStateOf |
| 31 | +import androidx.compose.runtime.remember |
| 32 | +import androidx.compose.runtime.setValue |
| 33 | +import androidx.compose.ui.Alignment |
| 34 | +import androidx.compose.ui.Modifier |
| 35 | +import androidx.compose.ui.tooling.preview.Preview |
| 36 | +import androidx.compose.ui.unit.dp |
| 37 | + |
| 38 | +@OptIn(ExperimentalMaterial3Api::class) |
| 39 | +@Preview |
| 40 | +// [START android_compose_components_partialbottomsheet] |
| 41 | +@Composable |
| 42 | +fun PartialBottomSheet() { |
| 43 | + var showBottomSheet by remember { mutableStateOf(false) } |
| 44 | + val sheetState = rememberModalBottomSheetState( |
| 45 | + skipPartiallyExpanded = false, |
| 46 | + ) |
| 47 | + |
| 48 | + Column( |
| 49 | + modifier = Modifier.fillMaxWidth(), |
| 50 | + horizontalAlignment = Alignment.CenterHorizontally, |
| 51 | + ) { |
| 52 | + Button( |
| 53 | + onClick = { showBottomSheet = true } |
| 54 | + ) { |
| 55 | + Text("Display partial bottom sheet") |
| 56 | + } |
| 57 | + |
| 58 | + if (showBottomSheet) { |
| 59 | + ModalBottomSheet( |
| 60 | + modifier = Modifier.fillMaxHeight(), |
| 61 | + sheetState = sheetState, |
| 62 | + onDismissRequest = { showBottomSheet = false } |
| 63 | + ) { |
| 64 | + Text( |
| 65 | + "Swipe up to open sheet. Swipe down to dismiss.", |
| 66 | + modifier = Modifier.padding(16.dp) |
| 67 | + ) |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | +// [END android_compose_components_partialbottomsheet] |
0 commit comments