@@ -341,8 +341,8 @@ export class AmpStory extends AMP.BaseElement {
341341 /** @private @const {!../../../src/service/platform-impl.Platform} */
342342 this . platform_ = Services . platformFor ( this . win ) ;
343343
344- /** @private @const {!../../../src/service/document-state.DocumentState } */
345- this . documentState_ = Services . documentStateFor ( this . win ) ;
344+ /** @private @const {!../../../src/service/viewer-impl.Viewer } */
345+ this . viewer_ = Services . viewerForDoc ( this . element ) ;
346346
347347 /**
348348 * Store the current paused state, to make sure the story does not play on
@@ -751,9 +751,7 @@ export class AmpStory extends AMP.BaseElement {
751751 }
752752 } ) ;
753753
754- // TODO(#16795): Remove once the runtime triggers pause/resume callbacks
755- // on document visibility change (eg: user switches tab).
756- this . documentState_ . onVisibilityChanged ( ( ) => this . onVisibilityChanged_ ( ) ) ;
754+ this . viewer_ . onVisibilityChanged ( ( ) => this . onVisibilityChanged_ ( ) ) ;
757755
758756 this . getViewport ( ) . onResize ( debounce ( this . win , ( ) => this . onResize ( ) , 300 ) ) ;
759757 this . installGestureRecognizers_ ( ) ;
@@ -767,11 +765,9 @@ export class AmpStory extends AMP.BaseElement {
767765 // If the story is within a viewer that enabled the swipe capability, this
768766 // disables the navigation education overlay on the X axis to enable the
769767 // swipe to the next story feature.
770- const viewerService = Services . viewerForDoc ( this . element ) ;
771- const swipeRecognizer =
772- viewerService && viewerService . hasCapability ( 'swipe' )
773- ? SwipeYRecognizer
774- : SwipeXYRecognizer ;
768+ const swipeRecognizer = this . viewer_ . hasCapability ( 'swipe' )
769+ ? SwipeYRecognizer
770+ : SwipeXYRecognizer ;
775771
776772 // Shows "tap to navigate" hint when swiping.
777773 gestures . onGesture ( swipeRecognizer , gesture => {
@@ -956,7 +952,7 @@ export class AmpStory extends AMP.BaseElement {
956952 // Preloads and prerenders the share menu.
957953 this . shareMenu_ . build ( ) ;
958954
959- const infoDialog = Services . viewerForDoc ( this . element ) . isEmbedded ( )
955+ const infoDialog = this . viewer_ . isEmbedded ( )
960956 ? new InfoDialog ( this . win , this . element )
961957 : null ;
962958 if ( infoDialog ) {
@@ -976,7 +972,7 @@ export class AmpStory extends AMP.BaseElement {
976972 // Story is being prerendered: resolve the layoutCallback when the first
977973 // page is built. Other pages will only build if the document becomes
978974 // visible.
979- if ( ! Services . viewerForDoc ( this . element ) . hasBeenVisible ( ) ) {
975+ if ( ! this . viewer_ . hasBeenVisible ( ) ) {
980976 return whenUpgradedToCustomElement ( firstPageEl ) . then ( ( ) =>
981977 firstPageEl . whenBuilt ( )
982978 ) ;
@@ -1711,9 +1707,7 @@ export class AmpStory extends AMP.BaseElement {
17111707 * @private
17121708 */
17131709 onVisibilityChanged_ ( ) {
1714- this . documentState_ . isHidden ( )
1715- ? this . pauseCallback ( )
1716- : this . resumeCallback ( ) ;
1710+ this . viewer_ . isVisible ( ) ? this . resumeCallback ( ) : this . pauseCallback ( ) ;
17171711 }
17181712
17191713 /**
0 commit comments