Skip to content

Commit

Permalink
feat(core): add waitTransition (#983)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarthificial committed Mar 11, 2024
1 parent 6bd072a commit 27f24e1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/src/transitions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
export * from './fadeTransition';
export * from './slideTransition';
export * from './useTransition';
export * from './waitTransition';
export * from './zoomInTransition';
export * from './zoomOutTransition';
31 changes: 31 additions & 0 deletions packages/core/src/transitions/waitTransition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {waitFor} from '../flow';
import {SignalValue} from '../signals';
import {ThreadGenerator} from '../threading';
import {useTransition} from './useTransition';

/**
* Perform a transition that doesn't do anything.
*
* @remarks
* This is useful when you want to achieve a transition effect by animating
* objects in the scenes. It will overlay the scenes on top of each other for
* the duration of the transition.
*
* @param duration - The duration of the transition.
* @param previousOnTop - Whether the previous scene should be rendered on top.
*/
export function* waitTransition(
duration = 0.6,
previousOnTop: SignalValue<boolean> = true,
): ThreadGenerator {
const endTransition = useTransition(
() => {
// do nothing
},
undefined,
previousOnTop,
);

yield* waitFor(duration);
endTransition();
}
5 changes: 5 additions & 0 deletions packages/docs/docs/getting-started/transitions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ All available transitions are listed below:
<ApiSnippet url={'/api/core/transitions#fadeTransition'} />
<hr />

### `waitTransition`

<ApiSnippet url={'/api/core/transitions#waitTransition'} />
<hr />

## Custom transitions

You can use the [`useTransition`](/api/core/transitions#useTransition) function
Expand Down

0 comments on commit 27f24e1

Please sign in to comment.