UNPKG

1.22 kBPlain TextView Raw
1'use strict';
2
3import type { LockAxis, ScreenTransitionConfig } from './commonTypes';
4import { configureProps } from '../../ConfigHelper';
5import { applyStyle } from './styleUpdater';
6import { getSwipeSimulator } from './swipeSimulator';
7
8configureProps();
9
10export function startScreenTransition(
11 screenTransitionConfig: ScreenTransitionConfig
12) {
13 'worklet';
14 const { stackTag, sharedEvent } = screenTransitionConfig;
15 sharedEvent.addListener(stackTag, () => {
16 applyStyle(screenTransitionConfig, sharedEvent.value);
17 });
18}
19
20function getLockAxis(goBackGesture: string): LockAxis {
21 'worklet';
22 if (['swipeRight', 'swipeLeft', 'horizontalSwipe'].includes(goBackGesture)) {
23 return 'x';
24 } else if (
25 ['swipeUp', 'swipeDown', 'verticalSwipe'].includes(goBackGesture)
26 ) {
27 return 'y';
28 }
29 return undefined;
30}
31
32export function finishScreenTransition(
33 screenTransitionConfig: ScreenTransitionConfig
34) {
35 'worklet';
36 const { stackTag, sharedEvent, goBackGesture } = screenTransitionConfig;
37 sharedEvent.removeListener(stackTag);
38 const lockAxis = getLockAxis(goBackGesture);
39 const step = getSwipeSimulator(
40 sharedEvent.value,
41 screenTransitionConfig,
42 lockAxis
43 );
44 step();
45}