@@ -4,7 +4,9 @@ import android.content.res.Configuration
4
4
import android.graphics.Color
5
5
import androidx.compose.foundation.background
6
6
import androidx.compose.foundation.isSystemInDarkTheme
7
+ import androidx.compose.foundation.layout.Box
7
8
import androidx.compose.foundation.layout.Column
9
+ import androidx.compose.foundation.layout.PaddingValues
8
10
import androidx.compose.foundation.layout.WindowInsets
9
11
import androidx.compose.foundation.layout.WindowInsetsSides
10
12
import androidx.compose.foundation.layout.asPaddingValues
@@ -13,6 +15,7 @@ import androidx.compose.foundation.layout.imePadding
13
15
import androidx.compose.foundation.layout.navigationBars
14
16
import androidx.compose.foundation.layout.only
15
17
import androidx.compose.foundation.layout.padding
18
+ import androidx.compose.foundation.layout.statusBars
16
19
import androidx.compose.foundation.layout.widthIn
17
20
import androidx.compose.foundation.shape.RoundedCornerShape
18
21
import androidx.compose.material3.MaterialTheme
@@ -54,6 +57,8 @@ import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorDismissReason
54
57
import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorPage
55
58
import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorParams
56
59
import com.gravatar.quickeditor.ui.editor.GravatarUiMode
60
+ import com.gravatar.quickeditor.ui.editor.QuickEditorPage
61
+ import com.gravatar.quickeditor.ui.editor.QuickEditorScopeOption
57
62
import com.gravatar.quickeditor.ui.editor.UpdateHandler
58
63
import com.gravatar.ui.GravatarTheme
59
64
import com.gravatar.ui.LocalGravatarTheme
@@ -84,7 +89,7 @@ public fun GravatarQuickEditorBottomSheet(
84
89
authenticationMethod = authenticationMethod,
85
90
updateHandler = updateHandler,
86
91
onDismiss = onDismiss,
87
- modalDetents = gravatarQuickEditorParams.scopeOption.avatarPickerContentLayout. modalDetents(),
92
+ modalDetents = gravatarQuickEditorParams.scopeOption.modalDetents(),
88
93
)
89
94
}
90
95
@@ -120,7 +125,7 @@ public fun GravatarQuickEditorBottomSheet(
120
125
}
121
126
},
122
127
onDismiss = onDismiss,
123
- modalDetents = gravatarQuickEditorParams.scopeOption.avatarPickerContentLayout. modalDetents(),
128
+ modalDetents = gravatarQuickEditorParams.scopeOption.modalDetents(),
124
129
)
125
130
}
126
131
@@ -261,36 +266,49 @@ private fun GravatarModalBottomSheet(
261
266
Scrim (
262
267
scrimColor = MaterialTheme .colorScheme.scrim.copy(alpha = 0.32f ),
263
268
)
264
- Sheet (
269
+ Box (
265
270
modifier = Modifier
266
- .imePadding()
267
- .clip(RoundedCornerShape (topStart = 28 .dp, topEnd = 28 .dp))
268
- .background(MaterialTheme .colorScheme.surfaceColorAtElevation(1 .dp))
269
- .widthIn(max = 640 .dp)
270
- .fillMaxWidth()
271
271
.padding(
272
- WindowInsets .navigationBars
273
- .only(WindowInsetsSides .Vertical )
274
- .asPaddingValues(),
272
+ paddingValues = if (configuration.orientation == Configuration .ORIENTATION_LANDSCAPE ) {
273
+ PaddingValues (0 .dp)
274
+ } else {
275
+ WindowInsets .statusBars
276
+ .only(WindowInsetsSides .Top )
277
+ .asPaddingValues()
278
+ },
275
279
),
276
280
) {
277
- val window = LocalModalWindow .current
278
- val isDarkTheme = isSystemInDarkTheme()
279
- LaunchedEffect (Unit ) {
280
- window.navigationBarColor = Color .TRANSPARENT
281
- WindowInsetsControllerCompat (window, window.decorView).isAppearanceLightNavigationBars =
282
- ! isDarkTheme
283
- }
284
- Surface (
281
+ Sheet (
285
282
modifier = Modifier
286
- .fillMaxWidth(),
287
- tonalElevation = 1 .dp,
283
+ .imePadding()
284
+ .clip(RoundedCornerShape (topStart = 28 .dp, topEnd = 28 .dp))
285
+ .background(MaterialTheme .colorScheme.surfaceColorAtElevation(1 .dp))
286
+ .widthIn(max = 640 .dp)
287
+ .fillMaxWidth()
288
+ .padding(
289
+ WindowInsets .navigationBars
290
+ .only(WindowInsetsSides .Vertical )
291
+ .asPaddingValues(),
292
+ ),
288
293
) {
289
- Column (
290
- horizontalAlignment = Alignment .CenterHorizontally ,
294
+ val window = LocalModalWindow .current
295
+ val isDarkTheme = isSystemInDarkTheme()
296
+ LaunchedEffect (Unit ) {
297
+ window.navigationBarColor = Color .TRANSPARENT
298
+ WindowInsetsControllerCompat (window, window.decorView).isAppearanceLightNavigationBars =
299
+ ! isDarkTheme
300
+ }
301
+ Surface (
302
+ modifier = Modifier
303
+ .fillMaxWidth(),
304
+ tonalElevation = 1 .dp,
291
305
) {
292
- QEDragHandle ()
293
- content()
306
+ Column (
307
+ horizontalAlignment = Alignment .CenterHorizontally ,
308
+ ) {
309
+ QEDragHandle ()
310
+ content()
311
+ }
294
312
}
295
313
}
296
314
}
@@ -300,35 +318,63 @@ private fun GravatarModalBottomSheet(
300
318
}
301
319
}
302
320
303
- internal val peek = SheetDetent (identifier = " peek" ) { containerHeight, _ ->
321
+ private val peek = SheetDetent (identifier = " peek" ) { containerHeight, _ ->
304
322
containerHeight * 0.6f
305
323
}
306
324
307
325
@Composable
308
- internal fun AvatarPickerContentLayout .modalDetents (): ModalDetents {
326
+ internal fun QuickEditorScopeOption .modalDetents (): ModalDetents {
309
327
val windowHeightSizeClass = currentWindowAdaptiveInfo().windowSizeClass.windowHeightSizeClass
310
- val initialDetent = if (windowHeightSizeClass == WindowHeightSizeClass .COMPACT ) {
311
- FullyExpanded
312
- } else {
313
- when (this ) {
314
- AvatarPickerContentLayout .Horizontal -> FullyExpanded
315
- AvatarPickerContentLayout .Vertical -> peek
316
- }
317
- }
318
328
319
- val detents = buildList {
320
- add(Hidden )
321
- if (this @modalDetents == AvatarPickerContentLayout .Horizontal ) {
322
- add(FullyExpanded )
323
- } else {
329
+ val detents = buildDetentsList()
330
+ val initialDetent = initialDetent(windowHeightSizeClass)
331
+
332
+ return ModalDetents (
333
+ initialDetent = if (detents.contains(initialDetent)) initialDetent else detents.last(),
334
+ detents = detents,
335
+ )
336
+ }
337
+
338
+ private fun QuickEditorScopeOption.buildDetentsList (): List <SheetDetent > {
339
+ return when (this .scope) {
340
+ is QuickEditorScopeOption .Scope .AvatarPickerAndAboutEditor ,
341
+ is QuickEditorScopeOption .Scope .AboutEditor ,
342
+ -> buildList {
343
+ add(Hidden )
324
344
add(peek)
325
345
add(FullyExpanded )
326
346
}
347
+
348
+ is QuickEditorScopeOption .Scope .AvatarPicker -> buildList {
349
+ add(Hidden )
350
+ if (avatarPickerContentLayout == AvatarPickerContentLayout .Vertical ) {
351
+ add(peek)
352
+ }
353
+ add(FullyExpanded )
354
+ }
355
+ }
356
+ }
357
+
358
+ private fun QuickEditorScopeOption.initialDetent (windowHeightSizeClass : WindowHeightSizeClass ): SheetDetent {
359
+ return if (windowHeightSizeClass == WindowHeightSizeClass .COMPACT ) {
360
+ FullyExpanded
361
+ } else {
362
+ when (this .scope) {
363
+ is QuickEditorScopeOption .Scope .AboutEditor -> peek
364
+ is QuickEditorScopeOption .Scope .AvatarPickerAndAboutEditor ,
365
+ is QuickEditorScopeOption .Scope .AvatarPicker ,
366
+ -> {
367
+ if (
368
+ this .avatarPickerContentLayout == AvatarPickerContentLayout .Horizontal &&
369
+ this .initialPage == QuickEditorPage .AvatarPicker
370
+ ) {
371
+ FullyExpanded
372
+ } else {
373
+ peek
374
+ }
375
+ }
376
+ }
327
377
}
328
- return ModalDetents (
329
- initialDetent = initialDetent,
330
- detents = detents,
331
- )
332
378
}
333
379
334
380
internal data class ModalDetents (
0 commit comments