Repository navigation
showOnScreen doesn't trigger scroll if item is already fully on screen - #17729
Conversation
| // TODO(goderbauer): Don't scroll if that puts us outside of viewport's bounds. | ||
| if ((currentOffset - leadingEdgeOffset).abs() < (currentOffset - trailingEdgeOffset).abs()) { | ||
|
|
||
| if (currentOffset > leadingEdgeOffset && currentOffset > trailingEdgeOffset) { |
There was a problem hiding this comment.
can you assert leadingEdgeOffset <= trailingEdgeOffset?
There was a problem hiding this comment.
No, but I can guarantee it the other way around: leadingEdgeOffset >= trailingEdgeOffset :)
There was a problem hiding this comment.
(really? that's surprising)
in that case, assert that then simplify the expressions
There was a problem hiding this comment.
To get a list item to the leading edge (as opposed to the trailing edge) you have to scroll further, therefore leadingEdgeOffset >= trailingEdgeOffset, no?
Will simplify expression.
There was a problem hiding this comment.
In a regular vertically scrolling list, the leading edge is above the trailing edge, so you get it first (lower scroll offset) than the trailing edge (higher scroll offset) unless I'm missing something?
There was a problem hiding this comment.
To ensure that we talk about the same thing I have drawn up two diagrams: Both show a long scrollable list (on the left) that scrolls through the viewport window (on the right in yellow).
In the first picture, the list item in question is shown at the leading edge of the viewport. I'd argue that the scrollOffset here is 600, which is called the leadingEdgeOffset in the code.
Now, let's move the list item in question to the trailing edge of the viewport. I'd argue that in this picture the scrollOffset is 350, which is called the trailingEdgeOffset in the code.
So, now I would argue that 600 > 350. And therefore (even though this is by now means a full mathematically proof), it seems that leadingEdgeOffset >= trailingEdgeOffset holds.
There was a problem hiding this comment.
ah, yup, i was missing something. :-)
| offset.jumpTo(leadingEdgeOffset); | ||
| } else { | ||
| } else if (currentOffset < leadingEdgeOffset && currentOffset < trailingEdgeOffset ) { | ||
| offset.jumpTo(trailingEdgeOffset); |
There was a problem hiding this comment.
any chance we can factor the common code into the base class?
There was a problem hiding this comment.
I've looked into doing that before and there is no good common ancestor for this...
There was a problem hiding this comment.
create a common mixin (RenderViewportShowOnScreenMixin) or make a static method on some class (RenderViewportBase.showChildInViewport or some such) and use that.
There was a problem hiding this comment.
Mixin doesn't work (or gets awkward because of the super call in the method. I changed it to a static method.
| expect(scrollController.offset, kItemHeight / 2); | ||
|
|
||
| semantics.dispose(); | ||
| }); |
There was a problem hiding this comment.
we should test that this works with negative-scroll-offset children too

Fixes #11663.