Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PageView ballistics overshoot the page on some devices #12884

Merged
merged 2 commits into from Nov 14, 2017

Conversation

jwmcglynn
Copy link
Contributor

On some devices, such as Cupertino “Plus”-sized devices, scrolling left on the first page of a PageView will overshoot the first page and land on the second page. Here is a gif that shows the problem:

overshoot

The issue is that applyContentDimensions incorrectly detects a content size change due to a floating point comparison on certain screen sizes (18257.400000000005 vs 18257.4)

To fix this, perform a nearEqual comparison in applyContentDimensions.

On some devices, such as Cupertino “Plus”-sized devices, scrolling left on the first page of a PageView will overshoot the first page and land on the second page.

The issue is that applyContentDimensions incorrectly detects a content size change due to a floating point comparison on certain screen sizes (18257.400000000005 vs 18257.4)

To fix this, perform a nearEqual comparison in applyContentDimensions.
@eseidelGoogle
Copy link
Contributor

@HansMuller is probably a good reviewer. Thanks for the patch!

return (a == b);
} else {
return (a > (b - epsilon)) && (a < (b + epsilon));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please write this as:

  /// Whether two doubles are within a given distance of each other.
  ///
  /// The `epsilon` argument must be positive and not null.
  /// The `a` and `b` arguments may be null. A null value is
  /// only considered near-equal to another null value.
bool nearEqual(double a, double b, double epsilon) {
    assert(epsilon != null);
    assert(epsilon >= 0.0);
    if (a == null || b == null)
      return a == b;
    return (a > (b - epsilon)) && (a < (b + epsilon));
  }

Thanks!

@Hixie
Copy link
Contributor

Hixie commented Nov 9, 2017

I don't fully understand why the maths doesn't work out, but this seems reasonable.

LGTM modulo the suggested change.

@Hixie
Copy link
Contributor

Hixie commented Nov 9, 2017

And thanks for the tests!

@Hixie
Copy link
Contributor

Hixie commented Nov 9, 2017

@jwmcglynn Please let us know when you've updated the patch as suggested, and then we can land it. Thanks again!

@jwmcglynn
Copy link
Contributor Author

Hey @Hixie, I pushed a new commit that addresses your feedback. Thanks for the review!

@xster
Copy link
Member

xster commented Nov 14, 2017

Thanks for the contribution!

@xster xster merged commit 473d75a into flutter:master Nov 14, 2017
DaveShuckerow pushed a commit to DaveShuckerow/flutter that referenced this pull request May 14, 2018
* PageView ballistics overshoot the page on some devices

On some devices, such as Cupertino “Plus”-sized devices, scrolling left on the first page of a PageView will overshoot the first page and land on the second page.

The issue is that applyContentDimensions incorrectly detects a content size change due to a floating point comparison on certain screen sizes (18257.400000000005 vs 18257.4)

To fix this, perform a nearEqual comparison in applyContentDimensions.

* Apply style changes to nearEqual for code review feedback.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants