Correct issues in visible children determination (flutter/engine#6455)

* fix off by one

* add documentation on counting for setToIndex
This commit is contained in:
Jonah Williams
2018-10-08 11:05:09 -07:00
committed by GitHub
parent 1c5797421b
commit c0edacaa1b

View File

@@ -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);
}