Giter VIP home page Giter VIP logo

Comments (2)

ef4 avatar ef4 commented on August 26, 2024

The thing that the library tries very hard to achieve is making sure that your transition will start running before the browser gets to paint. We do this by always using microtasks. Compliant browsers will not paint while there are pending microtasks.

Once a transition is running, paints will happen, so you do need to use the start of the transition to get things into the right style.

That said, insertedSprites are supposed to begin hidden by default, and they don't appear until you apply the first motion to them. So maybe we have a bug. See the places where we call reveal() and hide() on Sprite.

from ember-animated.

napafundi avatar napafundi commented on August 26, 2024

Just wanted to drop in and say this is still happening with [email protected] and [email protected]

Here's a minimum reproducible example:

import { fadeIn, fadeOut } from 'ember-animated/motions/opacity';

export default class AnimatedIfCustomTransition extends Component {
    @tracked itemVisible = false;

    customTransition = function* ({ insertedSprites, removedSprites, keptSprites, duration }: TransitionContext) {
        yield Promise.all(
            removedSprites.map((sprite) => {
                return fadeOut(sprite, { duration: duration / 2 });
            })
        );
        for (let sprite of insertedSprites.concat(keptSprites)) {
            fadeIn(sprite, { duration: duration / 2 });
        }
    };

    @action
    toggleItemVisible(val: boolean) {
        this.itemVisible = val;
    }
}
<div>
    <button
        class="btn btn-primary"
        {{on "click" (fn this.toggleItemVisible (not this.itemVisible))}}
        type="button"
    >Click Me!</button>
    <div class="mt-3">
        <AnimatedContainer>
            {{#animated-if this.itemVisible use=this.customTransition duration=750}}
                <div>Lorem ipsum genie magic!</div>
            {{else}}
                <div>Watch me animate!</div>
            {{/animated-if}}
        </AnimatedContainer>
    </div>
</div>

As stated in the original comment, applying an opacity of 0 at the start of the animation fixes things:

customTransition = function* ({ insertedSprites, removedSprites, keptSprites, duration }: TransitionContext) {
        for (let sprite of insertedSprites.concat(keptSprites)) {
            sprite.applyStyles({ opacity: '0' });
        }
        yield Promise.all(
            removedSprites.map((sprite) => {
                return fadeOut(sprite, { duration: duration / 2 });
            })
        );
        for (let sprite of insertedSprites.concat(keptSprites)) {
            fadeIn(sprite, { duration: duration / 2 });
        }
    };

from ember-animated.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.