-
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
No previous from tap on card on desktop #12671
Changes from 6 commits
73ce974
b691356
133d5c9
c7774b5
4584157
a9db922
c6df609
9245e5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ import {dict} from '../../../src/utils/object'; | |
import {renderSimpleTemplate} from './simple-template'; | ||
import {MediaPool, MediaType} from './media-pool'; | ||
import {PaginationButtons} from './pagination-buttons'; | ||
|
||
import {TapNavigationDirection} from './page-advancement'; | ||
|
||
|
||
/** @private @const {string} */ | ||
|
@@ -345,6 +345,21 @@ export class AmpStory extends AMP.BaseElement { | |
this.ampStoryHint_.showFirstPageHintOverlay(); | ||
}); | ||
|
||
this.element.addEventListener(EventType.TAP_NAVIGATION, e => { | ||
const {direction} = e.detail; | ||
|
||
if (this.isDesktop_()) { | ||
this.next_(); | ||
return; | ||
} | ||
|
||
if (direction === TapNavigationDirection.NEXT) { | ||
this.next_(); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can you explicitly check that this is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
this.previous_(); | ||
} | ||
}); | ||
|
||
const gestures = Gestures.get(this.element, | ||
/* shouldNotPreventDefault */ true); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,11 @@ const NEXT_SCREEN_AREA_RATIO = 0.75; | |
/** @const {number} */ | ||
const POLL_INTERVAL_MS = 250; | ||
|
||
/** @const @enum */ | ||
export const TapNavigationDirection = { | ||
'NEXT': 1, | ||
'PREVIOUS': 2, | ||
}; | ||
|
||
/** | ||
* Base class for the AdvancementConfig. By default, does nothing other than | ||
|
@@ -45,6 +50,9 @@ export class AdvancementConfig { | |
/** @private @const {!Array<function()>} */ | ||
this.previousListeners_ = []; | ||
|
||
/** @private @const {!Array<function(number)>} */ | ||
this.tapNavigationListeners_ = []; | ||
|
||
/** @private {boolean} */ | ||
this.isRunning_ = false; | ||
} | ||
|
@@ -75,6 +83,14 @@ export class AdvancementConfig { | |
this.previousListeners_.push(previousListener); | ||
} | ||
|
||
/** | ||
* @param {function(number)} onTapNavigationListener A function that handles when a | ||
* navigation listener to be fired. | ||
*/ | ||
addOnTapNavigationListener(onTapNavigationListener) { | ||
this.tapNavigationListeners_.push(onTapNavigationListener); | ||
} | ||
|
||
/** | ||
* Invoked when the advancement configuration should begin taking effect. | ||
*/ | ||
|
@@ -127,6 +143,16 @@ export class AdvancementConfig { | |
}); | ||
} | ||
|
||
/** | ||
* @param {number} navigationDirection Direction of navigation | ||
* @protected | ||
*/ | ||
onNavigate(navigationDirection) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. onTapNavigation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
this.tapNavigationListeners_.forEach(navigationListener => { | ||
navigationListener(navigationDirection); | ||
}); | ||
} | ||
|
||
/** | ||
* Provides an AdvancementConfig object for the specified amp-story-page. | ||
* @param {!./amp-story-page.AmpStoryPage} page | ||
|
@@ -287,9 +313,9 @@ class ManualAdvancement extends AdvancementConfig { | |
const nextScreenAreaMax = offsetLeft + offsetWidth; | ||
|
||
if (event.pageX >= nextScreenAreaMin && event.pageX < nextScreenAreaMax) { | ||
this.onAdvance(); | ||
this.onNavigate(TapNavigationDirection.NEXT); | ||
} else if (event.pageX >= offsetLeft && event.pageX < nextScreenAreaMin) { | ||
this.onPrevious(); | ||
this.onNavigate(TapNavigationDirection.PREVIOUS); | ||
} | ||
} | ||
} | ||
|
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.
nit:
navigateOnTap
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.
Done!