UNPKG

1.8 kBPlain TextView Raw
1'use strict';
2import { useAnimatedStyle } from './useAnimatedStyle';
3import type { DependencyList, UseAnimatedStyleInternal } from './commonTypes';
4import { shouldBeUseWeb } from '../PlatformChecker';
5import type { AnimatedPropsAdapterFunction } from '../commonTypes';
6
7// TODO: we should make sure that when useAP is used we are not assigning styles
8
9type UseAnimatedProps = <Props extends object>(
10 updater: () => Partial<Props>,
11 dependencies?: DependencyList | null,
12 adapters?:
13 | AnimatedPropsAdapterFunction
14 | AnimatedPropsAdapterFunction[]
15 | null,
16 isAnimatedProps?: boolean
17) => Partial<Props>;
18
19function useAnimatedPropsJS<Props extends object>(
20 updater: () => Props,
21 deps?: DependencyList | null,
22 adapters?:
23 | AnimatedPropsAdapterFunction
24 | AnimatedPropsAdapterFunction[]
25 | null
26) {
27 return (useAnimatedStyle as UseAnimatedStyleInternal<Props>)(
28 updater,
29 deps,
30 adapters,
31 true
32 );
33}
34
35const useAnimatedPropsNative = useAnimatedStyle;
36
37/**
38 * Lets you create an animated props object which can be animated using shared values.
39 *
40 * @param updater - A function returning an object with properties you want to animate.
41 * @param dependencies - An optional array of dependencies. Only relevant when using Reanimated without the Babel plugin on the Web.
42 * @param adapters - An optional function or array of functions allowing to adopt prop naming between JS and the native side.
43 * @returns An animated props object which has to be passed to `animatedProps` property of an Animated component that you want to animate.
44 * @see https://docs.swmansion.com/react-native-reanimated/docs/core/useAnimatedProps
45 */
46export const useAnimatedProps: UseAnimatedProps = shouldBeUseWeb()
47 ? (useAnimatedPropsJS as UseAnimatedProps)
48 : useAnimatedPropsNative;