Skip to content

Commit cdabf28

Browse files
committed
fix: fling issues
1 parent c0d9134 commit cdabf28

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

bottom-drawer-scaffold/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ apply from: '../buildCompose.gradle'
88

99
ext {
1010
PUBLISH_GROUP_ID = 'de.charlex.compose'
11-
PUBLISH_VERSION = '2.0.0-alpha01'
11+
PUBLISH_VERSION = '2.0.0-alpha02'
1212
PUBLISH_ARTIFACT_ID = 'bottom-drawer-scaffold'
1313
}
1414

bottom-drawer-scaffold/src/main/java/de/charlex/compose/bottomdrawerscaffold/AnchoredDraggableStateExt.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import androidx.compose.ui.input.nestedscroll.NestedScrollSource
88
import androidx.compose.ui.unit.Velocity
99

1010
@OptIn(ExperimentalFoundationApi::class)
11-
internal fun <T> AnchoredDraggableState<T>.createPreUpPostDownNestedScrollConnection(): NestedScrollConnection {
11+
internal fun <T> AnchoredDraggableState<T>.createPreUpPostDownNestedScrollConnection(topOffset: Int): NestedScrollConnection {
1212
return object : NestedScrollConnection {
1313
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
1414
val delta = available.toFloat()
@@ -33,8 +33,7 @@ internal fun <T> AnchoredDraggableState<T>.createPreUpPostDownNestedScrollConnec
3333

3434
override suspend fun onPreFling(available: Velocity): Velocity {
3535
val toFling = Offset(available.x, available.y).toFloat()
36-
// return if (toFling < 0 && offset.value > minBound) {
37-
return if (toFling < 0) {
36+
return if (toFling < 0 && offset > topOffset) {
3837
settle(velocity = toFling)
3938
// since we go to the anchor with tween settling, consume all for the best UX
4039
available

bottom-drawer-scaffold/src/main/java/de/charlex/compose/bottomdrawerscaffold/BottomDrawerScaffold.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import androidx.compose.ui.graphics.Shape
4242
import androidx.compose.ui.input.nestedscroll.nestedScroll
4343
import androidx.compose.ui.layout.Layout
4444
import androidx.compose.ui.layout.onGloballyPositioned
45+
import androidx.compose.ui.platform.LocalConfiguration
4546
import androidx.compose.ui.platform.LocalDensity
4647
import androidx.compose.ui.semantics.collapse
4748
import androidx.compose.ui.semantics.expand
@@ -61,14 +62,15 @@ fun rememberBottomDrawerScaffoldState(
6162
confirmValueChange: (newValue: BottomDrawerValue) -> Boolean = { true }
6263
): AnchoredDraggableState<BottomDrawerValue> {
6364
val density = LocalDensity.current
65+
val maxHeight = with(density) { LocalConfiguration.current.screenHeightDp.dp.toPx() }
6466
return remember {
6567
AnchoredDraggableState(
6668
initialValue = initialValue,
6769
positionalThreshold = positionalThreshold,
6870
velocityThreshold = velocityThreshold ?: { with(density) { 100.dp.toPx() } },
6971
animationSpec = animationSpec,
7072
anchors = DraggableAnchors {
71-
BottomDrawerValue.Collapsed at 0f
73+
BottomDrawerValue.Collapsed at maxHeight
7274
BottomDrawerValue.Expanded at 0f
7375
},
7476
confirmValueChange = confirmValueChange
@@ -86,9 +88,7 @@ fun BottomDrawerScaffold(
8688
bottomBar: @Composable (() -> Unit)? = null,
8789
gesturesEnabled: Boolean = true,
8890
drawerModifier: Modifier = Modifier,
89-
// snackbarHostState: SnackbarHostState,
9091
snackbarHost: @Composable () -> Unit = {},
91-
// snackbarHost: @Composable (SnackbarHostState) -> Unit = { SnackbarHost(it) },
9292
floatingActionButton: @Composable (() -> Unit)? = null,
9393
floatingActionButtonPosition: FabPosition = FabPosition.End,
9494
drawerGesturesEnabled: Boolean? = null,
@@ -143,7 +143,7 @@ fun BottomDrawerScaffold(
143143

144144
val anchoredDraggableModifier = Modifier
145145
.nestedScroll(
146-
bottomDrawerScaffoldState.createPreUpPostDownNestedScrollConnection()
146+
bottomDrawerScaffoldState.createPreUpPostDownNestedScrollConnection(topPadding.toInt())
147147
)
148148
.anchoredDraggable(
149149
state = bottomDrawerScaffoldState,

0 commit comments

Comments
 (0)