Add support for custom accessibility actions to android and iOS.#18882
Add support for custom accessibility actions to android and iOS.#18882jonahwilliams merged 24 commits intoflutter:masterfrom
Conversation
|
| config.onDidLoseAccessibilityFocus = _performDidLoseAccessibilityFocus; | ||
| if (customAccessibilityActions != null) { | ||
| config.customAccessibilityActions = _customAccessibilityActions; | ||
| } |
There was a problem hiding this comment.
please be consistent with nearby code regarding braces, to make the code easier to read
| String toString() => '$runtimeType($name)'; | ||
| } | ||
|
|
||
| /// A custom accessibility action. |
There was a problem hiding this comment.
this is not a helpful description since it's exactly the class name. :-)
The first line should be a brief but still useful description. It appears in documentation summaries (e.g. in the library-level docs).
| }); | ||
| } | ||
|
|
||
|
|
| return new Semantics( | ||
| customAccessibilityActions: <CustomAccessibilityAction, VoidCallback>{ | ||
| const CustomAccessibilityAction(label: 'Archive'): () { | ||
| setState(() { |
There was a problem hiding this comment.
Maybe factor this out into a method so the same code can be used for the dismisable (when the user swipes) and the custom a11y action?
| ) | ||
| ) | ||
| ) | ||
| ), |
There was a problem hiding this comment.
nit: is formatting off here somehow? Looks strange to have to closing ) with the same indentation?
|
|
||
| /// A map from each supported [CustomAccessibilityAction] to a provided handler. | ||
| /// | ||
| /// The handler associated with each custom action is invoked whenever a |
There was a problem hiding this comment.
This doc comment seems to describe impl details? Maybe rephrase it a little and focus on what I as a user of this could do with it?
| /// Custom accessibility actions can be provided to make complex user | ||
| /// interactions more accessible. A drag and drop list, for example, may | ||
| /// require a user to press and hold an item to move it. This may be | ||
| /// difficult for a user interacting with your app using a hardware switch. A |
There was a problem hiding this comment.
avoid refering to "your" app; the reader may not be the person whose app they're trying to understand
Prefer something like "For instance, if an application has a drag-and-drop list that requires the user to press and hold an item to move it, users interacting with the application using a hardware switch may have difficulty."
There was a problem hiding this comment.
I incorporated this suggestion and did a pass on the entire doc comment.
| /// interactions more accessible. A drag and drop list, for example, may | ||
| /// require a user to press and hold an item to move it. This may be | ||
| /// difficult for a user interacting with your app using a hardware switch. A | ||
| /// custom accessibility action allows you to specifiy actions such as |
There was a problem hiding this comment.
same here, "allows the application to specify..."
(also, typo on specify)
| /// In Android, these actions are presented in the local context menu. In iOS, | ||
| /// these are in the radial context menu. | ||
| class CustomAccessibilityAction { | ||
|
|
|
|
||
| /// Creates a new [CustomAccessibilityAction]. | ||
| /// | ||
| /// [label] must not be null or the empty string. |
There was a problem hiding this comment.
consider starting with "The [label] argument must..." to avoid starting with a lowercase letter.
| /// | ||
| /// [label] must not be null or the empty string. | ||
| const CustomAccessibilityAction({@required this.label}) | ||
| : assert(label != null && label != ''); |
There was a problem hiding this comment.
prefer splitting asserts into multiple asserts rather than chaining expressions with &&, it makes it easier to see what went wrong when they fire
| static int getIdentifier(CustomAccessibilityAction action) { | ||
| int result = _ids[action]; | ||
| if (result == null) { | ||
| result =_nextId++; |
| && typedOther.scrollExtentMin == scrollExtentMin | ||
| && typedOther.transform == transform; | ||
| && typedOther.transform == transform | ||
| && setEquals(typedOther.customAccessibilityActions, customAccessibilityActions); |
There was a problem hiding this comment.
yikes, this is one expensive == method
There was a problem hiding this comment.
I think replacing the set of custom actions with a sorted list of ints will make this faster...
| /// | ||
| /// See also: | ||
| /// | ||
| /// * [CustomAccessibilityAction], for an explaination of custom actions. |
| /// A map from each supported [CustomAccessibilityAction] to a provided handler. | ||
| /// | ||
| /// The handler associated with each custom action is invoked whenever a | ||
| /// semantics event of type [SemanticsEvent.customEvent] is recieved. The |
|
|
||
| /// A map from each supported [CustomAccessibilityAction] to a provided handler. | ||
| /// | ||
| /// The handler associated with each custom action is invoked whenever a |
There was a problem hiding this comment.
nit: prefer "called" over "invoked" (see style guide)
|
I think I addressed most of the comments, PTAL |
|
Since we're going to tie these in with renaming hint text for actions on Android (in a future PR), i've updated the name to CustomSemanticsAction to make the relationship with SemanticsAction more obvious. |
|
|
||
| @override | ||
| int get hashCode => ui.hashValues(flags, actions, label, value, increasedValue, decreasedValue, hint, textDirection, rect, tags, textSelection, scrollPosition, scrollExtentMax, scrollExtentMin, transform); | ||
| int get hashCode => ui.hashValues(flags, actions, label, value, increasedValue, decreasedValue, hint, textDirection, rect, tags, textSelection, scrollPosition, scrollExtentMax, scrollExtentMin, transform, customSemanticsActionIds); |
There was a problem hiding this comment.
nit: maybe its time to add some line breaks to this line?
|
|
||
| /// A map from each supported [CustomSemanticsAction] to a provided handler. | ||
| /// | ||
| /// The handler associated with each custom action is called whenever a |
There was a problem hiding this comment.
Should this doc also be updated to the version you are using above?
There was a problem hiding this comment.
Do you mean the CustomSemanticsAction doc comment?
| ' mergeAllDescendantsIntoThisNode: false\n' | ||
| ' Rect.fromLTRB(0.0, 0.0, 0.0, 0.0)\n' | ||
| ' actions: []\n' | ||
| ' customActions: []\n' |
There was a problem hiding this comment.
Maybe add a test that ensures that custom actions are properly printed when the Semantics tree is printed out?
Fixes #18432