Add support for viewers scrolling away UI during document consumption
E.g. a viewer might show the origin of the doc and may want to hide that as the user scrolls down, but show it again when they scroll up.
Event should be send on scroll event and contain scrollTop and potentially the cached scrollHeight
@ericfs Tuned your description a bit :)
Assigned to @muxin
The converse of this would enable "tap scrollbar to scroll to top" in iOS. If a user does, it'll trigger a scroll event (if the viewer is not already at the top) in the viewer window. If we send down that scroll event, we can scroll to the top of the AMP doc as well.
Putting in Backlog for now. @muxin, if you plan to work on soon, please change to Current or Next as appropriate. Thanks!
Thanks for taking this. It looks like only scrollTop is sent and not scrollHeight. Is it possible to get the height too?
Hmm, when @muxin and I looked at this, it seemed we sent this already, but now I can't find it. We certainly can.
@dvoytenko ScrollHeight is currently not cached. Could we start only recalculating it when we mutated the doc or the viewport changed?
@cramforce We used to do it and I asked it to be removed (/cc @jridgewell) due to some problems in the way we implemented it. We can bring this back if it's really necessary, but we need to see how. We used to do it in each runtime pass and that was fairly expensive. I think, a better option might be to do it for scroll events specifically, but only calculate scrollHeight once for scroll series.
scrollHeight would be helpful, if it's available, particularly to know when the scroll reaches the bottom, but I think we can manage without it.
@ericfs but what would be the most applicable target message for this info? scroll message?
Yes, that would be fine.
Re: https://github.com/ampproject/amphtml/issues/3515. If we do reintroduce it, we need to cache.
Can we update scroll height:
- after we build an element
- after resize
- after mutate
Are there other situations where it might change?
@ericfs Do you need a precise value?
I think it would be preferable, but I think I can work with whatever you can provide. Ideally a Viewer would know when the page is scrolled to the bottom, but an estimate may be ok.