Code Monkey home page Code Monkey logo

Comments (13)

BryanWilhite avatar BryanWilhite commented on June 21, 2024
ng generate app year-of-moo-animation --skip-tests --style=scss --dry-run

ng generate component components/index --flat=false --module=app --project=year-of-moo-animation --spec=false --styleext=scss --dry-run
ng generate component components/use-animation --flat=false --module=app --project=year-of-moo-animation --spec=false --styleext=scss --dry-run
ng generate component components/animation-builder --flat=false --module=app --project=year-of-moo-animation --spec=false --styleext=scss --dry-run

from unicorn-whale.

BryanWilhite avatar BryanWilhite commented on June 21, 2024

to switch apps for npm start the defaultProject config setting (in angular.json) has to be set; to check the current value:

ng config defaultProject

to set the value:

ng config defaultProject year-of-moo-animation

from unicorn-whale.

BryanWilhite avatar BryanWilhite commented on June 21, 2024

boom:

image

image

from unicorn-whale.

BryanWilhite avatar BryanWilhite commented on June 21, 2024

not managing players properly :(

from unicorn-whale.

BryanWilhite avatar BryanWilhite commented on June 21, 2024

i've noticed that @matsko never uses AnimationPlayer.reset() in his entire demo repository; in his sole example, showing the use of AnimationBuilder, he has a method, animateTo() that appears to not reuse instances of AnimationPlayer

when @matsko uses the term reusable he is almost always referring to reusable AnimationReferenceMetadata not reusable AnimationPlayer instances; nevertheless there is a reason why methods reset() and setPosition(0) exist on AnimationPlayer

from unicorn-whale.

BryanWilhite avatar BryanWilhite commented on June 21, 2024

the animation-builder demo is not working at all on Chrome; simultaneously a warning message in the console on Edge suggest that web-animations-js [NPM] is required

from unicorn-whale.

BryanWilhite avatar BryanWilhite commented on June 21, 2024

this is the pattern that is working:

image

slideBack(): void {
    this.photos.forEach(img => {
        const player = this.getImgPlayer(slideBackAnimation, img);
        player.play();
    });
}
slideForward(): void {
    this.photos.forEach(img => {
        const player = this.getImgPlayer(slideForwardAnimation, img);
        player.play();
    });
}

previously, i tried to store AnimationPlayer[] in a private field in order to loop through each and play() but this did not work on Chrome

my concern however is that these local instances of player might be stacking up in memory; i thought i was being clever by doing this:

player.onDone(() => player.destroy());

but this throws errors likely due to race conditions (then there is a temptation to delay the call with something like setTimeout but this feels like playing games)

from unicorn-whale.

BryanWilhite avatar BryanWilhite commented on June 21, 2024

this 'game' is working:

player.onDone(() => {
    console.log(`player ${player['id']} done`, player);
    setTimeout(() => player.destroy(), 500);
});

however, the final animation state is destroyed when the player is destroyed

more context around the above:

private getPlayer(
    animationMetadata: AnimationReferenceMetadata,
    el: Element
): AnimationPlayer {
    const factory = this.animationBuilder.build(animationMetadata);
    const x = el.clientWidth / 2;
    const player = factory.create(el, { params: { x: x } });
    player.onDestroy(() => console.log(`player ${player['id']} destroyed`));
    player.onDone(() => {
        console.log(`player ${player['id']} done`, player);
        setTimeout(() => player.destroy(), 500);
    });
    return player;
}

from unicorn-whale.

BryanWilhite avatar BryanWilhite commented on June 21, 2024

quick look at the reset() method:

this move does not pop the element back to where it started the animation on Edge—on Chrome it is fine:

player.onDone(() => {
    console.log(`player ${player['id']} done`, player);
    setTimeout(() => player.reset(), 500);
});

this is telling me, i need to resolve #8

from unicorn-whale.

BryanWilhite avatar BryanWilhite commented on June 21, 2024

for this particular example the goal post will be moved to show both of these scenarios:

  • reusing an animation player
  • using an animation player once (and destroying it before it is replaced)

the latter scenario is important when AnimationOptions.params need to change frequently for a given animation

from unicorn-whale.

BryanWilhite avatar BryanWilhite commented on June 21, 2024

this approach is not working:

slideDivBack(): void {
    const player = this.simpleBlockAnimationMeta.slideBackPlayer;
    if (player.hasStarted()) {
        player.reset();
    }
    player.play();
}
slideDivForward(): void {
    const player = this.simpleBlockAnimationMeta.slideForwardPlayer;
    if (player.hasStarted()) {
        player.reset();
    }
    player.play();
}

from unicorn-whale.

BryanWilhite avatar BryanWilhite commented on June 21, 2024

another approach: exclusively address the concern of using an animation player once (and destroying it before it is replaced)

the arguments passed to getPlayer() should contain a unique ID; this unique ID should be saved in a private array of { id: string, player: AnimationPlayer }

the catch is around generating the unique ID

from unicorn-whale.

BryanWilhite avatar BryanWilhite commented on June 21, 2024

this latest strategy appears to be working:

image

from unicorn-whale.

Related Issues (15)

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.