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

Fix keyframe types #6438

Merged
merged 13 commits into from
Sep 2, 2024
Prev Previous commit
Next Next commit
fix
Latropos committed Aug 21, 2024
commit 829bce43c90c1ccaf81308e019b84e4bb9a2958a
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ class Keyframe {

An object, that contains definitions of your animation.
The object keys should be within range `0-100` and correspond to animation progress.
The object values should consist of style props and/or [easing function](/docs/animations/withTiming/#easing). If easing property is not provided, it defaults to `Easing.linear`.
The object values should consist of style props and optionally of an [easing function](/docs/animations/withTiming/#easing). If easing property is not provided, it defaults to `Easing.linear`.

The keys take the following values:

@@ -84,6 +84,7 @@ keyframe

- Providing keyframe `0` or `from` is required as it contains the initial state of the object you want to animate.
- Ensure you provide the initial value for all style properties you want to animate in other keyframes.
- If you want to add easing to an animation between two keyframes you have to pass it to the second one. As a result you should never provide any easing to keyframe `0`.
- Do not provide both `0` and `from`, or `100` and `to` keyframes, as it will result in a parsing conflict.
- If you want to animate transform style, make sure that all properties in the transformation array are in the same order in all keyframes.

4 changes: 2 additions & 2 deletions packages/react-native-reanimated/src/helperTypes.ts
Original file line number Diff line number Diff line change
@@ -18,14 +18,14 @@ import type {
EntryExitAnimationFunction,
LayoutAnimationFunction,
} from './layoutReanimation/animationBuilder/commonTypes';
import type { Keyframe as ReanimatedKeyframe } from './layoutReanimation/animationBuilder/Keyframe';
import type { ReanimatedKeyframe } from './layoutReanimation/animationBuilder/Keyframe';
import type { SharedTransition } from './layoutReanimation/sharedTransitions';

type EntryOrExitLayoutType =
| BaseAnimationBuilder
| typeof BaseAnimationBuilder
| EntryExitAnimationFunction
| typeof ReanimatedKeyframe;
| ReanimatedKeyframe;

/*
Style type properties (properties that extends StyleProp<ViewStyle>)
Original file line number Diff line number Diff line change
@@ -304,4 +304,12 @@ function makeKeyframeKey(index: number, transformProp: string) {
return `${index}_transform:${transformProp}`;
}

export const Keyframe = InnerKeyframe;
export declare class ReanimatedKeyframe {
constructor(definitions: ValidKeyframeProps);
duration(durationMs: number): ReanimatedKeyframe;
delay(delayMs: number): ReanimatedKeyframe;
reduceMotion(reduceMotionV: ReduceMotion): ReanimatedKeyframe;
withCallback(callback: (finished: boolean) => void): ReanimatedKeyframe;
}

export const Keyframe = InnerKeyframe as typeof ReanimatedKeyframe;