@@ -2,6 +2,7 @@ package com.gravatar.quickeditor.ui.editor.bottomsheet
2
2
3
3
import android.content.res.Configuration
4
4
import android.graphics.Color
5
+ import android.util.Log
5
6
import androidx.compose.foundation.background
6
7
import androidx.compose.foundation.isSystemInDarkTheme
7
8
import androidx.compose.foundation.layout.Box
@@ -57,6 +58,8 @@ import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorDismissReason
57
58
import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorPage
58
59
import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorParams
59
60
import com.gravatar.quickeditor.ui.editor.GravatarUiMode
61
+ import com.gravatar.quickeditor.ui.editor.QuickEditorPage
62
+ import com.gravatar.quickeditor.ui.editor.QuickEditorScopeOption
60
63
import com.gravatar.quickeditor.ui.editor.UpdateHandler
61
64
import com.gravatar.ui.GravatarTheme
62
65
import com.gravatar.ui.LocalGravatarTheme
@@ -87,7 +90,7 @@ public fun GravatarQuickEditorBottomSheet(
87
90
authenticationMethod = authenticationMethod,
88
91
updateHandler = updateHandler,
89
92
onDismiss = onDismiss,
90
- modalDetents = gravatarQuickEditorParams.scopeOption.avatarPickerContentLayout. modalDetents(),
93
+ modalDetents = gravatarQuickEditorParams.scopeOption.modalDetents(),
91
94
)
92
95
}
93
96
@@ -123,7 +126,7 @@ public fun GravatarQuickEditorBottomSheet(
123
126
}
124
127
},
125
128
onDismiss = onDismiss,
126
- modalDetents = gravatarQuickEditorParams.scopeOption.avatarPickerContentLayout. modalDetents(),
129
+ modalDetents = gravatarQuickEditorParams.scopeOption.modalDetents(),
127
130
)
128
131
}
129
132
@@ -177,6 +180,7 @@ internal fun GravatarQuickEditorBottomSheet(
177
180
}
178
181
179
182
LaunchedEffect (modalBottomSheetState.currentDetent) {
183
+ Log .d(" QuickEditor" , " Current detent: ${modalBottomSheetState.currentDetent.identifier} " )
180
184
onCurrentDetentChanged(modalBottomSheetState.currentDetent)
181
185
}
182
186
@@ -316,34 +320,63 @@ private fun GravatarModalBottomSheet(
316
320
}
317
321
}
318
322
323
+ private val peek = SheetDetent (identifier = " peek" ) { containerHeight, _ ->
324
+ containerHeight * 0.6f
325
+ }
326
+
319
327
@Composable
320
- internal fun AvatarPickerContentLayout.modalDetents (): ModalDetents {
321
- val peek = SheetDetent (identifier = " peek" ) { containerHeight, sheetHeight ->
322
- containerHeight * 0.6f
323
- }
328
+ internal fun QuickEditorScopeOption.modalDetents (): ModalDetents {
324
329
val windowHeightSizeClass = currentWindowAdaptiveInfo().windowSizeClass.windowHeightSizeClass
325
- val initialDetent = if (windowHeightSizeClass == WindowHeightSizeClass .COMPACT ) {
326
- FullyExpanded
327
- } else {
328
- when (this ) {
329
- AvatarPickerContentLayout .Horizontal -> FullyExpanded
330
- AvatarPickerContentLayout .Vertical -> peek
331
- }
332
- }
333
330
334
- val detents = buildList {
335
- add(Hidden )
336
- if (this @modalDetents == AvatarPickerContentLayout .Horizontal ) {
337
- add(FullyExpanded )
338
- } else {
331
+ val detents = buildDetentsList()
332
+ val initialDetent = initialDetent(windowHeightSizeClass)
333
+
334
+ return ModalDetents (
335
+ initialDetent = if (detents.contains(initialDetent)) initialDetent else detents.last(),
336
+ detents = detents,
337
+ )
338
+ }
339
+
340
+ private fun QuickEditorScopeOption.buildDetentsList (): List <SheetDetent > {
341
+ return when (this .scope) {
342
+ is QuickEditorScopeOption .Scope .AvatarPickerAndAboutEditor ,
343
+ is QuickEditorScopeOption .Scope .AboutEditor ,
344
+ -> buildList {
345
+ add(Hidden )
339
346
add(peek)
340
347
add(FullyExpanded )
341
348
}
349
+
350
+ is QuickEditorScopeOption .Scope .AvatarPicker -> buildList {
351
+ add(Hidden )
352
+ if (avatarPickerContentLayout == AvatarPickerContentLayout .Vertical ) {
353
+ add(peek)
354
+ }
355
+ add(FullyExpanded )
356
+ }
357
+ }
358
+ }
359
+
360
+ private fun QuickEditorScopeOption.initialDetent (windowHeightSizeClass : WindowHeightSizeClass ): SheetDetent {
361
+ return if (windowHeightSizeClass == WindowHeightSizeClass .COMPACT ) {
362
+ FullyExpanded
363
+ } else {
364
+ when (this .scope) {
365
+ is QuickEditorScopeOption .Scope .AboutEditor -> peek
366
+ is QuickEditorScopeOption .Scope .AvatarPickerAndAboutEditor ,
367
+ is QuickEditorScopeOption .Scope .AvatarPicker ,
368
+ -> {
369
+ if (
370
+ this .avatarPickerContentLayout == AvatarPickerContentLayout .Horizontal &&
371
+ this .initialPage == QuickEditorPage .AvatarPicker
372
+ ) {
373
+ FullyExpanded
374
+ } else {
375
+ peek
376
+ }
377
+ }
378
+ }
342
379
}
343
- return ModalDetents (
344
- initialDetent = initialDetent,
345
- detents = detents,
346
- )
347
380
}
348
381
349
382
internal data class ModalDetents (
0 commit comments