Skip to content

Commit dacb127

Browse files
Update sheet detens/initial detent with new Scopes
1 parent ddd5f6b commit dacb127

File tree

5 files changed

+69
-35
lines changed

5 files changed

+69
-35
lines changed

gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/abouteditor/AboutEditor.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ internal fun AboutEditor(
106106
}
107107

108108
Surface {
109-
Box(modifier = Modifier
110-
.wrapContentSize()
111-
.animateContentSize()
109+
Box(
110+
modifier = Modifier
111+
.wrapContentSize()
112+
.animateContentSize(),
112113
) {
113114
AboutEditor(
114115
uiState = uiState,

gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/editor/QuickEditorScopeOption.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ public class QuickEditorScopeOption private constructor(
4747
is Scope.AvatarPicker -> AboutInputField.all
4848
}
4949

50+
internal val initialPage: QuickEditorPage
51+
get() = when (scope) {
52+
is Scope.AvatarPicker -> QuickEditorPage.AvatarPicker
53+
is Scope.AboutEditor -> QuickEditorPage.AboutEditor
54+
is Scope.AvatarPickerAndAboutEditor -> scope.config.initialPage.internalType
55+
}
56+
5057
public companion object {
5158
internal val default = QuickEditorScopeOption(
5259
scope = Scope.AvatarPicker(AvatarPickerConfiguration.default),

gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/editor/QuickEditorViewModel.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,7 @@ internal class QuickEditorViewModelFactory(
121121
}
122122
}
123123

124-
private val QuickEditorScopeOption.initialPage: QuickEditorPage
125-
get() = when (scope) {
126-
is Scope.AvatarPicker -> QuickEditorPage.AvatarPicker
127-
is Scope.AboutEditor -> QuickEditorPage.AboutEditor
128-
is Scope.AvatarPickerAndAboutEditor -> scope.config.initialPage.internalType
129-
}
130-
131-
private val AvatarPickerAndAboutEditorConfiguration.Page.internalType: QuickEditorPage
124+
internal val AvatarPickerAndAboutEditorConfiguration.Page.internalType: QuickEditorPage
132125
get() = when (this) {
133126
AvatarPicker -> QuickEditorPage.AvatarPicker
134127
AboutEditor -> QuickEditorPage.AboutEditor

gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/editor/bottomsheet/GravatarQuickEditorBottomSheet.kt

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.gravatar.quickeditor.ui.editor.bottomsheet
22

33
import android.content.res.Configuration
44
import android.graphics.Color
5+
import android.util.Log
56
import androidx.compose.foundation.background
67
import androidx.compose.foundation.isSystemInDarkTheme
78
import androidx.compose.foundation.layout.Box
@@ -57,6 +58,8 @@ import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorDismissReason
5758
import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorPage
5859
import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorParams
5960
import com.gravatar.quickeditor.ui.editor.GravatarUiMode
61+
import com.gravatar.quickeditor.ui.editor.QuickEditorPage
62+
import com.gravatar.quickeditor.ui.editor.QuickEditorScopeOption
6063
import com.gravatar.quickeditor.ui.editor.UpdateHandler
6164
import com.gravatar.ui.GravatarTheme
6265
import 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

349382
internal data class ModalDetents(

gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/editor/extensions/QuickEditorExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal fun addQuickEditorToView(
2525
authenticationMethod = authenticationMethod,
2626
updateHandler = updateHandler,
2727
onDismiss = onDismiss,
28-
modalDetents = gravatarQuickEditorParams.scopeOption.avatarPickerContentLayout.modalDetents(),
28+
modalDetents = gravatarQuickEditorParams.scopeOption.modalDetents(),
2929
onCurrentDetentChanged = {
3030
if (it == Hidden) {
3131
viewGroup.removeView(this)

0 commit comments

Comments
 (0)