Skip to content

Commit

Permalink
Add hasImplicitScrolling SemanticFlag and support in Android bridge (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahwilliams authored Aug 6, 2018
1 parent 4681351 commit a5215ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
13 changes: 13 additions & 0 deletions lib/ui/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ class SemanticsFlag {
static const int _kIsLiveRegionIndex = 1 << 15;
static const int _kHasToggledStateIndex = 1 << 16;
static const int _kIsToggledIndex = 1 << 17;
static const int _kHasImplicitScrollingIndex = 1 << 18;

const SemanticsFlag._(this.index);

Expand Down Expand Up @@ -465,6 +466,15 @@ class SemanticsFlag {
/// * [SemanticsFlag.hasToggledState], which enables a toggled state.
static const SemanticsFlag isToggled = const SemanticsFlag._(_kIsToggledIndex);

/// Whether the platform can scroll the semantics node when the user attempts
/// to move focus to an offscreen child.
///
/// For example, a [ListView] widget has implicit scrolling so that users can
/// easily move to the next visible set of children. A [TabBar] widget does
/// not have implicit scrolling, so that users can navigate into the tab
/// body when reaching the end of the tab bar.
static const SemanticsFlag hasImplicitScrolling = const SemanticsFlag._(_kHasImplicitScrollingIndex);

/// The possible semantics flags.
///
/// The map's key is the [index] of the flag and the value is the flag itself.
Expand All @@ -487,6 +497,7 @@ class SemanticsFlag {
_kIsLiveRegionIndex: isLiveRegion,
_kHasToggledStateIndex: hasToggledState,
_kIsToggledIndex: isToggled,
_kHasImplicitScrollingIndex: hasImplicitScrolling,
};

@override
Expand Down Expand Up @@ -528,6 +539,8 @@ class SemanticsFlag {
return 'SemanticsFlag.hasToggledState';
case _kIsToggledIndex:
return 'SemanticsFlag.isToggled';
case _kHasImplicitScrollingIndex:
return 'SemanticsFlag.hasImplicitScrolling';
}
return null;
}
Expand Down
14 changes: 11 additions & 3 deletions shell/platform/android/io/flutter/view/AccessibilityBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ enum Flag {
IS_IMAGE(1 << 14),
IS_LIVE_REGION(1 << 15),
HAS_TOGGLED_STATE(1 << 16),
IS_TOGGLED(1 << 17);
IS_TOGGLED(1 << 17),
HAS_IMPLICIT_SCROLLING(1 << 18);

Flag(int value) {
this.value = value;
Expand Down Expand Up @@ -256,8 +257,15 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
|| object.hasAction(Action.SCROLL_RIGHT) || object.hasAction(Action.SCROLL_DOWN)) {
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");
// the visible viewport of a scrollable, unless the node itself does not
// allow implicit scrolling - then we leave the className as view.View.
if (object.hasFlag(Flag.HAS_IMPLICIT_SCROLLING)) {
if (object.hasAction(Action.SCROLL_LEFT) || object.hasAction(Action.SCROLL_RIGHT)) {
result.setClassName("android.widget.HorizontalScrollView");
} else {
result.setClassName("android.widget.ScrollView");
}
}
// TODO(ianh): Once we're on SDK v23+, call addAction to
// expose AccessibilityAction.ACTION_SCROLL_LEFT, _RIGHT,
// _UP, and _DOWN when appropriate.
Expand Down

0 comments on commit a5215ce

Please sign in to comment.