Skip to content

Commit

Permalink
Remove padding in sheet demos because it is blocking clicks outside
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstyl committed Feb 23, 2025
1 parent 1024c4d commit 3fe1eb0
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 73 deletions.
37 changes: 20 additions & 17 deletions demo-modalsheet/src/commonMain/kotlin/ModalBottomSheetDemo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,30 @@ fun ModalBottomSheetDemo() {
ModalBottomSheet(state = modalSheetState) {
Scrim(scrimColor = Color.Black.copy(0.3f), enter = fadeIn(), exit = fadeOut())

Sheet(
modifier = Modifier
Box(
Modifier.fillMaxSize()
.padding(top = 12.dp)
.let { if (isCompact) it else it.padding(horizontal = 56.dp) }
.displayCutoutPadding()
.statusBarsPadding()
.padding(WindowInsets.navigationBars.only(WindowInsetsSides.Horizontal).asPaddingValues())
.shadow(4.dp, RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp))
.clip(RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp))
.background(Color.White)
.widthIn(max = 640.dp)
.fillMaxWidth()
.imePadding(),
) {
Box(Modifier.fillMaxWidth().height(600.dp), contentAlignment = Alignment.TopCenter) {
DragIndication(
modifier = Modifier.padding(top = 22.dp)
.background(Color.Black.copy(0.4f), RoundedCornerShape(100))
.width(32.dp)
.height(4.dp)
)
.padding(WindowInsets.navigationBars.only(WindowInsetsSides.Horizontal).asPaddingValues())) {
Sheet(
modifier = Modifier
.shadow(4.dp, RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp))
.clip(RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp))
.background(Color.White)
.widthIn(max = 640.dp)
.fillMaxWidth()
.imePadding(),
) {
Box(Modifier.fillMaxWidth().height(600.dp), contentAlignment = Alignment.TopCenter) {
DragIndication(
modifier = Modifier.padding(top = 22.dp)
.background(Color.Black.copy(0.4f), RoundedCornerShape(100))
.width(32.dp)
.height(4.dp)
)
}
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions demo-sheet/src/commonMain/kotlin/BottomSheetDemo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ private val Peek = SheetDetent("peek") { containerHeight, sheetHeight ->

@Composable
fun BottomSheetDemo() {
BoxWithConstraints(
Box(
modifier = Modifier
.fillMaxSize()
.background(Brush.linearGradient(listOf(Color(0xFF800080), Color(0xFFDA70D6)))),
.background(Brush.linearGradient(listOf(Color(0xFF800080), Color(0xFFDA70D6))))
.padding(top = 12.dp)
.statusBarsPadding()
.padding(WindowInsets.navigationBars.only(WindowInsetsSides.Horizontal).asPaddingValues()),
) {
val isCompact = maxWidth < 600.dp

val sheetState = rememberBottomSheetState(
initialDetent = Peek,
detents = listOf(Hidden, Peek, FullyExpanded)
Expand All @@ -70,10 +71,6 @@ fun BottomSheetDemo() {
BottomSheet(
state = sheetState,
modifier = Modifier
.padding(top = 12.dp)
.let { if (isCompact) it else it.padding(horizontal = 56.dp) }
.statusBarsPadding()
.padding(WindowInsets.navigationBars.only(WindowInsetsSides.Horizontal).asPaddingValues())
.shadow(4.dp, RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp))
.clip(RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp))
.background(Color.White)
Expand Down
1 change: 0 additions & 1 deletion docs/bottom-sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ val sheetState = rememberBottomSheetState(
BottomSheet(
state = sheetState,
modifier = Modifier
.padding(top = 12.dp)
.shadow(4.dp, RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp))
.clip(RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp))
.background(Color.White)
Expand Down
95 changes: 48 additions & 47 deletions docs/modal-bottom-sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ val sheetState = rememberModalBottomSheetState(
ModalBottomSheet(state = sheetState) {
Sheet(
modifier = Modifier
.padding(top = 12.dp)
.shadow(4.dp, RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp))
.clip(RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp))
.background(Color.White)
Expand Down Expand Up @@ -231,20 +230,21 @@ val sheetState = rememberModalBottomSheetState(
)

ModalBottomSheet(state = sheetState) {
Sheet(
modifier = Modifier.fillMaxWidth()
.padding(
WindowInsets.navigationBars.only(WindowInsetsSides.Horizontal)
.asPaddingValues()
)
.navigationBarsPadding(),
) {
Column(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
Box(Modifier.padding(
// make sure the sheet is not behind nav bars on landscape
WindowInsets.navigationBars.only(WindowInsetsSides.Horizontal)
.asPaddingValues()
)) {
Sheet(
modifier = Modifier.fillMaxWidth().navigationBarsPadding(),
) {
DragIndication()
BasicText("Here is some content")
Column(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
) {
DragIndication()
BasicText("Here is some content")
}
}
}
}
Expand All @@ -262,45 +262,46 @@ val sheetState = rememberModalBottomSheetState(
initialDetent = FullyExpanded,
)
ModalBottomSheet(state = sheetState) {
Sheet(
modifier = Modifier.fillMaxWidth()
.padding(
// make sure the sheet is not behind nav bars on landscape
WindowInsets.navigationBars.only(WindowInsetsSides.Horizontal)
.asPaddingValues()
)
.background(Color.White),
) {
Column(
Box(Modifier.padding(
// make sure the sheet is not behind nav bars on landscape
WindowInsets.navigationBars.only(WindowInsetsSides.Horizontal)
.asPaddingValues()
)) {
Sheet(
modifier = Modifier.fillMaxWidth()
.padding(16.dp)
// make sure the contents of the sheet is always above the nav bar
.navigationBarsPadding()
// draw the contents above the soft keyboard
.imePadding()
.background(Color.White),
) {
DragIndication(Modifier.align(Alignment.CenterHorizontally))

var text by remember { mutableStateOf("") }
BasicTextField(
value = text,
onValueChange = { text = it },
Column(
modifier = Modifier.fillMaxWidth()
)
Box(Modifier
.clip(RoundedCornerShape(4.dp))
.background(Color.Blue)
.clickable { /* TODO */ }
.padding(4.dp)
.align(Alignment.End)) {
BasicText(
text = "Save note",
style = TextStyle.Default.copy(color = Color.White)
.padding(16.dp)
// make sure the contents of the sheet is always above the nav bar
.navigationBarsPadding()
// draw the contents above the soft keyboard
.imePadding()
) {
DragIndication(Modifier.align(Alignment.CenterHorizontally))

var text by remember { mutableStateOf("") }
BasicTextField(
value = text,
onValueChange = { text = it },
modifier = Modifier.fillMaxWidth()
)
Box(
Modifier
.clip(RoundedCornerShape(4.dp))
.background(Color.Blue)
.clickable { /* TODO */ }
.padding(4.dp)
.align(Alignment.End)) {
BasicText(
text = "Save note",
style = TextStyle.Default.copy(color = Color.White)
)
}
}
}
}
}
}}
```

### Scrollable sheets
Expand Down

0 comments on commit 3fe1eb0

Please sign in to comment.