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

TwoDimensional scrolling foundation #125437

Merged
merged 48 commits into from May 26, 2023
Merged

TwoDimensional scrolling foundation #125437

merged 48 commits into from May 26, 2023

Conversation

Piinks
Copy link
Contributor

@Piinks Piinks commented Apr 24, 2023

From the 2D scrolling proposal: flutter.dev/go/2D-Foundation ✅ updated 4/25

Fixes #125505

Follow up issues:

This adds a mostly abstract foundation for 2D scrolling in Flutter.

With these base classes, developers will be able to construct widgets that scroll in both dimensions and can lazily load their children for the best performance. This implementation is meant to be flexible in order to support different kinds of 2D compositions, from tables to scatter plots.

The upcoming TableView, TreeView, etc widgets (coming soon in flutter/packages) are built on top of this foundation.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. labels Apr 24, 2023
@Piinks Piinks requested a review from goderbauer April 24, 2023 20:45
@goderbauer
Copy link
Member

I'll have to block some time to look at this. In the meantime, can you make the checks pass?

@Piinks
Copy link
Contributor Author

Piinks commented Apr 25, 2023

I'll have to block some time to look at this.

Of course! Take your time. :)

In the meantime, can you make the checks pass?

Oof sorry! I thought I caught all of them. On it!

xLayoutOffset += 200;
}
if (applyDimensions) {
verticalOffset.applyContentDimensions(0, 200 * 100 - viewportDimension.height);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only thing I am still unsure of. I tried to write some logic to estimate the max scroll extent for the user, but it was really hard to guess what they were building or how long it would be in one or both dimensions.

So right now, the user has to call applyContentDimensions. I currently have a check that will tell them to do so if they have not.

The other thing I considered was exposing a maxScrollOffset getter that the subclasses would have to implement, and then the super class could call applyContentDimensions with that at the end of performLayout.

I like the getter approach, curious to know what you think first though. :)

Copy link
Member

Choose a reason for hiding this comment

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

Either seems fine to me. If we want people to call applyContentDimensions within layoutChildSequence we should document that, though. The getter may be a little less flexible (which could be fine), but simpler to implement.

@Piinks Piinks changed the title [WIP] TwoDimensional* Foundation [WIP] TwoDimensional scrolling foundation Apr 25, 2023
@Piinks Piinks added the c: new feature Nothing broken; request for a new capability label Apr 25, 2023
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

Comments from initial read-through to familiarize myself with this large PR. It's not a full review yet and I didn't get to two_dimensional_viewport.dart and the test file yet.

packages/flutter/lib/src/widgets/framework.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/widgets/scroll_delegate.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/widgets/scrollable.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/widgets/scrollable.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/widgets/scrollable.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/widgets/scrollable.dart Outdated Show resolved Hide resolved
@Piinks Piinks force-pushed the 2DTime branch 4 times, most recently from 0ad8747 to b3add8d Compare May 1, 2023 21:57
@Piinks
Copy link
Contributor Author

Piinks commented May 1, 2023

I am having branch issues. I really do not want to close this, but the Github UI is not updating with the code.

@Piinks
Copy link
Contributor Author

Piinks commented May 1, 2023

Ok I think my branch issues are behind me. I responded to the last review and left a few questions for feedback. I will push tests next now that I have everything fixed.

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

Finished initial read-through of the last few remaining files.

