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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
馃悰 amp-base-carousel: Update offset and index together #30963
Conversation
879f7c5
to
15148c3
Compare
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.
Looks good to me, leaving a comment to allow others to take a look too.
|
||
// Fake the scroll that ends short of the correct index. | ||
// This is handled by scroll event listener. | ||
carousel.touching_ = false; |
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.
Thank you for adding a comment here describing what the intent of these values are, nice touch!
describe('resetScrollReferencePoint_', () => { | ||
it('currentElementOffset_ & currentIndex_ should be set when it is a' + | ||
' programmatic scroll', async () => { | ||
setStyle(element, 'width', '299.2px'); |
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.
Does this condition happen only when the element width is not floored?
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.
No, this is actually unnecessary. I'll simplify.
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.
Thank you!
372629c
to
e6fc9b3
Compare
e6fc9b3
to
ba5d222
Compare
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.
LGTM. Thanks for adding e2e tests.
Closes #30905
When the viewport is barely bigger than the carousel (on the scrolling axis), the scroll listener will not receive the final event that would set
currentElementOffset_
andcurrentIndex_
to0
andn+1
(instead it would be set at something like-0.998
,n
).Then, when
resetScrollReferencePoint_()
is finally called, it will updatecurrentIndex_
to the correct value, but leavecurrentElementOffset_
to be referencing the old index value.amphtml/extensions/amp-base-carousel/0.1/carousel.js
Lines 1182 to 1187 in f479ea6
Then finally, when
restoreScrollStart_()
is called,deltaOffset
will not be 0, due toactualOffset
andcurrentElementOffset_
referencing 2 different elements (causing another shift in the carousel).amphtml/extensions/amp-base-carousel/0.1/carousel.js
Line 1229 in f479ea6