Skip to content

Commit

Permalink
Fix nested scroll when Pager involved in scrolling process (#1154)
Browse files Browse the repository at this point in the history
Fix scroll interruption by Pager component when the scroll happens in
perpendicular direction

## Proposed Changes

Do not interrupt scrolling if it occurs in a perpendicular direction to
the Pager.

## Testing

Test: see description here:
JetBrains/compose-multiplatform#4395

## Issues Fixed

Fixes: The bug on
JetBrains/compose-multiplatform#4395
  • Loading branch information
ASalavei committed Mar 4, 2024
1 parent d25515c commit e26d5f5
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ private class DefaultPagerNestedScrollConnection(
available: Offset,
source: NestedScrollSource
): Offset {
if (source == NestedScrollSource.Fling && available != Offset.Zero) {
if (source == NestedScrollSource.Fling && available.toFloat() != 0f) {
throw CancellationException("End of scrollable area reached")
}
return Offset.Zero
Expand All @@ -904,6 +904,9 @@ private class DefaultPagerNestedScrollConnection(
override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity {
return available.consumeOnOrientation(orientation)
}

private fun Offset.toFloat(): Float =
if (orientation == Orientation.Horizontal) this.x else this.y
}

@OptIn(ExperimentalFoundationApi::class)
Expand Down

0 comments on commit e26d5f5

Please sign in to comment.