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

[Announcement bar] Slides animation. #2595

Merged
merged 38 commits into from
Jun 28, 2023
Merged

Conversation

eugenekasimov
Copy link
Contributor

@eugenekasimov eugenekasimov commented May 1, 2023

PR Summary:

This PR adds animation for slides in the announcement bar.

Why are these changes introduced?

Fixes #2550.

What approach did you take?

  1. Changed scroll-behavior: from smooth to auto to prevent the current way of visual animation.
  2. Added classes describing animation behaviour and keyframed them.
  3. In JS added a few methods to apply animation and update the current slide in the announcement bar. Added a delay for changing slides to give some time for animation.

Other considerations

Visual impact on existing themes

Before

After

Testing steps/scenarios

  • Add a few announcements to the announcement bar.
  • Go through slides back and forth and make sure that it responds right. When you click for the next slide it should be shifting to the left and vice versa.
  • Make sure that when you reach the last slide and keep clicking next it should return you to the first slide with opposite animation as though you clicked to the previous one. Same rule applies when clicking backward.
  • In the settings set the slider for auto-rotating. Make sure that animation works properly.
  • Add the slideshow section and make sure that the current changes don't affect it.

Demo links

Checklist

@eugenekasimov eugenekasimov force-pushed the animation-announcement-bar branch from f8bc819 to 758ccb6 Compare May 1, 2023 16:42
@eugenekasimov eugenekasimov force-pushed the animation-announcement-bar branch from 6541e4e to 50069e5 Compare May 10, 2023 16:45
@eugenekasimov eugenekasimov force-pushed the animation-announcement-bar branch from 1932286 to 1b40cdf Compare May 15, 2023 18:35
@eugenekasimov eugenekasimov changed the title [Announcement bar] Prototype of slider animation. [Announcement bar] Slides animation. May 15, 2023
@eugenekasimov eugenekasimov self-assigned this May 18, 2023
@ludoboludo ludoboludo self-requested a review June 5, 2023 16:22
@eugenekasimov eugenekasimov requested a review from YoannJailin June 5, 2023 16:25
@KaichenWang KaichenWang self-requested a review June 6, 2023 16:16
Copy link
Contributor

@ludoboludo ludoboludo left a comment

Choose a reason for hiding this comment

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

Just reviewed the CSS, sharing some initial thoughts

Copy link
Contributor

@KaichenWang KaichenWang left a comment

Choose a reason for hiding this comment

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

The animation looks good! Left some code suggestions.

Also, I noticed if I click next a few times quickly, the animation for returning to the 1st announcement is not playing at the correct moment anymore (between slide 4 -> 5, instead of 5 -> 1)

screencast.2023-06-06.18-33-45.mp4

