Skip to content

Commit dff14ca

Browse files
Material Design Teampekingme
Material Design Team
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 (cherry picked from commit 4b81bb1)
1 parent a5a738b commit dff14ca

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

+21-9
Original file line numberDiff line numberDiff line change
@@ -1732,17 +1732,14 @@ private void updateAccessibilityActions(
17321732
CoordinatorLayout coordinatorLayout, @NonNull T appBarLayout) {
17331733
ViewCompat.removeAccessibilityAction(coordinatorLayout, ACTION_SCROLL_FORWARD.getId());
17341734
ViewCompat.removeAccessibilityAction(coordinatorLayout, ACTION_SCROLL_BACKWARD.getId());
1735-
View scrollingView = findFirstScrollingChild(coordinatorLayout);
1736-
// Don't add a11y actions if there is no scrolling view that the abl depends on for scrolling
1737-
// or the abl has no scroll range.
1738-
if (scrollingView == null || appBarLayout.getTotalScrollRange() == 0) {
1735+
// Don't add a11y actions if the abl has no scroll range.
1736+
if (appBarLayout.getTotalScrollRange() == 0) {
17391737
return;
17401738
}
1741-
// Don't add actions if the scrolling view doesn't have the behavior that will cause the abl
1742-
// to scroll.
1743-
CoordinatorLayout.LayoutParams lp =
1744-
(CoordinatorLayout.LayoutParams) scrollingView.getLayoutParams();
1745-
if (!(lp.getBehavior() instanceof ScrollingViewBehavior)) {
1739+
// Don't add actions if a child view doesn't have the behavior that will cause the abl to
1740+
// scroll.
1741+
View scrollingView = getChildWithScrollingBehavior(coordinatorLayout);
1742+
if (scrollingView == null) {
17461743
return;
17471744
}
17481745

@@ -1769,6 +1766,21 @@ public void onInitializeAccessibilityNodeInfo(
17691766
addAccessibilityScrollActions(coordinatorLayout, appBarLayout, scrollingView);
17701767
}
17711768

1769+
@Nullable
1770+
private View getChildWithScrollingBehavior(CoordinatorLayout coordinatorLayout) {
1771+
final int childCount = coordinatorLayout.getChildCount();
1772+
for (int i = 0; i < childCount; i++) {
1773+
final View child = coordinatorLayout.getChildAt(i);
1774+
1775+
CoordinatorLayout.LayoutParams lp =
1776+
(CoordinatorLayout.LayoutParams) child.getLayoutParams();
1777+
if (lp.getBehavior() instanceof ScrollingViewBehavior) {
1778+
return child;
1779+
}
1780+
}
1781+
return null;
1782+
}
1783+
17721784
private boolean childrenHaveScrollFlags(AppBarLayout appBarLayout) {
17731785
final int childCount = appBarLayout.getChildCount();
17741786
for (int i = 0; i < childCount; i++) {

0 commit comments

Comments
 (0)