Feature: Desktop Mouse Support (Cursor styling, Scroll Panning & Smooth Zoom-to-Cursor)#571
Open
quaaantumdev wants to merge 1 commit intobluefireteam:mainfrom
Open
Feature: Desktop Mouse Support (Cursor styling, Scroll Panning & Smooth Zoom-to-Cursor)#571quaaantumdev wants to merge 1 commit intobluefireteam:mainfrom
quaaantumdev wants to merge 1 commit intobluefireteam:mainfrom
Conversation
0a452a9 to
8ecc638
Compare
Author
|
I change the implementation behind this PR to a much nicer implementation, with physics based animations which feels really good now. So that's the reason for the forced-push, it's not an incremental updated but a larger restructuring of what i had before. Hope the work is appreciated, would be great to see this in the official package :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR significantly improves the user experience for Web and Desktop targets by implementing native-feeling mouse interactions. It introduces proper scroll-to-pan, Ctrl+scroll-to-zoom, and adaptive cursor styling, powered by a new internal animation engine that ensures butter-smooth transitions.
Key Features
Native Desktop Interaction (
PhotoViewScrollHandler)Adaptive Cursor Styling (
PhotoViewMouseRegion)SystemMouseCursors.grabwhen hovering over the image andgrabbingwhen dragging.Smooth Additive Animations (
PhotoViewAnimationEngine)Implementation Note
We aimed to keep the refactoring footprint minimal to preserve the stability of the existing code. However, the architectural changes included here—specifically extracting the Animation Engine—were deemed necessary because they add major value:
Stateclass makes the core logic significantly easier to read and maintain.Technical Implementation Details
Architecture Refactor (Engine/Delegate Pattern):
PhotoViewAnimationEngine: Extracted all animation logic (Fling, Rebound, Double-Tap) out ofPhotoViewCoreinto a dedicated class. This separates "Physics & Math" from "Rendering & Event Listening."PhotoViewControllerDelegate: Updated the controller architecture to allow the Core to receive imperative animation commands directly from the controller.Refactor:
PhotoViewCoreBuild Logic:StreamBuilderto readcontroller.valuedirectly instead of relying on the potentially delayedsnapshot.data. This prevents one-frame lag artifacts when driving the view via the animation engine which is very noticeable when zooming with Ctrl+scroll-to-zoom, making the rendered view jumping back and forth unexpectedly.buildmethod to chain widget wrappers sequentially, improving readability with the new additional widgets.File Reorganization (Diff Notice):
photo_view_controller.dart: To keep the files manageable, the abstract base classes (PhotoViewControllerBase,PhotoViewControllerValue) were moved to a new filephoto_view_controller_base.dart.photo_view_controller.dartwill show a large deletion, but this code was simply moved to the base file. The implementation logic remains inphoto_view_controller.dart, there is just additional code for the attach/detach procedure and the animate commnads.Usage & Public API
This functionality is integrated directly into
PhotoViewCoreand works out of the box.Additionally, the
PhotoViewControllernow exposes new imperative methods (animateScaleBy,animatePositionBy).Why?
Previous versions required setting
controller.scale = valuedirectly to zoom programmatically, which resulted in instant, jarring jumps. Exposing these animation methods allows developers to easily implement external UI controls—such as Zoom In/Out buttons or directional pads—that utilize the same smooth, physics-based engine as the internal gestures.Checklist