AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
26.14k stars 2.27k forks source link

Introduce smooth scrolling #12977

Open timunie opened 1 year ago

timunie commented 1 year ago

Is your feature request related to a problem? Please describe. Until today scrolling cannot be animated very good which feels unnatural in some situations, for example having long text.

Describe the solution you'd like Provide an API to enable animated scrolling on user request

Describe alternatives you've considered Implement a Behavior or a custom ScrollViewer

Additional context First discussed here #12945

Meloman19 commented 1 year ago

I think we need something similar to InteractionTracker from UWP/WinUI. Scrolling in the composition layer will be maximum smooth. Also, such scrolling will not be affected by possible microfreezings in the UI thread. And after that, it will be possible to rewrite ScrollViewer (ScrollContentPresenter) to this tracker. I don't think anyone really needs current "jumping" scroll...

I tried to implement something similar and it seems to be working, but had to use a tons of hacks.

TextBox https://github.com/AvaloniaUI/Avalonia/assets/23280622/f935b98d-8d3f-4906-a01c-29c1d96e8aca
ItemsRepeater https://github.com/AvaloniaUI/Avalonia/assets/23280622/93de549f-de07-4168-ba7b-bfb5c0101eb0
timunie commented 1 year ago

@Meloman19 how beautiful is that 😍

Do you mind sharing your tons of hacks here for others? I'd be interested also in how you made it work.

Meloman19 commented 1 year ago

@timunie Sorry for the delay.

Here test implementation: https://github.com/Meloman19/CompositionScroll Only scrolling with the mouse wheel and scroll bar works. There are some issues with virtualization and anchoring.

In general, the concept is working, but virtualization tied to EffectiveViewport causes a problem, because we need to call Arrange in each Offset changed.

timunie commented 1 year ago

@Meloman19 thank you so much. Appreciate it ❤️

dotNET-anykey commented 11 months ago

@Meloman19

I can't describe how your work is amazing. Can I ask, maybe you have any ideas how it could work with touch input as well? What needs to be done there in order to work?

maxkatz6 commented 11 months ago

@dotNET-anykey their code should handle touch scroll gesture as well.

Although, Avalonia already supports smooth scrolling for touch for a long time. But we planned to implement composition-level scrolling for a while now too.

dotNET-anykey commented 10 months ago

With the implementation from @Meloman19, I found an issue that having compositeScroll and Carousel in same userControl makes Carousel not reflect to updates of SelectedIndex.

Meloman19 commented 8 months ago

With the implementation from @Meloman19, I found an issue that having compositeScroll and Carousel in same userControl makes Carousel not reflect to updates of SelectedIndex.

CompositeScroll not support ILogicalScrollable (DateTimePickerPanel and VirtualizingCarouselPanel). By design ILogicalScrollable handle own scrolling what conflict with Presenter's InteractionTracker.