How do you achieve smooth scroll on desktop?
# compose-desktop
l
How do you achieve smooth scroll on desktop?
Note tha scroll on desktop is quite different from that on mobile. On mobile you scroll by dragging, and smooth scroll is just like throwing. But on desktop however, you scroll by some kind of stimulating, where each time you scroll your wheel a little bit will you scroll down certain amount of distance, and smooth scroll can be achieved by converting this to be velocity based, where each time you scroll you wheel will the scroll velocity build up slowly, and then decay as time goes.
So I was trying to implement this with the help of compose animation, but quickly found a problem: animations in compose are one-offs and immutable. They're not designed to be state based. This means that when the animation is still going and user sends another scroll input, the animation will be stopped and restarted. I then noticed that the content freezes first if I scroll too quickly. It may be because the old animation is still on its first frame when here comes the new one and kills the old one, resulting in a loop where no animation is actually running, but being stopped or started over and over again, until I release my mouse to let it go.
k
https://pavelfatin.com/scrolling-with-pleasure/ for some ideas and code links if you're ready to dive down into Swing and AWT