Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Web LA] Add EntryExitTransition #6232

Merged
merged 19 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export interface TransitionData {
scaleX: number;
scaleY: number;
reversed?: boolean;
entering?: any;
exiting?: any;
}

export function convertAnimationObjectToKeyframes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,18 @@ export function tryActivateLayoutTransition<
return;
}

const enteringAnimation = (props.layout as CustomConfig).enteringV
?.presetName;
const exitingAnimation = (props.layout as CustomConfig).exitingV?.presetName;

const transitionData: TransitionData = {
translateX: snapshot.x - rect.x,
translateY: snapshot.y - rect.y,
scaleX: snapshot.width / rect.width,
scaleY: snapshot.height / rect.height,
reversed: false, // This field is used only in `SequencedTransition`, so by default it will be false
entering: enteringAnimation,
exiting: exitingAnimation,
};

startWebLayoutAnimation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ export function handleLayoutTransition(
case 'JumpingTransition':
animationType = TransitionType.JUMPING;
break;
case 'EntryExitTransition':
animationType = TransitionType.ENTRY_EXIT;
break;
default:
animationType = TransitionType.LINEAR;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ export interface CustomConfig {
callbackV?: AnimationCallback;
reversed?: boolean;
definitions?: KeyframeDefinitions;
enteringV?: any;
exitingV?: any;
}

export enum TransitionType {
LINEAR,
SEQUENCED,
FADING,
JUMPING,
ENTRY_EXIT,
}

export const AnimationsData: Record<string, AnimationData> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { SequencedTransition } from './transition/Sequenced.web';
import { FadingTransition } from './transition/Fading.web';
import { JumpingTransition } from './transition/Jumping.web';
import { insertWebAnimation } from './domUtils';
import { EntryExitTransition } from './transition/EntryExit.web';

type TransformType = NonNullable<TransformsStyle['transform']>;

Expand Down Expand Up @@ -108,13 +109,18 @@ export function TransitionGenerator(
transitionData
);
break;

case TransitionType.JUMPING:
transitionObject = JumpingTransition(
transitionKeyframeName,
transitionData
);
break;
case TransitionType.ENTRY_EXIT:
transitionObject = EntryExitTransition(
transitionKeyframeName,
transitionData
);
break;
}

const transitionKeyframe =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';
import type { AnimationData, TransitionData } from '../animationParser';
import { AnimationsData } from '../config';

export function EntryExitTransition(
name: string,
transitionData: TransitionData
) {
const exitingAnimationData = structuredClone(
AnimationsData[transitionData.exiting]
);
const enteringAnimationData = structuredClone(
AnimationsData[transitionData.entering]
);

const additionalData = {
translateX: `${transitionData.translateX}px`,
translateY: `${transitionData.translateY}px`,
scale: `${transitionData.scaleX},${transitionData.scaleY}`,
};

const keyframeData: AnimationData = {
name,
style:
'0' in exitingAnimationData.style
? {}
: { 0: { transform: [additionalData] } },
duration: 300,
};
m-bert marked this conversation as resolved.
Show resolved Hide resolved

for (const [timestamp, styles] of Object.entries(
exitingAnimationData.style
)) {
if (styles.transform !== undefined) {
styles.transform.unshift(additionalData);
} else {
styles.transform = [additionalData];
}
m-bert marked this conversation as resolved.
Show resolved Hide resolved

const newTimestamp = parseInt(timestamp) / 2;

keyframeData.style[`${newTimestamp === 50 ? 49 : newTimestamp}`] = styles;
m-bert marked this conversation as resolved.
Show resolved Hide resolved
}

for (const [timestamp, styles] of Object.entries(
enteringAnimationData.style
)) {
keyframeData.style[parseInt(timestamp) / 2 + 50] = styles;
}

return keyframeData;
}