Skip to content

Revise Action API - #42940

Merged
gspencergoog merged 7 commits into
flutter:masterfrom
gspencergoog:nodeless_actions
Apr 7, 2020
Merged

gspencergoog merged 7 commits into
flutter:masterfrom
gspencergoog:nodeless_actions

Conversation

@gspencergoog

@gspencergoog gspencergoog commented Oct 17, 2019 •

Copy link
Copy Markdown
Contributor

Description

We've had some feedback that people would like to be able to invoke actions when they are not in the context of keyboard input (from a mouse click, etc.).

The original design was oriented towards invoking actions from widgets, and
having those actions act in the context of the widget. Teams have been using
actions, and found several limitations in that design that needed to be
addressed:

  1. They were unable to invoke actions from outside of the widget hierarchy.
    Examples of this include processing a script of commands, and some undo/redo
    systems.
  2. The mapping between shortcut key to Intent and then to Action wasn't
    always clear, since the data structures were mapping LogicalKeySet =>
    Intent and then LocalKey => ActionFactory. The new mapping is still
    LogicalKeySet => Intent but then it maps Type (Intent type) =>
    Action, which more direct and readable, since the type of the intent is
    written in the mapping.
  3. If the key binding for an action was in another part of the widget hierarchy,
    it was not always possible for the Intent to have access to the state
    necessary to decide if the intent/action should be enabled or not.

Here are the changes made to address these problems:

  1. The FocusNode argument to Action.invoke and Actions.invoke was removed.
  2. The Map<LocalKey, ActionFactory> that was given to the Actions widget is
    now a Map<Type, Action<Intent>> (the type is the type of the Intent).
  3. The isEnabled method was moved from the Intent to the Action class.
  4. Invoking an action no longer creates a new instance of the Action.
  5. The Action class is now a generic (Action<T extends Intent>) for better
    type safety.
  6. A LocalKey is no longer an argument to the Intent constructor.
  7. The Action class may now be listened to for changes in state.
  8. The OnInvokeCallback used by CallbackAction no longer takes a FocusNode
    argument.
  9. The LocalKey argument to CallbackAction has been removed.
  10. The ActionDispatcher.invokeAction signature has changed to not accept an
    optional FocusNode, but instead take an optional BuildContext.
  11. The LocalKey static constants (named key) in Action subclasses have been
    removed.
  12. The Action.invoke and ActionDispatcher.invokeAction methods now return
    the result of invoking the action.
  13. The ActionFactory typedef has been removed, as it is no longer used.

There is a design doc for the changes in the PR: https://flutter.dev/go/actions-and-shortcuts-design-revision

Tests

  • Modified existing tests to verify that the correct context is being passed.

Related Issues

Breaking Change

  • Yes, this is a breaking change for anyone using Actions, and probably Shortcuts too.
    • The signature for Action.invoke has changed significantly, as has the Action constructor.
    • The RequestFocusAction now requires the use of a RequestFocusIntent.
    • The signature for onInvoke property of the CallbackAction has also changed.
    • The invokeAction signature on the ActionDispatcher has changed.
    • The map for actions on the Actions widget is now a Map<Type, Action<Intent>>.
    • Invoking an action doesn't create a new instance of the action.

@fluttergithubbot fluttergithubbot added p: material_ui material_ui package in flutter/packages framework flutter/packages/flutter repository. See also f: labels. c: contributor-productivity Team-specific productivity, code health, technical debt. work in progress; do not review labels Oct 17, 2019
@codecov

This comment has been minimized.

@gspencergoog
gspencergoog force-pushed the nodeless_actions branch 5 times, most recently from 076e57a to 838afea Compare October 31, 2019 07:12
@gspencergoog
gspencergoog marked this pull request as ready for review November 1, 2019 01:05
@gspencergoog
gspencergoog force-pushed the nodeless_actions branch 2 times, most recently from 704c477 to af339df Compare November 1, 2019 02:45
@gspencergoog gspencergoog changed the title Makes focus nodes not required to invoke actions. WIP: Makes focus nodes not required to invoke actions. Nov 13, 2019
@gspencergoog
gspencergoog force-pushed the nodeless_actions branch 6 times, most recently from 2b4cdfd to 3c8d8b2 Compare November 22, 2019 22:39
@gspencergoog
gspencergoog force-pushed the nodeless_actions branch 4 times, most recently from 5c4a210 to ba67cf0 Compare December 19, 2019 23:27
@gspencergoog
gspencergoog force-pushed the nodeless_actions branch 3 times, most recently from 04a86dd to 2200d39 Compare January 31, 2020 00:20
@gspencergoog gspencergoog changed the title WIP: Revise Action API Revise Action API Feb 25, 2020
@gspencergoog
gspencergoog force-pushed the nodeless_actions branch 5 times, most recently from 199b309 to 8e8bb87 Compare March 3, 2020 14:27
@gspencergoog
gspencergoog force-pushed the nodeless_actions branch 3 times, most recently from 1b79aba to 6c11dd2 Compare March 12, 2020 21:41
@gspencergoog
gspencergoog force-pushed the nodeless_actions branch 2 times, most recently from 737609e to 517c658 Compare March 25, 2020 20:05

@goderbauer goderbauer left a comment

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 new API is pretty nice!

Comment thread dev/manual_tests/lib/actions.dart Resolved
Comment thread dev/manual_tests/lib/actions.dart Resolved
@gspencergoog
gspencergoog force-pushed the nodeless_actions branch 2 times, most recently from ec432aa to b9dd6a5 Compare March 31, 2020 23:09
@gspencergoog

Copy link
Copy Markdown
Contributor Author

@goderbauer, Thanks for your review!

I think this is ready for another look.

@goderbauer goderbauer left a comment

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.

LGTM

@goderbauer goderbauer left a comment

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.

LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

c: contributor-productivity Team-specific productivity, code health, technical debt. 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Actions API to not need FocusNodes and improve Intent->Action mapping

4 participants

⌂ Proxy