Skip to content

InteractiveViewer pan axis locking - #61019

Merged
fluttergithubbot merged 6 commits into
flutter:masterfrom
justinmc:iv-scroll-lock
Jul 8, 2020
Merged

fluttergithubbot merged 6 commits into
flutter:masterfrom
justinmc:iv-scroll-lock

Conversation

@justinmc

@justinmc justinmc commented Jul 7, 2020

Copy link
Copy Markdown
Contributor

Description

This PR adds an alignPanAxis parameter to InteractiveViewer. When true, panning is only allowed along the x or y axes, not diagonally.

align_pan_axis

Related Issues

Closes #58043
Mentioned in #12878

Tests

I added the following tests:

  • A 45 degree drag pans vertically.
  • A <45 degree drag pans horizontally.
  • Zoom still allows updating the translation along a diagonal.

Breaking Change

None.

@justinmc
justinmc requested a review from LongCatIsLooong July 7, 2020 20:07
@justinmc justinmc self-assigned this Jul 7, 2020
@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label Jul 7, 2020
@justinmc justinmc mentioned this pull request Jul 7, 2020
&& boundaryMargin.left.isFinite)),
super(key: key);

/// If true, panning is only allowed in the direction of the main axes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I couldn't find the definition of "main axes". Maybe "horizontal axis or vertical axis"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, that sounds better.

/// If true, panning is only allowed in the direction of the main axes.
///
/// In other words, when this is true, diagonal panning is not allowed. This
/// is a common pattern in tables where data is displayed in columns and rows.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears to me that if the user initiates a horizontal drag, then they won't be able to change the direction to vertical later (in the same gesture). Maybe add documentation for this behavior too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. I'll document it. It seems to be how Google Sheets works on my iPhone too.

}

final Offset alignedTranslation = widget.alignPanAxis && _panAxis != null
&& _gestureType == _GestureType.pan

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be done in _onScaleUpdate to avoid checking _gestureType?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call 👍

@fluttergithubbot
fluttergithubbot merged commit a82005a into flutter:master Jul 8, 2020
@justinmc
justinmc deleted the iv-scroll-lock branch July 8, 2020 17:11
mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InteractiveViewer scroll direction locking

4 participants