Skip to content

[WIP] DefaultScrollAction - #69616

Closed
Piinks wants to merge 11 commits into
flutter:masterfrom
Piinks:primaryScroller
Closed

Piinks wants to merge 11 commits into
flutter:masterfrom
Piinks:primaryScroller

Conversation

@Piinks

@Piinks Piinks commented Nov 2, 2020 •

Copy link
Copy Markdown
Contributor

Description

This introduces a new widget that will enable fallback/default keyboard scrolling for ScrollActions. The DefaultScrollAction manages a given Scrollable context so if one is not found during the course of a ScrollAction, the fallback Scrollable will receive it.

Earlier ideas for this involved the user passing a key to the DefaultScrollAction, but this felt kludgy and bug prone, especially since the given key would need to be below the Scrollable for look-up. I've added Scrollable.isDefaultScrollAction to all associated classes instead to see if this is a better user experience. The boolean flag will indicate if the Scrollable should connect with the DefaultScrollAction, and can provide the right key for accessing the state of the Scrollable. This also felt less exposed as we can leave most of the implementation private.

Design Document

Related Issues

#43694

Tests

WIP

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.

@flutter-dashboard flutter-dashboard Bot added framework flutter/packages/flutter repository. See also f: labels. work in progress; do not review labels Nov 2, 2020
@google-cla google-cla Bot added the cla: yes label Nov 2, 2020
@Piinks Piinks added a: desktop Running on desktop and removed cla: yes labels Nov 2, 2020
@google-cla google-cla Bot added the cla: yes label Nov 2, 2020
@Piinks Piinks added platform-web Web applications specifically and removed cla: yes labels Nov 2, 2020
@google-cla google-cla Bot added the cla: yes label Nov 2, 2020
@Piinks

Piinks commented Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

cc/ @gspencergoog I think I found a cleaner way to implement this. Still needs tests if this is the way to go, but WDYT?

@Piinks Piinks added the c: new feature Nothing broken; request for a new capability label Nov 2, 2020
Comment thread packages/flutter/lib/src/widgets/scrollable.dart Outdated
Comment thread packages/flutter/lib/src/widgets/scrollable.dart Outdated
/// for default ScrollActions to take place outside of th context fo the
/// current focus.
/// {@endtemplate}
final bool primaryScrollShortcut;

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 think this needs a better name, I found it hard to know what it was before I read this documentation block.

Some ideas:

  • isDefaultPrimaryScrollable
  • isFallbackScrollable
  • isPrimaryScrollable
  • isDefaultScrollable
  • Or something else...these don't feel perfect either.

I feel like it doesn't need the "Shortcut" as part of the name, since you could invoke the ScrollAction without using a shortcut if you wanted to. It should also probably begin with "is", since it's a bool.

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.

I see what you mean, I'll experiment with some new names. Thanks for the feedback! :)

@Piinks Piinks changed the title [WIP] PrimaryScrollShortcut [WIP] DefaultScrollAction Nov 3, 2020
this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
this.restorationId,
this.clipBehavior = Clip.hardEdge,
this.isDefaultScrollAction = false,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Semantically, how is this different from primary (line 84)?

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.

Oh that is probably a much better flag to use rather than introducing a new one. Thanks!

child: Overlay(
key: _overlayKey,
initialEntries: overlay == null ? _allRouteOverlayEntries.toList(growable: false) : const <OverlayEntry>[],
child: DefaultScrollAction(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The navigator is an odd place to add scrolling behavior.

// Similar to notificationContext, _ScrollableScope is placed above the
// widget using it: RawGestureDetector, which allows us to access this
// ScrollableState
defaultScrollAction?._defaultScrollKey = _gestureDetectorKey;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if we have two scrollables with isDefaultScrollAction set to true?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In some situations that would probably be illegal. In others (e.g. if they are in separate routes) it would presumably be ok?

child: Overlay(
key: _overlayKey,
initialEntries: overlay == null ? _allRouteOverlayEntries.toList(growable: false) : const <OverlayEntry>[],
child: DefaultScrollAction(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, wouldn't route A and B both have separate defaultScrollables? When route B is popped, how does Route A become the default again (I don't think there's any guarantee that the Scrollable's didChangeDependencies of Route A will run to re-register when Route B is popped.

@Piinks

Piinks commented Nov 4, 2020

Copy link
Copy Markdown
Contributor Author

Closing for now in favor of discussing an alternative solution in #69795

@Piinks Piinks closed this Nov 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop c: new feature Nothing broken; request for a new capability framework flutter/packages/flutter repository. See also f: labels. platform-web Web applications specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants