sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
78.94k stars 4.15k forks source link

Flag to wait for out transition to finish before 'in' start #8978

Open Moonlander1 opened 1 year ago

Moonlander1 commented 1 year ago

Describe the problem

Having an element inside a key tag plays both its in and out transition. I feel most of the time you want them to play after each other and not simultaneously. It can easily be done by setting the delay on the in transition for the duration of the out transition, however when the duration varies for example on the text's length a lot of extra steps are needed to overcome this challange and does not scale at all.

Example:

{#key random_text}
    <h3 out:typewriter in:typewriter> {random_text} </h3>
{/key}

Describe the proposed solution

An easy solution would be to add a flag to the in transition to wait for the out transition.

Alternatives considered

Another fix could be to have the old value of the key accessable in the block, then the same calculations could be performed and it would give more flexibility.

Importance

would make my life easier

elron commented 1 year ago

did you try |global ?

Moonlander1 commented 1 year ago

did you try |global ?

I'm not sure what you are referring to

elron commented 1 year ago

I'm referring to this <h3 out:typewriter|global in:typewriter|global> {random_text} </h3>

Moonlander1 commented 1 year ago

I'm referring to this <h3 out:typewriter|global in:typewriter|global> {random_text} </h3>

That's not really related to the problem. The problem isn't triggering the animation, rather the overlap of the in and out animation. If you don't know the exact duration of the out aniamtion you can't delay the in animation so the new and old element overlap ruining the layout for the duration of the overlap.