-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Add key event handlers that happen before or after the focus traversal #136280
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
Add key event handlers that happen before or after the focus traversal #136280
Conversation
goderbauer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just some doc suggestions.
| typedef FocusOnKeyEventCallback = KeyEventResult Function(FocusNode node, KeyEvent event); | ||
|
|
||
| /// Signature of a callback used by [FocusManager.addEarlyKeyEventHandler] and | ||
| /// [FocusManager.addLateKeyEventHandler]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you document the semantics of the argument and return value here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| /// All of the handlers in the set will be called for every key event the | ||
| /// [FocusManager] receives. If any one of the handlers returns | ||
| /// [KeyEventResult.handled] or [KeyEventResult.skipRemainingHandlers], then | ||
| /// none of the handlers in the focus tree will be called. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe link to removeEarlyKeyEventHandler, e.g. in a see also section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also link to addLateKeyEventHandler (and vice versa) just for discoverability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For completeness: can you also document the behavior if handlers are added/removed from a OnKeyEventCallback (i.e. while the callbacks are being invoked)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| /// If the event reaches the root of the focus tree without being handled, | ||
| /// then all of the handlers in the set will be called. If any of them returns | ||
| /// [KeyEventResult.handled] or [KeyEventResult.skipRemainingHandlers], then | ||
| /// event propagation to the platform will be stopped. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| /// If the event reaches the root of the focus tree without being handled, | ||
| /// then all of the handlers in the set will be called. If any of them returns | ||
| /// [KeyEventResult.handled] or [KeyEventResult.skipRemainingHandlers], then | ||
| /// event propagation to the platform will be stopped. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
link to remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, converted this to a macro, since the text is identical.
|
auto label is removed for flutter/flutter/136280, due to - The status or check suite Windows build_tests_4_5 has failed. Please fix the issues identified (or deflake) before re-applying this label. |
Description
This adds a mechanism for listening to key events before or after focus traversal occurs.
It adds four methods to the public
FocusManagerAPI:addEarlyKeyEventHandler- Adds a handler that can handle events before they are given to the focus tree for handling.removeEarlyKeyEventHandler- Removes an early event handler.addLateKeyEventHandler- Adds a handler that can handle events if they have not been handled by anything in the focus tree.removeLateKeyEventHandler- Removes a late event handler.This allows an app to get notified for a key anywhere, and prevent the focus tree from seeing that event if it handles it.
For the menu system, this allows it to eat an escape key press and close all the open menus.
Related Issues
Tests