This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
a11y: Add SemanticsAction "showOnScreen" #3856
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ class AccessibilityBridge extends AccessibilityNodeProvider { | |
private static final int SEMANTICS_ACTION_SCROLL_DOWN = 1 << 5; | ||
private static final int SEMANTICS_ACTION_INCREASE = 1 << 6; | ||
private static final int SEMANTICS_ACTION_DECREASE = 1 << 7; | ||
private static final int SEMANTICS_ACTION_SHOW_ON_SCREEN = 1 << 8; | ||
|
||
private static final int SEMANTICS_ACTION_SCROLLABLE = SEMANTICS_ACTION_SCROLL_LEFT | | ||
SEMANTICS_ACTION_SCROLL_RIGHT | | ||
|
@@ -77,7 +78,7 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) { | |
|
||
AccessibilityNodeInfo result = AccessibilityNodeInfo.obtain(mOwner, virtualViewId); | ||
result.setPackageName(mOwner.getContext().getPackageName()); | ||
result.setClassName("Flutter"); // Prettier than the more conventional node.getClass().getName() | ||
result.setClassName("Flutter"); // TODO(goderbauer): Set proper class names | ||
result.setSource(mOwner, virtualViewId); | ||
|
||
if (object.parent != null) { | ||
|
@@ -117,6 +118,9 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) { | |
result.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD); | ||
result.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD); | ||
result.setScrollable(true); | ||
// This tells Android's a11y to send scroll events when reaching the end of | ||
// the visible viewport of a scrollable. | ||
result.setClassName("android.widget.ScrollView"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see. The magic is to fake which class you are? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. That's exactly it. |
||
} | ||
|
||
result.setCheckable((object.flags & SEMANTICS_FLAG_HAS_CHECKED_STATE) != 0); | ||
|
@@ -199,6 +203,12 @@ public boolean performAction(int virtualViewId, int action, Bundle arguments) { | |
mFocusedObject = object; | ||
return true; | ||
} | ||
// TODO(goderbauer): Use ACTION_SHOW_ON_SCREEN from Android Support Library after | ||
// https://github.com/flutter/flutter/issues/11099 is resolved. | ||
case 16908342: { // ACTION_SHOW_ON_SCREEN, added in API level 23 | ||
mOwner.dispatchSemanticsAction(virtualViewId, SEMANTICS_ACTION_SHOW_ON_SCREEN); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why?
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.
Android TalkBack uses the class to determine how to behave (for an example see below where I set the class to ScrollView to get the correct scroll behavoir). And if you set the class to button for example, Android talkback will correctly announce that it is a button. There are more classes with special meaning, apparently.