|
| 1 | +# Sheets |
| 2 | + |
| 3 | +Another BottomSheet in Jetpack Compose. |
| 4 | + |
| 5 | +<a href="images/screenshot_simple.png"><img src="images/screenshot_simple.png" width="32%"/></a> |
| 6 | +<a href="images/screenshot_list.png"><img src="images/screenshot_list.png" width="32%"/></a> |
| 7 | +<a href="images/screenshot_intent-picker.png"><img src="images/screenshot_intent-picker.png" width="32%"/></a> |
| 8 | + |
| 9 | +**Features**: |
| 10 | + |
| 11 | + |
| 12 | +- Independent. Unlike [`ModalBottomSheetLayout`](https://developer.android.com/reference/kotlin/androidx/compose/material/package-summary#ModalBottomSheetLayout(kotlin.Function1,androidx.compose.ui.Modifier,androidx.compose.material.ModalBottomSheetState,androidx.compose.ui.graphics.Shape,androidx.compose.ui.unit.Dp,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,kotlin.Function0)) , this bottom sheet will be displayed in a dialog window, which means we can easily create and display multiple sheets in the same composable: |
| 13 | + |
| 14 | + ```kotlin |
| 15 | + @Composable |
| 16 | + fun MyComposable() { |
| 17 | + val scope = rememberCoroutineScope() |
| 18 | + |
| 19 | + val sheet1 = rememberBottomSheetState() |
| 20 | + val sheet2 = rememberBottomSheetState() |
| 21 | + |
| 22 | + Column { |
| 23 | + Button(onClick = { scope.launch { sheet1.expand() } }) { |
| 24 | + Text("Sheet 1") |
| 25 | + } |
| 26 | + |
| 27 | + Button(onClick = { scope.launch { sheet2.expand() } }) { |
| 28 | + Text("Sheet 2") |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + BottomSheet(state = sheet1) { ... } |
| 33 | + BottomSheet(state = sheet2) { ... } |
| 34 | + } |
| 35 | + ``` |
| 36 | + |
| 37 | + |
| 38 | +- Peek state support: |
| 39 | + |
| 40 | + ```kotlin |
| 41 | + val state = rememberBottomSheetState() |
| 42 | + |
| 43 | + BottomSheet( |
| 44 | + state = state, |
| 45 | + /* |
| 46 | + * PeekHeight.px(Int) and PeekHeight.fraction(Float) are supported as well. |
| 47 | + */ |
| 48 | + peekHeight = PeekHeight.dp(300), |
| 49 | + ) { |
| 50 | + ... |
| 51 | + } |
| 52 | + |
| 53 | + state.peek() |
| 54 | + ``` |
| 55 | + |
| 56 | + |
| 57 | +- Customizable animation spec: |
| 58 | + |
| 59 | + ```kotlin |
| 60 | + val state = rememberBottomSheetState() |
| 61 | + |
| 62 | + state.expand(animationSpec = spring()) |
| 63 | + ``` |
| 64 | + |
| 65 | +# Quick start |
| 66 | + |
| 67 | +Add the dependency [](https://maven-badges.herokuapp.com/maven-central/io.github.dokar3/sheets): |
| 68 | + |
| 69 | +```groovy |
| 70 | +implementation "io.github.dokar3.sheets:sheets:latest_version" |
| 71 | +``` |
| 72 | + |
| 73 | +**Basic** |
| 74 | + |
| 75 | +```kotlin |
| 76 | +val scope = rememberCoroutineScope() |
| 77 | +val state = rememberBottomSheetState() |
| 78 | + |
| 79 | +Button(onClick = { scope.launch { state.expand() } }) { |
| 80 | + Text("Show bottom sheet") |
| 81 | +} |
| 82 | + |
| 83 | +BottomSheet(state = state) { |
| 84 | + Text("Sheet content") |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +**Skip peek state** |
| 89 | + |
| 90 | +To skip peek state, set `peekHeight` to a value at least equal to the content height, eg. `PeekHeight.px(Int.MAX_VALUE)`, `PeekHeight.fraction(1f)`: |
| 91 | + |
| 92 | +```kotlin |
| 93 | +BottomSheet( |
| 94 | + state = state, |
| 95 | + peekHeight = PeekHeight.fraction(1f), |
| 96 | +) { |
| 97 | + ... |
| 98 | +} |
| 99 | +``` |
| 100 | + |
| 101 | +**Embedded sheet** |
| 102 | + |
| 103 | +To embed the sheet in the current layout hierarchy, use the `BottomSheetLayout()`: |
| 104 | + |
| 105 | +```kotlin |
| 106 | +Box { |
| 107 | + OtherContent() |
| 108 | + |
| 109 | + val state = rememberBottomSheetState() |
| 110 | + if (state.visible) { |
| 111 | + BottomSheetLayout(state = state) { |
| 112 | + ... |
| 113 | + } |
| 114 | + } |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +# License |
| 119 | + |
| 120 | +``` |
| 121 | +Copyright 2022 dokar3 |
| 122 | +
|
| 123 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 124 | +you may not use this file except in compliance with the License. |
| 125 | +You may obtain a copy of the License at |
| 126 | +
|
| 127 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 128 | +
|
| 129 | +Unless required by applicable law or agreed to in writing, software |
| 130 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 131 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 132 | +See the License for the specific language governing permissions and |
| 133 | +limitations under the License. |
| 134 | +``` |
0 commit comments