From c0edacaa1bdfeace669d97639c1cfeabaf03860e Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 8 Oct 2018 11:05:09 -0700 Subject: [PATCH] Correct issues in visible children determination (flutter/engine#6455) * fix off by one * add documentation on counting for setToIndex --- .../io/flutter/view/AccessibilityBridge.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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); }