-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Implement Visibility API #2212
Implement Visibility API #2212
Conversation
Assigning to @dvoytenko, but we're waiting to merge this until later this week. |
2013b58
to
40bd5f7
Compare
/** | ||
* TODO | ||
*/ | ||
UNLOADED: 'unloaded', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better term for this might be "background". This state only triggers when the browser tab that displays the viewer/doc is not active (another tab is).
40bd5f7
to
aac902a
Compare
PTAL. |
Looking... |
@@ -445,7 +452,40 @@ export class Viewer { | |||
* @return {!VisibilityState} | |||
*/ | |||
getVisibilityState() { | |||
return this.visibilityState_; | |||
// The viewer has informed us that the doc is no longer active, meaning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's store a single and correct this.visibilityState_
(point of reference) and recalculate it only when something changes.
Looks great! Some comments... |
f28fb6c
to
dbda708
Compare
PTAL. |
dbda708
to
bffaf1a
Compare
this.visibilityState_; | ||
log.fine(TAG_, '- visibilityState:', this.visibilityState_); | ||
this.setVisibilityState_(this.params_['visibilityState'], | ||
/* opt_fix_unloaded */ true, /* opt_skip_fire */ true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opt_camelCase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to worry about skipFire
in this case (or maybe never?) - here we know that the list of listeners is empty :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is fixedUnloaded really true
here? Seems like the initial hidden
would indicate instead the prerendering state, not unloaded.
@jridgewell this looks awesome! I just would like to do these few steps:
|
bffaf1a
to
cc90d19
Compare
cc90d19
to
a5b7a0f
Compare
I had to backtrack a bit and do a bit of computation in |
*/ | ||
VISIBLE: 'visible', | ||
|
||
/** | ||
* Viewer has indicated that AMP document is hidden. | ||
* The AMP document is active but the browser tab is not. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"but the browser tab or an AMP app is not"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
Great! Some doc changes, clear up getter and setter and confirm if we need flush and we're at lgtm. |
40270a7
to
69e8e2a
Compare
@@ -251,7 +268,7 @@ export class Viewer { | |||
this.hasBeenVisible_ = this.isVisible(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line has to be called after this.recheckVisibilityState_()
call, otherwise it will misreport. Probably just better to call recheckVisibilityState_()
as soon as viewerVisibilityState_
and docState_
are initialized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Great! It looks like there's one small bug to be fixed with the sequence of initializations. But otherwise LGTM! |
238307a
to
1c63939
Compare
Implements a “standardized” visibility API with control from the viewer and browser document. - Allows the Viewer to send the `paused` state when the users swipes between AMP docs. (closes ampproject#1655, ampproject#1538) - Adds the `prerender` visibility state when the AMP document has not been shown yet. - Adds the `inactive` visibility state when the AMP document is not active. - Changes the `hidden` visibility to mean the AMP doc is active but the browser tab is not visible.
1c63939
to
0b66e51
Compare
Implements a “standardized” visibility API with control from the viewer
and browser document.
paused
state when the users swipesbetween AMP docs. (closes Add PAUSED VisibilityState #1655, add a 'paused' visibility state #1538)
inactive
visibility state when the AMP document is notactive
hidden
visibility to mean the AMP doc is active but thebrowser tab is not visible.