Switch to using animation request for scroll inertia dispatch#18997
Conversation
|
You can test this PR using the following package version. |
| return true; | ||
| }, TimeSpan.FromMilliseconds(16), DispatcherPriority.Background); | ||
|
|
||
| MediaContext.Instance.RequestAnimationFrame(StartInertia); |
There was a problem hiding this comment.
You can use TopLevel.RequestAnimationFrame method, as it's a stable API. MediaContext is internal.
There was a problem hiding this comment.
Note that animation frames will be toplevel-scoped at some point too, the plan is to not trigger callbacks if toplevel isn't visible or is being throttled by the system compositor.
There was a problem hiding this comment.
Unfortunately, TopLevel is in the Controls project, and not the Base project.
|
|
||
| var speed = _inertia * Math.Pow(InertialResistance, (_lastTime - _inertiaStartTime).TotalSeconds); | ||
| var distance = speed * elapsedSinceLastTick.TotalSeconds; | ||
| _inertiaDispatchOperation = Dispatcher.UIThread.InvokeAsync(() => |
There was a problem hiding this comment.
Can you add a comment here, that we actually want InvokeAsync only to raise events with Input priority?
There was a problem hiding this comment.
IIRC from the discussion, priority change was the only reason.
| return true; | ||
| }, TimeSpan.FromMilliseconds(16), DispatcherPriority.Background); | ||
|
|
||
| MediaContext.Instance.RequestAnimationFrame(StartInertia); |
There was a problem hiding this comment.
I think StartInertial should be called directly from PointerReleased. There is no reason to delay that.
| return; | ||
| } | ||
|
|
||
| var elapsedSinceLastTick = timeSpan - _lastTime; |
There was a problem hiding this comment.
All of those calculations should live in Input priority callback. The only job of animation frame callbacks is to throttle inertia events. OnAnimationRequested should just post a callback via dispatcher.
6ac2653 to
a60f7a9
Compare
|
You can test this PR using the following package version. |
…iaUI#18997) * switch to using animation request for scroll inertia dispatch * run inertia calcs in dispatcher operation
…iaUI#18997) * switch to using animation request for scroll inertia dispatch * run inertia calcs in dispatcher operation
What does the pull request do?
This PR dispatches scroll inertia events on animation tick. This provides much smoother inertia scrolling on high framerate devices.
What is the current behavior?
Scroll inertia was dispatched on 16ms interval, limiting it to 60fps. Devices with higher framerate or variable framerate will have choppy scroll animations when inertia is started.
What is the updated/expected behavior with this PR?
How was the solution implemented (if it's not obvious)?
Checklist
Breaking changes
Obsoletions / Deprecations
Fixed issues