assets/global.js Outdated
setTimeout(() => {
slide.classList.add(`announcement-bar-slider--fade-in-next`);
}, 200);
setTimeout(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can some of these setTimout be avoided if we leverage animation delay?

Copy link
Contributor Author

@eugenekasimov eugenekasimov Jun 7, 2023

Choose a reason for hiding this comment

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

I tried but I couldn't find a way to make it work.

Copy link
Contributor

@KaichenWang KaichenWang Jun 7, 2023

Choose a reason for hiding this comment

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

Ok I think we can keep the setTimeout. One other question is why we need to apply animation classes on every slide on every button click? Could we only need to apply animation on the outgoing and incoming slide?

@eugenekasimov
Copy link
Contributor Author

@ludoboludo @KaichenWang

I pushed updates. I tried to account for your suggestions regarding CSS and combined them.

@KaichenWang , regarding this quick clicking issue I think it's a very edge case and you really need to click faster than 200ms to reproduce it. I don't think it's reasonable to cover that case 🤔.

assets/global.js Outdated
setTimeout(() => {
slide.classList.add(`announcement-bar-slider--fade-in-next`);
}, 200);
setTimeout(() => {
Copy link
Contributor

@KaichenWang KaichenWang Jun 7, 2023

Choose a reason for hiding this comment

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

Ok I think we can keep the setTimeout. One other question is why we need to apply animation classes on every slide on every button click? Could we only need to apply animation on the outgoing and incoming slide?

Copy link
Contributor

@ludoboludo ludoboludo left a comment

Choose a reason for hiding this comment

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

Sharing my current feeling on the approach.

Curious of your thoughts as well as @KaichenWang's

@KaichenWang
Copy link
Contributor

@eugenekasimov

regarding this quick clicking issue I think it's a very edge case and you really need to click faster than 200ms to reproduce it. I don't think it's reasonable to cover that case

We can open a separate issue for this. Agreed it's an edge case, but we should try to understand why it's happening.

Copy link
Contributor

@KaichenWang KaichenWang left a comment

Choose a reason for hiding this comment

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

Looks good!

Tested:

  • Announcement bar
  • Slideshow section
  • Complementary products

@KaichenWang KaichenWang requested a review from ludoboludo June 20, 2023 21:02
eugenekasimov and others added 3 commits June 21, 2023 08:44
* Rename announcement-bar to utility-bar section.
Add basic logic for social-icons in the utility-bar.

* Remove social icons from the utility bar for tablet

Remove social icons snippet

* Prevent auto-rotation after users interact with arrow buttons.

Change the slider width for screens wider than 1200px.

Rename back a file name from utility-bar to announcement-bar.

* Prevent auto-rotation for mobile.

Reduce social icons sizes for in the utility bar.

Change grid system.

* Prevent showing bottom-border when the utility bar is empty.

* Add layout for screens under 1200px.

* Adjust a separater line for max-width: 1199px

* Revert announcement-bar name. Remove additional layout for desktop under 1120px. Remove JS logic.

* Minor changes.

* Refactor of css classes.

Refactor of liquid logic.

Use social-icons as a snippet.

* Refactor in social-icons snippet.

Change the naming in css accordingly BEM.

* Update 14 translation files

* Update 6 translation files

* Change label for show_social.

* Update 15 translation files

* Update 5 translation files

---------

Co-authored-by: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>
* Use live region to announce recipient form

* Inject text instead of toogling aria-hidden

* Announce form collapsed when checkbox unticked

* Update 20 translation files

* Update 4 translation files

* Update 6 translation files

---------

Co-authored-by: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>
Copy link
Contributor

@ludoboludo ludoboludo left a comment

Choose a reason for hiding this comment

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

Most of my comments are nitpicks but there is one for iOS/Safari that I think we would sort before shipping ideally.

Comment on lines +800 to +802
this.slider.scrollTo({
left: position,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we use the new function you added here ? setSlidePosition(position)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

inside itself?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh no, I didn't realize. It got me confused cause the function is so similar for the SliderComponent and SlideshowComponent. And named the same way as well though does it differently, one with a timeout and one without.

assets/global.js Outdated
this.announcementBarSlider = this.querySelector('.announcement-bar-slider');
// Value below should match --duration-announcement-bar CSS value
this.delay = this.announcementBarSlider ? 250 : 0;
this.sliderTransitionSelector = 'slider--transition';
Copy link
Contributor

Choose a reason for hiding this comment

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

There is something I'm seeing on Safari for the last slide:

RPReplay_Final1687374243.MP4

this.setSlidePosition(this.slideScrollPosition);

this.appleAnimationToAnnouncementBar(event.currentTarget.name);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

One thing I noticed is that all the logic is added to be tackled onButtonClick when it should also be running on scroll/swipe 😬

If you use it on mobile and swipe instead of you will see that it doesn't apply all the changes necessary.

So I think you could either look into:

  • applying some of the announcement-bar-slider--fade-*** class in liquid by default. Since you know which slide will be showing on page load and which ones won't.
  • look at applying the same transitions in the update() function where it's checking what is the current page and what's the previous page. If you apply the logic you added to onButtonClick there it should work in all cases. Tho it might be triggered too late compared to when the button is clicked 🤔

From what I'm seeing it's working ok on page load. No animation is applied but at least all slides are being shown. If you click on the previous or next button though, and then swipe later, the slides are hidden. Ideally they would work whatever the method you're using to go to the next slide is.

RPReplay_Final1687551919.MP4

Copy link
Contributor Author

@eugenekasimov eugenekasimov Jun 23, 2023

Choose a reason for hiding this comment

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

Thanks for flagging this Ludo.

This is happening because when you start scrolling/swiping we don't apply animation but some slides still have animation classes because we remove them only with the next cycle. I added code to prevent it. Now it looks good to me.

I would not apply animation for cases when we scroll/swipe because I think it looks better and more natural to have the effect we have now for scrolling.

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think having the animation on scroll/swipe would be good but I don't think we should delay this PR more for it. It could be a thing we look into adding in the future.

Copy link
Contributor

@ludoboludo ludoboludo left a comment

Choose a reason for hiding this comment

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

Looking good, just gotta remove a console log 👍

this.setSlidePosition(this.slideScrollPosition);

this.appleAnimationToAnnouncementBar(event.currentTarget.name);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think having the animation on scroll/swipe would be good but I don't think we should delay this PR more for it. It could be a thing we look into adding in the future.

Copy link
Contributor

@KaichenWang KaichenWang left a comment

Choose a reason for hiding this comment

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

🚀

@eugenekasimov eugenekasimov merged commit b9a36ab into main Jun 28, 2023
@eugenekasimov eugenekasimov deleted the animation-announcement-bar branch June 28, 2023 16:15
phapsidesGT pushed a commit to Gravytrain-UK/gt-shopify-dawn-theme that referenced this pull request Sep 3, 2024
* Add animation to the announcement bar.

* Add animation for the current and next slides.

* Make animation works for auto-rotating.

* Ensure the slider rotates in reverse when it reaches the end/begining.

* Add condition to apply delay for announcement-bar only

* Refactor and update some logic.

* Refactoring.

* Remove unneccessary css code.

* Refactor css. Change the order.

* Refactor JS.

* Refactor css.

* Isolate all logic in slideshowComponent.

* Simplify applyAnimation method.

* Reuse currentPage

* Apply animation on selected slides.

* Adjust duration of animation and shifting.

* Refactoring

* Another refactoring

* Remove timeout and add delay in css

* Refactoring

* Add no-js

* Prevent snapping during animation

* Fix auto-rotation positioning

* Refactor applyAnimation

* Refactor and remove unused elements

* [Announcement bar] Add social icons (Shopify#2497)

* Rename announcement-bar to utility-bar section.
Add basic logic for social-icons in the utility-bar.

* Remove social icons from the utility bar for tablet

Remove social icons snippet

* Prevent auto-rotation after users interact with arrow buttons.

Change the slider width for screens wider than 1200px.

Rename back a file name from utility-bar to announcement-bar.

* Prevent auto-rotation for mobile.

Reduce social icons sizes for in the utility bar.

Change grid system.

* Prevent showing bottom-border when the utility bar is empty.

* Add layout for screens under 1200px.

* Adjust a separater line for max-width: 1199px

* Revert announcement-bar name. Remove additional layout for desktop under 1120px. Remove JS logic.

* Minor changes.

* Refactor of css classes.

Refactor of liquid logic.

Use social-icons as a snippet.

* Refactor in social-icons snippet.

Change the naming in css accordingly BEM.

* Update 14 translation files

* Update 6 translation files

* Change label for show_social.

* Update 15 translation files

* Update 5 translation files

---------

Co-authored-by: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>

* Use live region to announce recipient form (Shopify#2672)

* Use live region to announce recipient form

* Inject text instead of toogling aria-hidden

* Announce form collapsed when checkbox unticked

* Update 20 translation files

* Update 4 translation files

* Update 6 translation files

---------

Co-authored-by: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>

* Safari fix and addressing feadback

* Correct typo

* Remove unnecessary code

* Prevent applying animation when you scroll

* Remove console.log

* Refactoring

---------

Co-authored-by: Ludo <[email protected]>
Co-authored-by: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>
Co-authored-by: Fred Ma <[email protected]>
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.

Announcement bar: Tweak slideshow animation
5 participants