react-native-reanimated
Version:
More powerful alternative to Animated library for React Native.
237 lines • 10.1 kB
TypeScript
import type { EntryExitAnimationFunction, ILayoutAnimationBuilder, LayoutAnimationAndConfig, LayoutAnimationFunction, StyleProps } from '../commonTypes';
import type { BaseAnimationBuilder } from './animationBuilder';
import { AnimationConfigBuilder } from './animationBuilder';
export type FadeContentConfig = {
/**
* The fade-out of the children of the moving view. `end` is the progress of
* the move, more than 0 and at most 1, at which they reach opacity 0. A value
* below 0.000001 works as 0.000001. Defaults to 1.
*/
fadeOut?: {
end?: number;
};
/**
* The fade-in of the children of the target view after the move. `duration`
* is in milliseconds. Defaults to half of the transition duration, or 250 ms
* when `springify()` gets no duration.
*/
fadeIn?: {
duration?: number;
};
};
export type SharedTransitionContentFade = {
fadeIn: EntryExitAnimationFunction;
fadeOutEnd: number;
};
/**
* Used to configure the `.defaultTransitionType()` shared transition modifier.
*
* @experimental
*/
export declare enum SharedTransitionType {
/**
* Use the regular or custom animation, except during iOS back navigation.
* During iOS back navigation, use the progress animation controlled by the
* screen transition.
*/
ANIMATION = "animation",
/**
* Always use the progress animation. During iOS back navigation, the screen
* transition controls progress. Otherwise, the builder settings, such as
* `.duration()` or `.springify()`, control progress.
*/
PROGRESS_ANIMATION = "progressAnimation"
}
type BoxShadowValue = {
offsetX: number;
offsetY: number;
blurRadius: number;
spreadDistance: number;
color: string;
};
type SharedTransitionSnapshotValues = {
OriginX: number;
OriginY: number;
/** The same as `OriginX`; the transition runs in window coordinates. */
GlobalOriginX: number;
/** The same as `OriginY`; the transition runs in window coordinates. */
GlobalOriginY: number;
Width: number;
Height: number;
Opacity: number;
BackgroundColor: string;
Transform: {
matrix: number[];
};
/**
* @deprecated Reanimated 3 compatibility. A flat 16-element column-major 4×4
* matrix. Read `Transform.matrix` instead.
*/
TransformMatrix: number[];
TransformOrigin: [number, number, number];
BorderRadius: number | string;
BorderTopLeftRadius?: number | string;
BorderTopRightRadius?: number | string;
BorderBottomLeftRadius?: number | string;
BorderBottomRightRadius?: number | string;
BorderTopStartRadius?: number | string;
BorderTopEndRadius?: number | string;
BorderBottomStartRadius?: number | string;
BorderBottomEndRadius?: number | string;
BorderStartStartRadius?: number | string;
BorderStartEndRadius?: number | string;
BorderEndStartRadius?: number | string;
BorderEndEndRadius?: number | string;
BorderWidth: number;
BorderLeftWidth?: number;
BorderRightWidth?: number;
BorderTopWidth?: number;
BorderBottomWidth?: number;
BorderColor: string;
BorderLeftColor?: string;
BorderRightColor?: string;
BorderTopColor?: string;
BorderBottomColor?: string;
BoxShadow: BoxShadowValue[];
ShadowColor: string;
ShadowOffset: {
width: number;
height: number;
};
ShadowOpacity: number;
ShadowRadius: number;
/** Android only. */
Elevation?: number;
/**
* The clip of the moving view in window coordinates: the bounds of its
* ancestors with `overflow: hidden`. Present only when an ancestor clips
* either view.
*/
ClipOriginX?: number;
ClipOriginY?: number;
ClipWidth?: number;
ClipHeight?: number;
ClipBorderRadius?: number;
};
/**
* Values passed to shared transition animation worklets: the snapshot of the
* source view (`current*`), the snapshot of the target view (`target*`) and the
* window size. Per-side and per-corner border values are present only when one
* of the views sets them.
*/
export type SharedTransitionAnimationsValues = {
[K in keyof SharedTransitionSnapshotValues as `current${K}`]: SharedTransitionSnapshotValues[K];
} & {
[K in keyof SharedTransitionSnapshotValues as `target${K}`]: SharedTransitionSnapshotValues[K];
} & {
windowWidth: number;
windowHeight: number;
};
interface SharedTransitionAnimations extends StyleProps {
transform?: [{
matrix: number[];
}];
transformMatrix?: number[];
}
/**
* A function that defines a custom shared transition animation. It receives the
* source/target values and should return an object containing animations for
* each property.
*/
export type CustomSharedTransitionAnimation = (values: SharedTransitionAnimationsValues) => SharedTransitionAnimations;
/**
* A function that defines a progress-based shared transition animation. It
* receives the source/target values along with the progress (0-1) and should
* return the interpolated style values.
*/
export type ProgressSharedTransitionAnimation = (values: SharedTransitionAnimationsValues, progress: number) => StyleProps;
export declare class SharedTransition extends AnimationConfigBuilder implements ILayoutAnimationBuilder {
static presetName: string;
fadeContentV?: FadeContentConfig;
private customAnimationFactory?;
private progressAnimationFactory?;
private transitionType;
static createInstance<T extends typeof BaseAnimationBuilder>(this: T): InstanceType<T>;
/**
* Fades the children of the shared view out while it moves, and fades the
* children of the target view in when it lands. The shared view itself stays
* visible. Use it when the two views have different children. Can be chained
* alongside other [layout animation
* modifiers](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#layout-animation-modifier).
*
* @param config - When the fade-out ends and how long the fade-in lasts.
*/
static fadeContent<T extends typeof SharedTransition>(this: T, config?: FadeContentConfig): InstanceType<T>;
fadeContent(config?: FadeContentConfig): this;
buildContentFade(): SharedTransitionContentFade | undefined;
/**
* Tells if the built animation aims at the current geometry of the target in
* each frame. Custom animations and timed progress animations use the
* geometry that the target has when they start, and move with a scroll of the
* target. This is used internally by the layout animations system.
*/
followsTarget(): boolean;
private buildContentFadeIn;
/**
* Creates a shared transition with a custom animation worklet. The worklet
* receives the source and target values and returns the animations for each
* property.
*/
static custom(customAnimationFactory: CustomSharedTransitionAnimation): SharedTransition;
/** Uses a custom animation worklet. See {@link SharedTransition.custom}. */
custom(customAnimationFactory: CustomSharedTransitionAnimation): this;
/**
* Creates a shared transition with a progress-based animation worklet. See
* {@link SharedTransition#progressAnimation}.
*/
static progressAnimation(progressAnimationFactory: ProgressSharedTransitionAnimation): SharedTransition;
/**
* Creates a shared transition with the given default transition type. See
* {@link SharedTransition#defaultTransitionType}.
*/
static defaultTransitionType(transitionType: SharedTransitionType): SharedTransition;
/**
* Defines a progress-based animation for the shared transition. The worklet
* receives the source and target values along with the progress (0-1) and
* returns the interpolated style values. Without it, every property is
* interpolated linearly.
*/
progressAnimation(progressAnimationFactory: ProgressSharedTransitionAnimation): this;
/**
* Sets the default transition type for the shared transition.
*
* - `SharedTransitionType.ANIMATION` - Uses the regular or custom animation,
* except during iOS back navigation, when the screen transition controls
* the progress animation.
* - `SharedTransitionType.PROGRESS_ANIMATION` - Uses the progress animation for
* all transitions. The screen transition controls progress during iOS back
* navigation; otherwise, the builder settings control progress.
*
* @param transitionType - The transition type to use.
*/
defaultTransitionType(transitionType: SharedTransitionType): this;
/** Not supported. A shared transition starts from the source view. */
static withInitialValues<T extends typeof BaseAnimationBuilder>(this: T, _values: never): InstanceType<T>;
/** Not supported. A shared transition starts from the source view. */
withInitialValues(_values: never): this;
/** Not supported. A shared transition ends at the target view. */
static withTargetValues<T extends typeof BaseAnimationBuilder>(this: T, _values: never): InstanceType<T>;
/** Not supported. A shared transition ends at the target view. */
withTargetValues(_values: never): this;
/** Not supported. A shared transition animates the transform of the view. */
static rotate<T extends typeof BaseAnimationBuilder>(this: T, _degree: never): InstanceType<T>;
/** Not supported. A shared transition animates the transform of the view. */
rotate(_degree: never): this;
getAnimationAndConfig(): LayoutAnimationAndConfig;
build: () => LayoutAnimationFunction;
private isPhysicsBasedSpring;
private getStyleProgressAnimation;
/**
* Gets the progress animation used for transitions that follow the screen
* transition progress. This is used internally by the layout animations
* system.
*/
getProgressAnimation(): ProgressSharedTransitionAnimation;
}
export {};
//# sourceMappingURL=SharedTransition.d.ts.map