Fixed layer: Support per-element opt-in for transfer to fixed layer
What's the issue?
Feature Request: Stable fixed elements in iOS amp search results
As you are aware, the amp framework currently has a workaround of moving fixed elements that meet certain criteria to a pseudo-fixed element in iOS google search results. However, this has a few disadvantages:
- Fixed elements shown in the main body after page load display in a juttery way. See video below.
- Moving elements to this fixed layer takes processing time on startup.
- Elements in this psuedo-fixed element do not update with amp-bind state changes.
- Not all fixed elements are moved, so DOM structure and layering of fixed elements becomes unpredictable.
- Fixed layers are difficult to quickly and accurately test before publishing the site.
Summary of Needs
During our eCommerce projects, we are running into situations where we would like to show fixed elements on the page after page load. We are finding ourselves needing to ensure that modals, sidebars, persistent buy buttons, filtering options, or help/chat buttons work together and are visually consistent with our client's mobile sites.
In summary, our main needs regarding fixed elements are:
- Fixed elements that don't jutter
- Predictible fixed element layering
- A stable DOM for CSS Rules
- Amp-bind working properly in fixed elements
- Fast initial load times
Our preference is create fixed elements with more universal tools like css, amp-bind, and amp-list instead of working with specialized amp-components for fixed elements on the page.
Potential Solutions
- One potential solution for fixed element jutter in iOS (our preference, perhaps the simplest) is to remove the !important restriction on this rule:
html.i-amphtml-ios-embed.i-amphtml-ios-overscroll,
html.i-amphtml-ios-embed.i-amphtml-ios-overscroll>#i-amphtml-wrapper{
-webkit-overflow-scrolling:touch!important
}
This would allow us to specify -webkit-overflow-scrolling:auto instead so that fixed elements will no longer jutter. The benefits of relaxing this rule can be seen here: https://www.youtube.com/watch?v=gAFD_wS0wg4
Stable fixed elements, reliable z-index layering, consistent UI, and faster page load times are higher priorities than momentum scrolling for many of our clients. This solution lets the browser fix the problem with CSS instead of adding more javascript. Also, this approach ensures that amp-bind will work in fixed elements.
-
Another potential solution (suggested by others before) is to allow developers to specify which elements should go in the pseudo-fixed element and what the z-index of that element should be. This has processing disadvantages at runtime. Also, we would also not be able to move elements that depended on amp-bind into this element because they wouldn't update properly in GSR.
-
A third alternative is to allow initial coding of amp pages so that the amp runtime doesn't need to expensively rearrange the page on page load. Just load the iOS edge case solution everywhere. This is both declarative and will allow faster load times for amp pages not preprocessed on the google CDN.
<iframe id="ampViewer">
<html>
<html>
<body id="scrollableThings">
</body>
</html>
<body id="fixedStuffGoesHere">
<div id="modal"></div>
<div id="chatBtn"></div>
<div id="ampDoesntHaveToTestIfiAmFixed"></div>
<body>
</html>
</iframe>
What browsers are affected?
All mobile Safari browsers in Google Search Results
Which AMP version is affected?
This has always been an issue.
/to @jridgewell
Thanks for the detailed bug report @jerimiahwelch and laying out possible solutions! I am assigning to @jridgewell to move this forward.
Hi @jridgewell , @aghassemi,
I'm concerned that I made this request too broad.
I'm trying to get rid of the jank on fixed elements in amp pages as shown in this video: https://www.youtube.com/watch?v=gAFD_wS0wg4
Would this get resolved more quickly I make a specific bug request to remove !important from this rule that is causing the jank?
html.i-amphtml-ios-embed.i-amphtml-ios-overscroll,
html.i-amphtml-ios-embed.i-amphtml-ios-overscroll>#i-amphtml-wrapper{
-webkit-overflow-scrolling:touch!important
}
This bug affects all iOS users on several of our sites. We are guessing it affects about half a million people a week, so I'd like to resolve it soon.
Thank you, Jerimiah
Oo, seem to have missed this since it was posted late on Friday. Reviewing it now.
First, what's GSR?
Second, it seems this is two different bugs:
- Fixed-position elements in AMP on iOS sucks
- Transferred fixed-position elements don't update with amp-bind. /cc @choumx
As for the suggested fix (allowing overridable overflow-scrolling), I don't think we'd be willing to degrade the scroll experience any further. A very common criticism of AMP is that the scroll experience was different than normal Safari (it used to be inconsistent with Safari, because Safari was inconsistent with everything else in iOS). Allowing pages to take away inertia scrolling seems like we'd be regressing even further.
To address a few points:
Fixed elements shown in the main body after page load display in a juttery way.
We're hopeful that this won't be the case in iOS 11. I haven't yet done the legwork with testing multiple documents.
Moving elements to this fixed layer takes processing time on startup
Unfortunately, even without the fixed-layer transfer, we still need to do the same startup processing to find fixed-position elements. This is because we need to offset the top of fixed-position-top elements due to the Viewer's header bar.
Fixed layers are difficult to quickly and accurately test before publishing the site.
We have an open issue to unify the various iOS viewport hacks, so the iframe'd viewport is always used in iOS. That would eliminate any differences between local testing, and actually publishing the document.
Justin,
First, what's GSR?
Sorry about the acronym - GSR = "Google Search Results"
Splitting this into two different bugs is fine with me.
Allowing pages to take away inertia scrolling seems like we'd be regressing even further.
I was hoping for a quick solution, but the reason I included a list of needs was so that you could find creative solutions that meet the needs.
However, if it comes down to a choice between fixed element jutter and intertial scrolling, we would choose stable fixed elements. Juttery fixed elements are very noticeable while not having inertial scrolling is a more subtle thing to notice. We are certainly getting criticized for juttery elements on iOS.
We're hopeful that this won't be the case in iOS 11.
We still have a large portion of our audience on iOS 9 and iOS10. I would prefer not to ignore them.
We have an open issue to unify the various iOS viewport hacks, so the iframe'd viewport is always used in iOS
I applaud your push for consistency and testability on that thread.
Should I start a separate bug for amp-bind not updating fixed elements in iOS Google Search Results?
Perhaps this is helpful:
Our first attempt to solve this problem involved creating a single, full-screen fixed element that contained all of the "fixed" elements on the page as absolutely positioned children. Our hope was that this parent fixed container would get moved to the "pseudo-fixed" element in iOS. However, it wasn't moved because it 1) was transparent and 2) was over 300px high.
If there was a way we could flag a fixed parent element and promise that it is the only fixed element that needs moved, the amp runtime would only have to worry about positioning one element relative to the Viewer's header bar. We could layer our fixed layers and have a stable DOM. The amp-runtime could run more quickly on startup.
However, if it comes down to a choice between fixed element jutter and intertial scrolling, we would choose stable fixed elements. Juttery fixed elements are very noticeable while not having inertial scrolling is a more subtle thing to notice. We are certainly getting criticized for juttery elements on iOS.
/cc @cramforce, @dvoytenko, who'll need to make this decision.
We have an open issue to unify the various iOS viewport hacks, so the iframe'd viewport is always used in iOS
I'm getting internal bug reports about this too, I'll reprioritize to see if we can go this way.
Should I start a separate bug for amp-bind not updating fixed elements in iOS Google Search Results?
That'd be great. 😃
Our hope was that this parent fixed container would get moved to the "pseudo-fixed" element in iOS.
That might have captured all click events...
However, it wasn't moved because it 1) was transparent and 2) was over 300px high.
Maybe we can see about loosening the transfer restrictions?
To @dvoytenko :)
@jridgewell,
It looks like #14888 is being addressed.
Any progress on choosing an approach and a person to solve the jutter issue?
Here is the problem: https://www.youtube.com/watch?v=gAFD_wS0wg4
Here are options that have been discussed:
- Remove the important on this rule:
html.i-amphtml-ios-embed.i-amphtml-ios-overscroll, html.i-amphtml-ios-embed.i-amphtml-ios-overscroll>#i-amphtml-wrapper{ -webkit-overflow-scrolling:touch!important } - Allow for publishers to add an attribute signaling which elements should be moved to a pseudo-fixed container.
- Put all fixed elements in a single fixed container and move that to the pseudo-fixed container.
- Loosening fixed layer transfer restrictions.
- Authoring amp pages with the iOS pseudo-fixed structure to begin with so fixed elements don't need to be scanned for and moved.
- Any other approaches?
All,
However, it wasn't moved because it 1) was transparent and 2) was over 300px high.
I think it's fine to remove some of these restrictions, but we should be careful. Perhaps the this option is better:
Allow for publishers to add an attribute signaling which elements should be moved to a pseudo-fixed container.
I.e. we could add an attribute trasfer-fixed and default it to auto with current rules. And define true/false to control it directly.
Remove the important from
-webkit-overflow-scrolling:touch!important
This is hard to swallow since the iOS scrolling is very complicated. Did anyone check what's the actual behavior for this now? Last time I checked, the non-inertia scrolling was really really bad on iOS. Not sure where iOS 11 is now. If it's improving on iOS, I could advise a way or two to do something like this. So, please someone concern.
Authoring amp pages with the iOS pseudo-fixed structure to begin with so fixed elements don't need to be scanned for and moved.
It'd seem to me that this can partially be achieved now?
Ultimately, we could go here from iOS 11. If the fixed transfer is no longer needed - the best path would be to:
a. Remove transfer completely from iOS 11 b. Start removing restrictions before iOS 9/10 and possibly consider allowing non-inertia scrolling on opt-in.
Here is a video showing Inertial Scrolling(left) vs non-Inertial Scrolling (right) on iOS 9 and iOS10 in Google Search Results amp-viewer.
https://www.youtube.com/watch?v=gAFD_wS0wg4
If you expand the video to high quality, you can see the css rule applied to each page.
Scrolling in iOS 11 google search results amp-viewer currently behaves like the phone on the right in the video. You can sample scrolling on different iOS devices using this page:
https://www.google.com/amp/s/amp.docusearch.com/how-to-find-a-social-security-number-online.html
I'm confused. Do we have inertial scrolling turned on, or not? I believe we do; and it should behave the same as regular body scrolling as of iOS 11.
Do we have inertial scrolling turned on, or not? it should behave the same as regular body scrolling as of iOS 11.
We do, and it does.
But iOS 11 still uses non-inertia scrolling for inner boxes by default.
I.e. we could add an attribute trasfer-fixed and default it to auto with current rules. And define true/false to control it directly.
I'm ok with this route.
This is hard to swallow since the iOS scrolling is very complicated. Did anyone check what's the actual behavior for this now?
It's the same as before, still sucks.
Ultimately, we could go here from iOS 11. If the fixed transfer is no longer needed - the best path would be to:
Testing with the more expensive page, it seems #11900 is incorrect and the transfer is still needed in iOS 11. 😞
Any progress on this?
This issue seems to be in Pending Triage for awhile. @jridgewell Please triage this to an appropriate milestone.
This issue hasn't been updated in awhile. @jridgewell Do you have any updates?
Hi! I was wondering if there are any updates on the issue and what solutions are we exploring!