Skip to content

Default Keyboard ScrollActions with PrimaryScrollController - #69795

Merged
fluttergithubbot merged 11 commits into
flutter:masterfrom
Piinks:primaryScroller2
Nov 11, 2020
Merged

fluttergithubbot merged 11 commits into
flutter:masterfrom
Piinks:primaryScroller2

Conversation

@Piinks

@Piinks Piinks commented Nov 4, 2020 •

Copy link
Copy Markdown
Contributor

Description

This PR adds default behavior for ScrollActions by using the PrimaryScrollController. It also moves the PrimaryScrollController that is instantiated in CupertinoPageScaffold and Scaffold to be in the _ModalScopeState, so each route can have their own PrimaryScrollController. This also places it high enough to be found by a ScrollAction from the default/root focus point.

If a Scrollable is not found enclosing the primaryFocus when evaluating a ScrollAction, it will look up the PrimaryScrollController to see if the ScrollAction can be invoked. By using the primary flag in a ScrollView, you can connect your scroll view to the PrimaryScrollController and have ScrollActions work by default.

Original PR #69616
Design Document

Related Issues

Fixes #43694

Tests

Updates tests that were broken by moving the PrimaryScrollController to the route level from the Scaffold
Added test for default primary ScrollAction execution
Fixed and un-skip 6 web tests related to ScrollActions

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 p: cupertino_ui cupertino_ui package in flutter/packages p: material_ui material_ui package in flutter/packages framework flutter/packages/flutter repository. See also f: labels. work in progress; do not review labels Nov 4, 2020
@google-cla google-cla Bot added the cla: yes label Nov 4, 2020
@Piinks Piinks mentioned this pull request Nov 4, 2020
9 tasks done
Comment thread packages/flutter/lib/src/cupertino/page_scaffold.dart Outdated
Comment thread packages/flutter/lib/src/material/scaffold.dart Outdated
);
}

result = PrimaryScrollController(

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.

You probably need more than just one controller per app, no? E.g. if you have multiple routes stacked on top of each other, they can all have primary scrollables, that need to scroll independent of each other?

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.

In that case, would this be better placed in the Navigator like it originally was in #69616?

Comment thread packages/flutter/lib/src/widgets/scrollable.dart
@Piinks Piinks changed the title [WIP] Fallback ScrollActions with PrimaryScrollController Default Keyboard ScrollActions with PrimaryScrollController Nov 10, 2020
@Piinks Piinks added a: desktop Running on desktop f: focus Focus traversal, gaining or losing focus platform-web Web applications specifically c: new feature Nothing broken; request for a new capability labels Nov 10, 2020
@Piinks
Piinks marked this pull request as ready for review November 10, 2020 18:19
Comment thread packages/flutter/lib/src/widgets/scrollable.dart Outdated
Comment thread packages/flutter/lib/src/widgets/scrollable.dart Outdated
Comment thread packages/flutter/lib/src/widgets/scrollable.dart Outdated
bool isEnabled(ScrollIntent intent) {
final FocusNode? focus = primaryFocus;
return focus != null && focus.context != null && Scrollable.of(focus.context!) != null;
final bool contextIsValid = focus != null && focus.context != null;

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.

You could just move this into the if, since you only use it once.

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.

Or, you could leave it. The name does provide inherent documentation. Your choice.

final ScrollController _primaryScrollController = ScrollController();

void _handleStatusBarTap() {
final ScrollController? _primaryScrollController = PrimaryScrollController.of(context);

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.

Is there a good place where we could document on this class that it uses the PrimaryScrollController from the environment?

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.

Added


void _handleStatusBarTap() {
if (_primaryScrollController.hasClients) {
final ScrollController? _primaryScrollController = PrimaryScrollController.of(context);

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 comment above probably needs updating (we are no longer providing the primary scroll controller here.

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.

Fixed!

/// Another default behavior handled by the PrimaryScrollController is default
/// [ScrollAction]s. If a ScrollAction is not handled by an otherwise focused
/// part of the application, the ScrollAction will be evaluated using the scroll
/// view associated with this ScrollController, for example, when executing

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.

"this ScrollController" - it's not guaranteed that "this" scrollcontroller is used. The action uses whatever PrimaryScrollController it can find in its context, no?

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.

Tweaked.

Comment thread packages/flutter/lib/src/widgets/primary_scroll_controller.dart Outdated
Comment thread packages/flutter/lib/src/widgets/primary_scroll_controller.dart Outdated
ignoring: ignoreEvents,
child: child,
child: PrimaryScrollController(
controller: ScrollController(),

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.

We should probably not instantiate a new controller every time this rebuilds and instead reuse the same scrollcontroller instance?

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.

Fixed!

@fluttergithubbot
fluttergithubbot merged commit 1f0df54 into flutter:master Nov 11, 2020
zanderso added a commit that referenced this pull request Nov 12, 2020
zanderso added a commit that referenced this pull request Nov 12, 2020
@Piinks Piinks added the f: scrolling Viewports, list views, slivers, etc. label Nov 12, 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 f: focus Focus traversal, gaining or losing focus f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. p: cupertino_ui cupertino_ui package in flutter/packages p: material_ui material_ui package in flutter/packages platform-web Web applications specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[web] Add support for spacebar Shortcut to include ScrollIntent

5 participants