Skip to content

anchors 1/n: Handle GrowthDirection.reverse in sticky_header #496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 30, 2024

Conversation

gnprice
Copy link
Member

@gnprice gnprice commented Jan 30, 2024

This is the first of several PRs leading us to #80 and #82, opening the message list at an anchor other than the latest message in history.

For this PR, the main work is to lift one of the simplifying assumptions I originally made for an MVP of the sticky_header library, allowing the SliverStickyHeaderList to be a sliver that counts backward in the enclosing ScrollView rather than forward.

We also rearrange some things in how MessageList builds the list, in order to exercise that new flexibility and to get closer to how we'll want things when implementing #80 and #82.

Main commit messages

sticky_header: Handle GrowthDirection.reverse

This resolves the last of the "TODO dir" comments in this library.

We had originally written this library to rely on the assumption
that constraints.growthDirection was GrowthDirection.forward,
i.e. that the direction in which constraints.scrollOffset increases
was the same as constraints.axisDirection, in order to keep down
the number of distinct directions one needs to keep track of in
writing and reading (and debugging) the implementation.

But now that this logic is relatively solid within that case --
and now that we have a solid test suite for this library -- we can
go back and identify the handful of places that need to be flipped
around for GrowthDirection.reverse, and do so.

This support isn't yet especially useful: there are a couple of
unrelated bugs which are triggered when the area allotted to this
sliver isn't the entire viewport, and there isn't a lot of reason
to have a sliver with GrowthDirection.reverse when no other sliver
is potentially occupying part of the viewport. We'll fix those
separately.


msglist [nfc]: Let ScrollView count forward, and sliver handle reverse

This means that the overall scroll view has AxisDirection.down
as the scroll direction, rather than AxisDirection.up, and the
SliverStickyHeader is passed GrowthDirection.reverse instead
of GrowthDirection.forward in order to get the same effect.

This makes the scrolling a little easier to think about when focused
on MessageList's code, because for example (as seen in this diff)
scrollMetrics.extentBefore now refers to the messages that are
older than the ones on screen, rather than those that are newer.

This also brings us closer to the setup we'll want for #80 and #82,
opening the message list at an anchor other than the end: the empty
placeholder sliver at the bottom will become the list of messages
after the starting anchor, while the sliver at the top will remain
the list of messages above the anchor.

This will help keep down complexity (and depth of indentation)
as we make the list view more complex.  In particular it will
avoid duplication when we start having two back-to-back slivers
that both contain message-list items.
This will allow using it as one sliver in a CustomScrollView.
@gnprice gnprice added a-msglist The message-list screen, except what's label:a-content a-sticky_header Our `sticky_header` library labels Jan 30, 2024
This is effectively what StickyHeaderListView.builder was
abbreviating.  This expanded form will then give us flexibility
to introduce a second sliver.
This resolves the last of the "TODO dir" comments in this library.

We had originally written this library to rely on the assumption
that `constraints.growthDirection` was `GrowthDirection.forward`,
i.e. that the direction in which `constraints.scrollOffset` increases
was the same as `constraints.axisDirection`, in order to keep down
the number of distinct directions one needs to keep track of in
writing and reading (and debugging) the implementation.

But now that this logic is relatively solid within that case --
and now that we have a solid test suite for this library -- we can
go back and identify the handful of places that need to be flipped
around for `GrowthDirection.reverse`, and do so.

This support isn't yet especially *useful*: there are a couple of
unrelated bugs which are triggered when the area allotted to this
sliver isn't the entire viewport, and there isn't a lot of reason
to have a sliver with GrowthDirection.reverse when no other sliver
is potentially occupying part of the viewport.  We'll fix those
separately.
This is a more readable way of expressing the exact same thing.
This means that the overall scroll view has AxisDirection.down
as the scroll direction, rather than AxisDirection.up, and the
SliverStickyHeader is passed GrowthDirection.reverse instead
of GrowthDirection.forward in order to get the same effect.

This makes the scrolling a little easier to think about when focused
on MessageList's code, because for example (as seen in this diff)
`scrollMetrics.extentBefore` now refers to the messages that are
older than the ones on screen, rather than those that are newer.

This also brings us closer to the setup we'll want for zulip#80 and zulip#82,
opening the message list at an anchor other than the end: the empty
placeholder sliver at the bottom will become the list of messages
after the starting anchor, while the sliver at the top will remain
the list of messages above the anchor.
@chrisbobbe chrisbobbe merged commit bdac26f into zulip:main Jan 30, 2024
@chrisbobbe
Copy link
Collaborator

Thanks! Merged.

@gnprice gnprice deleted the pr-scroll-reverse branch January 30, 2024 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-msglist The message-list screen, except what's label:a-content a-sticky_header Our `sticky_header` library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants