@@ -2,6 +2,7 @@ package com.gravatar.quickeditor.ui.editor.bottomsheet
22
33import android.content.res.Configuration
44import android.graphics.Color
5+ import android.util.Log
56import androidx.compose.foundation.background
67import androidx.compose.foundation.isSystemInDarkTheme
78import androidx.compose.foundation.layout.Box
@@ -57,6 +58,8 @@ import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorDismissReason
5758import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorPage
5859import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorParams
5960import com.gravatar.quickeditor.ui.editor.GravatarUiMode
61+ import com.gravatar.quickeditor.ui.editor.QuickEditorPage
62+ import com.gravatar.quickeditor.ui.editor.QuickEditorScopeOption
6063import com.gravatar.quickeditor.ui.editor.UpdateHandler
6164import com.gravatar.ui.GravatarTheme
6265import com.gravatar.ui.LocalGravatarTheme
@@ -87,7 +90,7 @@ public fun GravatarQuickEditorBottomSheet(
8790 authenticationMethod = authenticationMethod,
8891 updateHandler = updateHandler,
8992 onDismiss = onDismiss,
90- modalDetents = gravatarQuickEditorParams.scopeOption.avatarPickerContentLayout. modalDetents(),
93+ modalDetents = gravatarQuickEditorParams.scopeOption.modalDetents(),
9194 )
9295}
9396
@@ -123,7 +126,7 @@ public fun GravatarQuickEditorBottomSheet(
123126 }
124127 },
125128 onDismiss = onDismiss,
126- modalDetents = gravatarQuickEditorParams.scopeOption.avatarPickerContentLayout. modalDetents(),
129+ modalDetents = gravatarQuickEditorParams.scopeOption.modalDetents(),
127130 )
128131}
129132
@@ -177,6 +180,7 @@ internal fun GravatarQuickEditorBottomSheet(
177180 }
178181
179182 LaunchedEffect (modalBottomSheetState.currentDetent) {
183+ Log .d(" QuickEditor" , " Current detent: ${modalBottomSheetState.currentDetent.identifier} " )
180184 onCurrentDetentChanged(modalBottomSheetState.currentDetent)
181185 }
182186
@@ -316,34 +320,63 @@ private fun GravatarModalBottomSheet(
316320 }
317321}
318322
323+ private val peek = SheetDetent (identifier = " peek" ) { containerHeight, _ ->
324+ containerHeight * 0.6f
325+ }
326+
319327@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 {
324329 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- }
333330
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 )
339346 add(peek)
340347 add(FullyExpanded )
341348 }
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+ }
342379 }
343- return ModalDetents (
344- initialDetent = initialDetent,
345- detents = detents,
346- )
347380}
348381
349382internal data class ModalDetents (
0 commit comments