Skip to content

Commit 1c411cb

Browse files
Remove Peek detent from the QuickEditor bottom sheet (#660)
* Remove Peek detent from the QuickEditor bottom sheet * Remove onFocus listener as we no longer need it
1 parent 12b52d1 commit 1c411cb

File tree

2 files changed

+10
-80
lines changed

2 files changed

+10
-80
lines changed

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

Lines changed: 9 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import androidx.compose.foundation.layout.widthIn
2020
import androidx.compose.foundation.shape.RoundedCornerShape
2121
import androidx.compose.material3.MaterialTheme
2222
import androidx.compose.material3.Surface
23-
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
2423
import androidx.compose.material3.surfaceColorAtElevation
2524
import androidx.compose.runtime.Composable
2625
import androidx.compose.runtime.CompositionLocalProvider
@@ -34,11 +33,9 @@ import androidx.compose.runtime.setValue
3433
import androidx.compose.ui.Alignment
3534
import androidx.compose.ui.Modifier
3635
import androidx.compose.ui.draw.clip
37-
import androidx.compose.ui.focus.onFocusChanged
3836
import androidx.compose.ui.platform.LocalConfiguration
3937
import androidx.compose.ui.unit.dp
4038
import androidx.core.view.WindowInsetsControllerCompat
41-
import androidx.window.core.layout.WindowHeightSizeClass
4239
import com.composables.core.ModalBottomSheet
4340
import com.composables.core.ModalBottomSheetState
4441
import com.composables.core.ModalSheetProperties
@@ -51,14 +48,11 @@ import com.composables.core.rememberModalBottomSheetState
5148
import com.composeunstyled.LocalModalWindow
5249
import com.gravatar.quickeditor.QuickEditorContainer
5350
import com.gravatar.quickeditor.ui.editor.AuthenticationMethod
54-
import com.gravatar.quickeditor.ui.editor.AvatarPickerContentLayout
5551
import com.gravatar.quickeditor.ui.editor.AvatarPickerResult
5652
import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorDismissReason
5753
import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorPage
5854
import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorParams
5955
import com.gravatar.quickeditor.ui.editor.GravatarUiMode
60-
import com.gravatar.quickeditor.ui.editor.QuickEditorPage
61-
import com.gravatar.quickeditor.ui.editor.QuickEditorScopeOption
6256
import com.gravatar.quickeditor.ui.editor.UpdateHandler
6357
import com.gravatar.ui.GravatarTheme
6458
import com.gravatar.ui.LocalGravatarTheme
@@ -89,7 +83,7 @@ public fun GravatarQuickEditorBottomSheet(
8983
authenticationMethod = authenticationMethod,
9084
updateHandler = updateHandler,
9185
onDismiss = onDismiss,
92-
modalDetents = gravatarQuickEditorParams.scopeOption.modalDetents(),
86+
modalDetents = modalDetents(),
9387
)
9488
}
9589

@@ -125,7 +119,7 @@ public fun GravatarQuickEditorBottomSheet(
125119
}
126120
},
127121
onDismiss = onDismiss,
128-
modalDetents = gravatarQuickEditorParams.scopeOption.modalDetents(),
122+
modalDetents = modalDetents(),
129123
)
130124
}
131125

@@ -242,17 +236,6 @@ private fun GravatarModalBottomSheet(
242236
modalBottomSheetState: ModalBottomSheetState,
243237
content: @Composable () -> Unit,
244238
) {
245-
val scope = rememberCoroutineScope()
246-
var hasFocus by remember { mutableStateOf(false) }
247-
248-
LaunchedEffect(hasFocus) {
249-
scope.launch {
250-
if (hasFocus) {
251-
modalBottomSheetState.animateTo(FullyExpanded)
252-
}
253-
}
254-
}
255-
256239
val configuration = Configuration(LocalConfiguration.current).apply {
257240
uiMode = when (colorScheme) {
258241
GravatarUiMode.LIGHT -> Configuration.UI_MODE_NIGHT_NO
@@ -313,9 +296,6 @@ private fun GravatarModalBottomSheet(
313296
}
314297
Surface(
315298
modifier = Modifier
316-
.onFocusChanged { state ->
317-
hasFocus = state.hasFocus
318-
}
319299
.fillMaxWidth(),
320300
) {
321301
Column(
@@ -332,64 +312,14 @@ private fun GravatarModalBottomSheet(
332312
}
333313
}
334314

335-
private val peek = SheetDetent(identifier = "peek") { containerHeight, _ ->
336-
containerHeight * 0.6f
337-
}
338-
339315
@Composable
340-
internal fun QuickEditorScopeOption.modalDetents(): ModalDetents {
341-
val windowHeightSizeClass = currentWindowAdaptiveInfo().windowSizeClass.windowHeightSizeClass
342-
343-
val detents = buildDetentsList()
344-
val initialDetent = initialDetent(windowHeightSizeClass)
345-
346-
return ModalDetents(
347-
initialDetent = if (detents.contains(initialDetent)) initialDetent else detents.last(),
348-
detents = detents,
349-
)
350-
}
351-
352-
private fun QuickEditorScopeOption.buildDetentsList(): List<SheetDetent> {
353-
return when (this.scope) {
354-
is QuickEditorScopeOption.Scope.AvatarPickerAndAboutEditor,
355-
is QuickEditorScopeOption.Scope.AboutEditor,
356-
-> buildList {
357-
add(Hidden)
358-
add(peek)
359-
add(FullyExpanded)
360-
}
361-
362-
is QuickEditorScopeOption.Scope.AvatarPicker -> buildList {
363-
add(Hidden)
364-
if (avatarPickerContentLayout == AvatarPickerContentLayout.Vertical) {
365-
add(peek)
366-
}
367-
add(FullyExpanded)
368-
}
369-
}
370-
}
371-
372-
private fun QuickEditorScopeOption.initialDetent(windowHeightSizeClass: WindowHeightSizeClass): SheetDetent {
373-
return if (windowHeightSizeClass == WindowHeightSizeClass.COMPACT) {
374-
FullyExpanded
375-
} else {
376-
when (this.scope) {
377-
is QuickEditorScopeOption.Scope.AboutEditor -> peek
378-
is QuickEditorScopeOption.Scope.AvatarPickerAndAboutEditor,
379-
is QuickEditorScopeOption.Scope.AvatarPicker,
380-
-> {
381-
if (
382-
this.avatarPickerContentLayout == AvatarPickerContentLayout.Horizontal &&
383-
this.initialPage == QuickEditorPage.AvatarPicker
384-
) {
385-
FullyExpanded
386-
} else {
387-
peek
388-
}
389-
}
390-
}
391-
}
392-
}
316+
internal fun modalDetents(): ModalDetents = ModalDetents(
317+
initialDetent = FullyExpanded,
318+
detents = buildList {
319+
add(Hidden)
320+
add(FullyExpanded)
321+
},
322+
)
393323

394324
internal data class ModalDetents(
395325
val initialDetent: SheetDetent,

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.modalDetents(),
28+
modalDetents = modalDetents(),
2929
onCurrentDetentChanged = {
3030
if (it == Hidden) {
3131
viewGroup.removeView(this)

0 commit comments

Comments
 (0)