Skip to content
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

sticky-ad IOS scrolling issue fix #3700

Merged
merged 9 commits into from Jun 28, 2016
Merged

sticky-ad IOS scrolling issue fix #3700

merged 9 commits into from Jun 28, 2016

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Jun 21, 2016

fix the issue that amp-sticky-ad disappear before it shows amp-ad.
But ad still only displays after scrolling is fully stopped.
#3599

@@ -28,6 +28,7 @@ amp-sticky-ad {
}

.-amp-sticky-ad-layout {
visibility: hidden;
Copy link
Contributor Author

@zhouyx zhouyx Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we prevent this from being customized?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!important

Copy link
Contributor Author

@zhouyx zhouyx Jun 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That also prevent myself from setting it to visible.
Here's my solution:
this.element.classList.add('-amp-sticky-ad-display')
.-amp-sticky-ad-display { visibility: visible !important; }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to set visible !important

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll have to set it to visible via a class as well. E.g.

.myclass {
  visibility: hidden !important;
}
.myclass.visible {
  visibility: visible !important;
}

@dvoytenko
Copy link
Contributor

@zhouyx Could you please explain why the issue is happening now? What causes the blink on iOS?

@jridgewell
Copy link
Contributor

But ad still only displays after scrolling is fully stopped.

Demo please. This worked perfectly for me before.

@zhouyx
Copy link
Contributor Author

zhouyx commented Jun 22, 2016

That probably needs one to scroll really fast.

@zhouyx zhouyx closed this Jun 22, 2016
@zhouyx zhouyx reopened this Jun 22, 2016
@jridgewell
Copy link
Contributor

Got it. The demo I was playing with earlier was not the current version of <stick-ad>, it had a transform: translateZ(0). That's the part that made the visibility changes paint immediately.

@zhouyx
Copy link
Contributor Author

zhouyx commented Jun 23, 2016

I don't remember putting transform: translateZ(0) to <amp-sticky-ad> anywhere. But if that solves the problem, can we adapt it?

@zhouyx
Copy link
Contributor Author

zhouyx commented Jun 23, 2016

Sadly I still haven't found the reason to the blink. Still looking for it, but it makes me really hard to debug because the issue only occurs when fetching amp-ad.js remotely. @dvoytenko

@dvoytenko
Copy link
Contributor

@zhouyx To confirm, however, according to the description of this PR it follows that switching from display to visibility solves the problem?

@zhouyx
Copy link
Contributor Author

zhouyx commented Jun 23, 2016

Yes, switching from display to visibility solves the blink problem

@zhouyx
Copy link
Contributor Author

zhouyx commented Jun 23, 2016

Discuss with @mkhatib, find one thing. Note to self.
By setting ownership of <amp-ad>, after user switch viewer and come back again w/o closing <amp-sticky-ad>, <amp-ad> layout need to be rescheduled by <amp-sticky-ad>

@zhouyx
Copy link
Contributor Author

zhouyx commented Jun 23, 2016

PTAL

@@ -160,7 +159,7 @@
</div>
</header>
<main role="main">
<amp-sticky-ad layout="nodisplay">
<amp-sticky-ad layout="container">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to specify layout=container - it's default. However, there's an issue here and why I'd like to go back to nodisplay. To start with, it does as as nodisplay. The second reason is that by the time the amp-sticky-ad code is done downloading the element might be actually visible, which could trigger all kind of issues that we don't want. Instead, we need to start with nodisplay, but as soon as amp-sticky-ad is initialized (buildCallback) to remove display:none and instead set visibility:hidden.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that before we get amp-sticky-ad css file, it might be treated as a normal div and would be visible.
changed the layout type back to nodisplay

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The blink comes back with display change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I see the updated code? The goal is to remove display:none and set visibility:hidden as soon as possible, e.g. in the buildCallback. I can't imagine the blink will still be there in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current code is updated. Here's what I found, after setting display:flex through css classList, I still find style = "display: none" on the HTML element.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add toggle(this.element, true) to buildCallback(), unfortunately I still see blink

@@ -38,21 +39,25 @@ class AmpStickyAd extends AMP.BaseElement {
dev.warn(TAG, `TAG ${TAG} disabled`);
return;
}

toggle(this.element, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should be done after the class is set below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed because the NODISPLAY layout? Why don't we change it to CONTAINER?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get this comment from @dvoytenko

No need to specify layout=container - it's default. However, there's an issue here and why I'd like to go back to nodisplay. To start with, it does as as nodisplay. The second reason is that by the time the amp-sticky-ad code is done downloading the element might be actually visible, which could trigger all kind of issues that we don't want. Instead, we need to start with nodisplay, but as soon as amp-sticky-ad is initialized (buildCallback) to remove display:none and instead set visibility:hidden.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@dvoytenko
Copy link
Contributor

@zhouyx The code looks fine now. At this point, since we remove display:none as soon as possible, I really do not understand the reason why it'd blink - there's simply no real difference here. One think we need to try and see if it helps: we need to move this.viewport_.addToFixedLayer(this.element); from where it is now to:

  1. Try to put it immediately after toggle(this.element, true) in the buildCallback
  2. Try to put it in the layoutCallback

If both (1) and (2) help - my preference is (2).

@@ -29,17 +29,21 @@ amp-sticky-ad {

.-amp-sticky-ad-layout {
display: flex;
visibility: hidden;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we forcing this with !important?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, will fix

@zhouyx
Copy link
Contributor Author

zhouyx commented Jun 28, 2016

PTAL

@jridgewell
Copy link
Contributor

LGTM.

@zhouyx zhouyx merged commit 8d079d5 into ampproject:master Jun 28, 2016
@zhouyx zhouyx deleted the ios-fix branch September 28, 2016 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants