-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Desktop pager physics #3447
Desktop pager physics #3447
Comments
How did you provide the input on the desktop? I guess by using a mouse wheel? It seems that the pager implementaion is expecting some kind of a gesture (a fling, swipe, drag). The desktop's use case was not properly thought of. |
I wrote a quick very dirty workaround to achieve this behavior by listening to the scroll offset and setting up both overscroll thresholds and a coroutine timeout that will kick it back to the original page if there is no further input. var sJob: Job? = null
LaunchedEffect(pagerState) {
snapshotFlow { pagerState.currentPageOffsetFraction }.collect { offset ->
if (!pagerState.isScrollInProgress) {
sJob?.cancel()
if (offset > 0.2f) {
pagerState.animateScrollToPage(pagerState.currentPage+1)
} else if (offset < -0.2f) {
pagerState.animateScrollToPage(pagerState.currentPage-1)
} else if (offset!=0f) {
sJob = scope.launch {
delay(500)
pagerState.animateScrollBy((pagerHeight*offset)*-1)
}
}
}
}
} Please feel free to use the code/merge it, but I'm sure there is a cleaner solution - this was just my dirty five minute fix. |
Any update guys ? |
Maybe the reason is #653 |
@HuixingWong Sorry, no updates yet |
Also, while scrolling via Shift + Mouse wheel, |
The workaround posted above did not work well enough for me (if the automatic fling is still in progress and you try to scroll the pager, it breaks and stops adjusting automatically), but I found my own dirty fix, maybe it will help some folks here.
Then the snapping behaviour can be reproduced like this:
Finally, we can apply the modifier to any composable that forms the content of the pager:
The main disadvantage of this is that the snap is based on the offset fraction and not scroll velocity. This is not in line with the mobile implementations, if I'm not mistaken. |
## Proposed Changes - Based on #1055 - Trigger `onScrollStopped` callback after mouse wheel scroll - Ignore `ScrollableDefaultFlingBehavior`s during mouse scroll to avoid breaking changes - Remove scrolling via `dispatchRawDelta`, `isSmoothScrollingEnabled = false` will just disable animation instead - Add pager test page in mpp demo ## Testing Test: run pager page in mpp demo ## Issues Fixed Fixes JetBrains/compose-multiplatform#3447 Fixes JetBrains/compose-multiplatform#3454
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks. |
For some reason desktop and web pagers don't align with next or prev page after end of a scroll. Compose version doesn't matter. It was from the 1st version that includes pager.
It that an intended behaviour or a bug?
Screen.Recording.2023-08-02.at.10.30.41.mov
I expect it to work like on Android/iOS:
Screen.Recording.2023-08-02.at.10.51.48.mov
The text was updated successfully, but these errors were encountered: