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] Fix easing #6304

Merged
merged 5 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions packages/react-native-reanimated/src/Easing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,15 @@ const EasingObject = {
inOut,
};

export const EasingNameSymbol = Symbol('easingName');

for (const [easingName, easing] of Object.entries(EasingObject)) {
Object.defineProperty(easing, EasingNameSymbol, {
value: easingName,
configurable: false,
enumerable: false,
writable: false,
});
}

export const Easing = EasingObject;
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,26 @@ import type { ReanimatedSnapshot, ScrollOffsets } from './componentStyle';
import { setElementPosition, snapshots } from './componentStyle';
import { Keyframe } from '../animationBuilder';
import { ReducedMotionManager } from '../../ReducedMotion';
import { EasingNameSymbol } from '../../Easing';

function getEasingFromConfig(config: CustomConfig): string {
const easingName =
config.easingV && config.easingV.name in WebEasings
? (config.easingV.name as WebEasingsNames)
: 'linear';
if (!config.easingV) {
return `cubic-bezier(${WebEasings.linear.toString()})`;
}

const easingName = config.easingV[EasingNameSymbol];

if (!(easingName in WebEasings)) {
console.warn(
`[Reanimated] Selected easing is not currently supported on web.`
);

return `cubic-bezier(${WebEasings.linear.toString()})`;
}

return `cubic-bezier(${WebEasings[easingName].toString()})`;
return `cubic-bezier(${WebEasings[
easingName as WebEasingsNames
].toString()})`;
}

function getRandomDelay(maxDelay = 1000) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ export interface AnimationConfig {
reversed: boolean;
}

interface EasingType {
(): number;
[EasingNameSymbol: symbol]: string;
}

export interface CustomConfig {
easingV?: () => number;
easingV?: EasingType;
durationV?: number;
delayV?: number;
randomizeDelay?: boolean;
Expand Down