Essentially I'm working on a slideshow project where each "slide" is loaded dynamically using <svelte:component this={currentSelection.component} />
. Each slide requires custom in and out transitions on a component-by-component basis. I'd like for the next slide to "wait" while the current slide finishes transitioning, however, as stated in the svelte documentation:
Unlike with transition:, transitions applied with in: and out: are not bidirectional — an in transition will continue to 'play' alongside the out transition, rather than reversing, if the block is outroed while the transition is in progress. If an out transition is aborted, transitions will restart from scratch.
Is there a sensible way to make the next slide "wait" until the current slide is finished with its outro transition?
Toy Example at REPL
Toy code posted for posterity:
//App.svelte
<script>
import RedThing from './RedThing.svelte';
import GreenThing from './GreenThing.svelte';
import BlueThing from './BlueThing.svelte';
const slides = [
RedThing,
BlueThing,
GreenThing
];
let currentComponent = 0;
const prev = () => currentComponent--;
const next = () => currentComponent++;
</script>
<button on:click={prev}>Prev</button><button on:click={next}>Next</button>
<div>
<svelte:component this={slides[currentComponent]}/>
</div>
//RedThing.svelte
<script>
import { fly, slide } from 'svelte/transition';
</script>
<style>
div { color: red; }
</style>
<div in:fly out:slide>red thing</div>
//GreenThing.svelte
<script>
import { fade, slide } from 'svelte/transition';
</script>
<style>
div { color: green; }
</style>
<div in:slide out:fade>green thing</div>
//BlueThing.svelte
<script>
import { scale, fade } from 'svelte/transition';
</script>
<style>
div { color: blue; }
</style>
<div in:scale out:fade>blue thing</div>
Edit: I should add a complication – I am driving component traversal through sapper anchor tags, which are taking care of component creation / destruction. In other words:
<a href={prev} id="previous-button">Previous</a>
<a href={next} id="next-button">Next</a>
<div>
<svelte:component this={slides[currentComponent]}/>
</div>
I'm not sure if that makes a difference?