Skip to content

Commit 4b81bb1

Browse files
Material Design Teamdsn5ft
authored andcommitted
[AppBarLayout] Loosen check for scrollable child when adding a11y actions
Adding the a11y delegate and a11y actions was dependent on there being a CoordinatorLayout child that both inherits from certain scrolling classes (NestedScrollingChild, ListView, ScrollView) and has an AppBarLayout scrolling behavior. This was too restrictive and so we only check for a behavior. Any scrolling child may add an a11y delegate or scroll action to the parent CoordinatorLayout. PiperOrigin-RevId: 448335380
1 parent d25d18d commit 4b81bb1

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

lib/java/com/google/android/material/appbar/AppBarLayout.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,17 +1745,14 @@ private void updateAccessibilityActions(
17451745
CoordinatorLayout coordinatorLayout, @NonNull T appBarLayout) {
17461746
ViewCompat.removeAccessibilityAction(coordinatorLayout, ACTION_SCROLL_FORWARD.getId());
17471747
ViewCompat.removeAccessibilityAction(coordinatorLayout, ACTION_SCROLL_BACKWARD.getId());
1748-
View scrollingView = findFirstScrollingChild(coordinatorLayout);
1749-
// Don't add a11y actions if there is no scrolling view that the abl depends on for scrolling
1750-
// or the abl has no scroll range.
1751-
if (scrollingView == null || appBarLayout.getTotalScrollRange() == 0) {
1748+
// Don't add a11y actions if the abl has no scroll range.
1749+
if (appBarLayout.getTotalScrollRange() == 0) {
17521750
return;
17531751
}
1754-
// Don't add actions if the scrolling view doesn't have the behavior that will cause the abl
1755-
// to scroll.
1756-
CoordinatorLayout.LayoutParams lp =
1757-
(CoordinatorLayout.LayoutParams) scrollingView.getLayoutParams();
1758-
if (!(lp.getBehavior() instanceof ScrollingViewBehavior)) {
1752+
// Don't add actions if a child view doesn't have the behavior that will cause the abl to
1753+
// scroll.
1754+
View scrollingView = getChildWithScrollingBehavior(coordinatorLayout);
1755+
if (scrollingView == null) {
17591756
return;
17601757
}
17611758

@@ -1782,6 +1779,21 @@ public void onInitializeAccessibilityNodeInfo(
17821779
addAccessibilityScrollActions(coordinatorLayout, appBarLayout, scrollingView);
17831780
}
17841781

1782+
@Nullable
1783+
private View getChildWithScrollingBehavior(CoordinatorLayout coordinatorLayout) {
1784+
final int childCount = coordinatorLayout.getChildCount();
1785+
for (int i = 0; i < childCount; i++) {
1786+
final View child = coordinatorLayout.getChildAt(i);
1787+
1788+
CoordinatorLayout.LayoutParams lp =
1789+
(CoordinatorLayout.LayoutParams) child.getLayoutParams();
1790+
if (lp.getBehavior() instanceof ScrollingViewBehavior) {
1791+
return child;
1792+
}
1793+
}
1794+
return null;
1795+
}
1796+
17851797
private boolean childrenHaveScrollFlags(AppBarLayout appBarLayout) {
17861798
final int childCount = appBarLayout.getChildCount();
17871799
for (int i = 0; i < childCount; i++) {

0 commit comments

Comments
 (0)