diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java b/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java index 3b32f73450..1fd27d3f36 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java @@ -726,13 +726,20 @@ class AccessibilityBridge // handle hidden children at the beginning and end of the list. for (SemanticsObject child : object.childrenInHitTestOrder) { if (!child.hasFlag(Flag.IS_HIDDEN)) { - break; + visibleChildren += 1; } - visibleChildren += 1; } assert(object.scrollIndex + visibleChildren <= object.scrollChildren); assert(!object.childrenInHitTestOrder.get(object.scrollIndex).hasFlag(Flag.IS_HIDDEN)); - event.setToIndex(object.scrollIndex + visibleChildren); + // The setToIndex should be the index of the last visible child. Because we counted all + // children, including the first index we need to subtract one. + // + // [0, 1, 2, 3, 4, 5] + // ^ ^ + // In the example above where 0 is the first visible index and 2 is the last, we will + // count 3 total visible children. We then subtract one to get the correct last visible + // index of 2. + event.setToIndex(object.scrollIndex + visibleChildren - 1); } sendAccessibilityEvent(event); }