xLayoutOffset += 200;
}
if (applyDimensions) {
verticalOffset.applyContentDimensions(0, 200 * 100 - viewportDimension.height);
Copy link
Member

Choose a reason for hiding this comment

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

Either seems fine to me. If we want people to call applyContentDimensions within layoutChildSequence we should document that, though. The getter may be a little less flexible (which could be fine), but simpler to implement.

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

Overall, this LGTM. It is missing some test coverage, though.

/// Subclasses must implement this function and will typically wrap their
/// children in [RepaintBoundary] widgets.
///
/// The values returned by this method are cached. To indicate that the
Copy link
Member

Choose a reason for hiding this comment

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

Can you also just call "notifyListeners" as the class level comment indicated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so, added more to the doc.

packages/flutter/lib/src/widgets/scrollable.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/widgets/scrollable.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/widgets/scrollable.dart Outdated Show resolved Hide resolved
for (final RenderBox child in _children.values) {
final TwoDimensionalViewportParentData childParentData = parentDataOf(child);
final Rect childRect = childParentData.paintOffset & child.size;
if (childRect.contains(position)) {
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't child.hitTest below already contain this check?

if (_size!.contains(position)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excellent point, fixed!

Copy link
Member

Choose a reason for hiding this comment

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

Looks like this wasn't resolved after all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right. I changed it, and then had a bug and ended up writing it back in. Let me double check. Thanks for pointing it out! I did not realize I ended up reverting it.

Comment on lines 1263 to 1412
void _startLayout();
void _buildChild(ChildVicinity index);
void _reuseChild(ChildVicinity index);
void _endLayout();
Copy link
Member

Choose a reason for hiding this comment

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

Maybe consider making the methods public. That way, people can implement their own TwoDimensionalChildManager if they wanted to and having a public class with no visible methods is kinda strange.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think that is where we started a conversation about finding a way to make it private.
Would folks actually be able to implement their own? So much of the implementation relies on private class members.

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

Overall, this LGTM. It is missing some test coverage, though. :)

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

for (final RenderBox child in _children.values) {
final TwoDimensionalViewportParentData childParentData = parentDataOf(child);
final Rect childRect = childParentData.paintOffset & child.size;
if (childRect.contains(position)) {
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this wasn't resolved after all?

@Piinks Piinks added framework flutter/packages/flutter repository. See also f: labels. f: scrolling Viewports, list views, slivers, etc. labels May 26, 2023
@github-actions github-actions bot removed f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. labels May 26, 2023
@Piinks Piinks added f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. autosubmit Merge PR when tree becomes green via auto submit App labels May 26, 2023
@auto-submit auto-submit bot merged commit 0f1a95d into flutter:master May 26, 2023
71 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 28, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 28, 2023
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jun 2, 2023
flutter/flutter@ee162e4...3db9504

2023-05-28 engine-flutter-autoroll@skia.org Roll Flutter Engine from 340936f7c03c to a4d4ad9dae1a (1 revision) (flutter/flutter#127772)
2023-05-28 engine-flutter-autoroll@skia.org Roll Flutter Engine from 57e491a46e05 to 340936f7c03c (1 revision) (flutter/flutter#127767)
2023-05-28 engine-flutter-autoroll@skia.org Roll Flutter Engine from a37b1a38d97a to 57e491a46e05 (1 revision) (flutter/flutter#127765)
2023-05-28 engine-flutter-autoroll@skia.org Roll Flutter Engine from b1698020bd57 to a37b1a38d97a (1 revision) (flutter/flutter#127761)
2023-05-27 engine-flutter-autoroll@skia.org Roll Flutter Engine from 9e97c7379c7f to b1698020bd57 (1 revision) (flutter/flutter#127758)
2023-05-27 engine-flutter-autoroll@skia.org Roll Flutter Engine from 0f38a0f0a18a to 9e97c7379c7f (1 revision) (flutter/flutter#127755)
2023-05-27 engine-flutter-autoroll@skia.org Roll Flutter Engine from 1187168472a7 to 0f38a0f0a18a (1 revision) (flutter/flutter#127752)
2023-05-27 engine-flutter-autoroll@skia.org Roll Flutter Engine from 3426cb827efb to 1187168472a7 (1 revision) (flutter/flutter#127745)
2023-05-27 engine-flutter-autoroll@skia.org Roll Flutter Engine from 795db50e7453 to 3426cb827efb (9 revisions) (flutter/flutter#127738)
2023-05-27 tessertaha@gmail.com Updated the `ToggleButtons` API doc to link to `SegmentedButton` (flutter/flutter#127021)
2023-05-26 nbosch@google.com Remove more `test_api/src` imports (flutter/flutter#127716)
2023-05-26 31859944+LongCatIsLooong@users.noreply.github.com Move shared inline widget logic to `RenderInlineWidgetContainerDefaults` (flutter/flutter#127308)
2023-05-26 engine-flutter-autoroll@skia.org Roll Flutter Engine from 3b5b5fc96b8f to 795db50e7453 (1 revision) (flutter/flutter#127720)
2023-05-26 pq@users.noreply.github.com Update collection-fors to prefer final (as per updated `prefer_final_in_for_each`) (flutter/flutter#127511)
2023-05-26 engine-flutter-autoroll@skia.org Roll Flutter Engine from eed12f36f595 to 3b5b5fc96b8f (1 revision) (flutter/flutter#127713)
2023-05-26 gspencergoog@users.noreply.github.com Remove references to deprecated `ThemeData.primaryColorBrightness` (flutter/flutter#127238)
2023-05-26 katelovett@google.com TwoDimensional scrolling foundation (flutter/flutter#125437)
2023-05-26 engine-flutter-autoroll@skia.org Roll Flutter Engine from 858d9753453c to eed12f36f595 (2 revisions) (flutter/flutter#127702)
2023-05-26 36861262+QuncCccccc@users.noreply.github.com Remove button announcement for `MenuItemButton` and `SubmenuButton` (flutter/flutter#127620)
2023-05-26 chillers@google.com Reland "Update labeler action wildcards #127524" (flutter/flutter#127690)
2023-05-26 vashworth@google.com Revert "Log all lines from ios-deploy (#127502)" (flutter/flutter#127684)
2023-05-26 engine-flutter-autoroll@skia.org Roll Flutter Engine from ec7b0ae3599f to 858d9753453c (2 revisions) (flutter/flutter#127700)
2023-05-26 tessertaha@gmail.com Add M3 date range picker tests and fix header background theme color (flutter/flutter#127662)
2023-05-26 reidbaker@google.com Support minifcation for apps that depend on AGP 8 and integration_test (flutter/flutter#127628)
2023-05-26 gspencergoog@users.noreply.github.com Bump Snippet version (flutter/flutter#127688)
2023-05-26 chris@bracken.jp [Linux] Use up_client_get_devices2 when possible (flutter/flutter#127699)
2023-05-26 engine-flutter-autoroll@skia.org Roll Flutter Engine from 84f2fc16e55d to ec7b0ae3599f (3 revisions) (flutter/flutter#127698)
2023-05-26 5236035+fzyzcjy@users.noreply.github.com Fix `TextField` error in production environment because it wrongly uses ancestor render boxes (flutter/flutter#126324)
2023-05-26 127535196+JsGjKJzi@users.noreply.github.com Interactive viewer doesn't appear to respect the trackpadScrollCausesScale parameter (flutter/flutter#127114)
2023-05-26 chillers@google.com Remove release timeline (flutter/flutter#127685)
2023-05-26 engine-flutter-autoroll@skia.org Manual roll Flutter Engine from 8573f3b63a1f to 84f2fc16e55d (7 revisions) (flutter/flutter#127676)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC bmparr@google.com,rmistry@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@x4080
Copy link

x4080 commented Aug 10, 2023

hello, how can I use this ? is there any example ?

Thanks

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App c: new feature Nothing broken; request for a new capability f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add 2D scrolling foundation to the framework
3 participants