UNPKG

react-native-reanimated

Version:

More powerful alternative to Animated library for React Native.

65 lines (59 loc) 2.05 kB
'use strict'; import type { ILayoutAnimationBuilder, LayoutAnimationFunction, } from '../../commonTypes'; import type { BaseAnimationBuilder } from '../animationBuilder'; import { ComplexAnimationBuilder } from '../animationBuilder'; /** * Linearly transforms the layout from one position to another. You can modify * the behavior by chaining methods like `.springify()` or `.duration(500)`. * * You pass it to the `layout` prop on [an Animated * component](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animated-component). * * @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/layout-transitions#linear-transition */ export class LinearTransition extends ComplexAnimationBuilder implements ILayoutAnimationBuilder { static presetName = 'LinearTransition'; static createInstance<T extends typeof BaseAnimationBuilder>( this: T ): InstanceType<T> { return new LinearTransition() as InstanceType<T>; } build = (): LayoutAnimationFunction => { const delayFunction = this.getDelayFunction(); const [animation, config] = this.getAnimationAndConfig(); const callback = this.callbackV; const delay = this.getDelay(); return (values) => { 'worklet'; return { initialValues: { originX: values.currentOriginX, originY: values.currentOriginY, width: values.currentWidth, height: values.currentHeight, }, animations: { originX: delayFunction( delay, animation(values.targetOriginX, config) ), originY: delayFunction( delay, animation(values.targetOriginY, config) ), width: delayFunction(delay, animation(values.targetWidth, config)), height: delayFunction(delay, animation(values.targetHeight, config)), }, callback, }; }; }; } /** @deprecated Please use {@link LinearTransition} instead. */ export const Layout = LinearTransition;