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

[Motion] No animation on added/edited section #2502

Merged
merged 14 commits into from
Apr 17, 2023

Conversation

ludoboludo
Copy link
Contributor

@ludoboludo ludoboludo commented Apr 7, 2023

PR Summary:

Prevent having animation while being in the editor.

Why are these changes introduced?

Fixes https://github.com/Shopify/themes/issues/400

What approach did you take?

I added some logic that only runs in the DOMContentLoaded listener, shopify:section:reorder, and shopify:section:load. So it should run when the page loads, when you're re ordering a section or when you're editing a section in the editor.
It adds a new class that overwrite the other ones.

Other considerations

At first I was thinking of removing the existing classes we had but I though it was cleaner/clearer to have a specific class to prevent fade in and slide in animations.

Decision log

# Decision Alternatives Rationale Downsides
1 Do not apply animation on elements in the viewport on page load Animate on page load all elements It can be a bit jarring to always have animated things show up. 🤷
2 Do not apply animation on elements being edited in the theme editor Animate elements everytime they reload it is not necessary to show the animation every time a merchant edit their section Merchant could wonder why the animation isn't applied when a section reloads

Visual impact on existing themes

In the editor, prevent a section from being animated anytime it's re rendered due to setting changes.

Testing steps/scenarios

  • Test in the editor while tweaking a section and/or its blocks

Demo links

Checklist

@kjellr kjellr self-requested a review April 7, 2023 17:11
@kjellr
Copy link
Contributor

kjellr commented Apr 7, 2023

This feels pretty good! @ludoboludo, how do you feel about the experience with these changes?

I do sort of miss the initial slide-in of some above-the-fold elements, but maybe that's because I've been seeing them slide in for so long now. Let's all test this and let it sit for a few days before we merge in.

@ludoboludo ludoboludo changed the title [Motion] No animation on elements in viewport [Motion] No animation on added/edited section Apr 11, 2023
@ludoboludo
Copy link
Contributor Author

After tweaking our animations which are feeling much nicer now, we agreed not to prevent them from happening for elements in the viewport on load. So this PR (description updated) is more about preventing the animation to happen when not necessary in the theme editor.

@kjellr
Copy link
Contributor

kjellr commented Apr 12, 2023

Thanks for revising the PR, @ludoboludo! This feels pretty good. Is it possible to turn off all the animations during this zoomed-out reorder state?

12-37-lgsho-g0iuh.mp4

document.addEventListener('shopify:section:load', (event) => initializeScrollAnimationTrigger(event.target));
if (Shopify.designMode) {
document.addEventListener('shopify:section:load', (event) => initializeScrollAnimationTrigger(event, event.target));
document.addEventListener('shopify:section:reorder', (event) =>
Copy link
Contributor Author

@ludoboludo ludoboludo Apr 13, 2023

Choose a reason for hiding this comment

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

@kjellr I added something for the section being re ordered. One thing to note, when I checked, I can only prevent the animation on the section I'm currently trying to re order. Any other section has the animation re running.

When I checked, section:load event wasn't triggered on other sections, so it must be a full page reload. I think it's ok though as long as the section we're currently moving around isn't animating every time we're moving it around.

Here is a little video of how it looks

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm ok. I'd definitely prefer to have the other animations stop on reorder too. Can we add a body class with some !important rules or something to disable all animations when you're in that mode or something? 😅

Either way, what we have here is an improvement, so happy to get this merged in and tackle improvements separately. I'll add an approval for now, with the caveat that if we come up with a quick fix to stop all animation on reorder, we should take it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok so I can actually do it by making it remove the animation from all present sections that usually do animate. One of the potential issue with this, is that if you're at the top of a page and you haven't fully scrolled down yet and triggered the animations and you're reordering one of your first section on the page, nothing will be animated on further navigation on this page until page reload.

Here is a video cause it's seem hard to explain without visual aid.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, nice work! This seems like a pretty good solution. From watching the video, I'm not concerned about the subsequent sections not animating. That seems like a reasonable tradeoff in this case. If you're happy with the dev solution, let's push it up here and test it out.

Copy link
Contributor

@kjellr kjellr left a comment

Choose a reason for hiding this comment

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

This generally looks good. Add a few additional notes in #2502 (comment).

@ludoboludo ludoboludo self-assigned this Apr 17, 2023
assets/animations.js Outdated Show resolved Hide resolved
assets/animations.js Outdated Show resolved Hide resolved
document.addEventListener('shopify:section:load', (event) => initializeScrollAnimationTrigger(event.target));
if (Shopify.designMode) {
document.addEventListener('shopify:section:load', (event) => initializeScrollAnimationTrigger(event, event.target));
document.addEventListener('shopify:section:reorder', (event) => initializeScrollAnimationTrigger(event));
Copy link
Contributor

Choose a reason for hiding this comment

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

If you don't pass in an element to initializeScrollAnimationTrigger it will create a new intersection observer for the entire document, which already has one from line 34. Can we just create the new observer for the section(s) that was reordered?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had it for the specific section in the first place but it worked in a way that only the re ordered section was not getting animated while every other section was (video).

What I did just now was adding an early return within my if statement. So that if the event triggering the initialization is coming from the editor ((re)load or reorder) so we're not observing more element as it's unnecessary since the classes applied prevent the animation from happening anyway.

e89ed02

assets/animations.js Outdated Show resolved Hide resolved
const animationTriggerElements = Array.from(rootEl.getElementsByClassName(SCROLL_ANIMATION_TRIGGER_CLASSNAME));
if (animationTriggerElements.length === 0) return;

if (isDesignMode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is isDesignMode simply Shopify.designMode or is there another use case where these won't be equal?

If they're the same thing, do we need this another variable/parameter instead of simply checking for Shopify.designMode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just changed the name based on your comment. It's not exactly Shopify.designMode but theme editor triggered events.

Cause for example you can be in the editor (Shopify.designMode = true) but we want to run some logic specifically for the section:load and section:reorder events.

Copy link
Contributor

@LucasLacerdaUX LucasLacerdaUX 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 to me now :D

@ludoboludo ludoboludo merged commit d032879 into main Apr 17, 2023
@ludoboludo ludoboludo deleted the no-animation-on-elements-in-viewport branch April 17, 2023 20:46
Roi-Arthur added a commit that referenced this pull request Apr 19, 2023
* [Motion] Use rootMargin instread of threshold to trigger slide in animations (#2517)

* Use rootMargin instread of threshold to trigger slide in animations

* address review comment, remove threshold

* Add conditional around data-cascade attribute (#2532)

* [Motion] No animation on added/edited section (#2502)

---------

Co-authored-by: Ludo <ludo.segura@shopify.com>
phapsidesGT pushed a commit to Gravytrain-UK/gt-shopify-dawn-theme that referenced this pull request Sep 3, 2024
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.

5 participants