@react-native-ama/animations 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ import type { ViewProps } from 'react-native';
3
+ import Animated, { AnimateProps } from 'react-native-reanimated';
4
+ import { AnimatedEntryViewStyle, AnimatedExitViewStyle, ToAnimation } from '../hooks/useReanimatedAnimationBuilder';
5
+ export declare const AnimatedContainer: React.ForwardRefExoticComponent<Omit<AnimateProps<ViewProps>, "entering" | "exiting"> & {
6
+ autofocus?: boolean | undefined;
7
+ duration?: number | undefined;
8
+ from: AnimatedEntryViewStyle;
9
+ exitFrom?: AnimatedExitViewStyle | undefined;
10
+ exitTo?: ToAnimation;
11
+ to: ToAnimation;
12
+ style?: Pick<ViewProps, "style"> | undefined;
13
+ } & {
14
+ children?: React.ReactNode;
15
+ } & React.RefAttributes<Animated.View>>;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __rest = (this && this.__rest) || function (s, e) {
26
+ var t = {};
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
+ t[p] = s[p];
29
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
+ t[p[i]] = s[p[i]];
33
+ }
34
+ return t;
35
+ };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.AnimatedContainer = void 0;
41
+ const core_1 = require("@react-native-ama/core");
42
+ const React = __importStar(require("react"));
43
+ const react_native_reanimated_1 = __importDefault(require("react-native-reanimated"));
44
+ const useReanimatedAnimationBuilder_1 = require("../hooks/useReanimatedAnimationBuilder");
45
+ exports.AnimatedContainer = React.forwardRef((_a, forwardRef) => {
46
+ var { from, to, exitFrom, exitTo, duration = 300, style, autofocus, children } = _a, rest = __rest(_a, ["from", "to", "exitFrom", "exitTo", "duration", "style", "autofocus", "children"]);
47
+ const { entering, exiting } = (0, useReanimatedAnimationBuilder_1.useReanimatedAnimationBuilder)({
48
+ from,
49
+ to,
50
+ exitFrom,
51
+ exitTo,
52
+ duration,
53
+ });
54
+ const Wrapper = autofocus ? core_1.AutofocusContainer : React.Fragment;
55
+ return (<Wrapper>
56
+ <react_native_reanimated_1.default.View style={style} entering={entering} exiting={exiting} ref={forwardRef} {...rest}>
57
+ {children}
58
+ </react_native_reanimated_1.default.View>
59
+ </Wrapper>);
60
+ });
@@ -0,0 +1,17 @@
1
+ import type { ViewStyle } from 'react-native';
2
+ import { Animated } from 'react-native';
3
+ type UseAnimation = {
4
+ from: ViewStyle;
5
+ to: ViewStyle;
6
+ duration: number;
7
+ useNativeDriver: boolean;
8
+ skipIfReduceMotionEnabled?: boolean;
9
+ };
10
+ export declare const useAnimation: ({ duration, useNativeDriver, from, to, skipIfReduceMotionEnabled, }: UseAnimation) => {
11
+ animatedStyle: {
12
+ [x: string]: any;
13
+ };
14
+ progress: Animated.Value;
15
+ play: (toValue?: number) => Animated.CompositeAnimation;
16
+ };
17
+ export {};
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __rest = (this && this.__rest) || function (s, e) {
26
+ var t = {};
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
+ t[p] = s[p];
29
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
+ t[p[i]] = s[p[i]];
33
+ }
34
+ return t;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.useAnimation = void 0;
38
+ const core_1 = require("@react-native-ama/core");
39
+ const internal_1 = require("@react-native-ama/internal");
40
+ const React = __importStar(require("react"));
41
+ const react_native_1 = require("react-native");
42
+ const useAnimation = ({ duration, useNativeDriver, from, to, skipIfReduceMotionEnabled = false, }) => {
43
+ const { isReduceMotionEnabled } = (0, core_1.useAMAContext)();
44
+ const progress = React.useRef(new react_native_1.Animated.Value(0)).current;
45
+ const reduceMotionProgress = React.useRef(new react_native_1.Animated.Value(0)).current;
46
+ const hasOnlyMotionAnimation = React.useRef(false);
47
+ const play = (toValue = 1) => {
48
+ if (isReduceMotionEnabled) {
49
+ react_native_1.Animated.timing(reduceMotionProgress, {
50
+ duration: 0,
51
+ toValue,
52
+ useNativeDriver,
53
+ }).start();
54
+ }
55
+ const animationDuration = isReduceMotionEnabled &&
56
+ (hasOnlyMotionAnimation.current || skipIfReduceMotionEnabled)
57
+ ? 0
58
+ : duration;
59
+ return react_native_1.Animated.timing(progress, {
60
+ duration: animationDuration,
61
+ toValue,
62
+ useNativeDriver,
63
+ });
64
+ };
65
+ const _a = (0, internal_1.interpolateAnimationStates)(from, to, isReduceMotionEnabled, progress, reduceMotionProgress), { __hasOnlyMotionAnimation } = _a, style = __rest(_a, ["__hasOnlyMotionAnimation"]);
66
+ hasOnlyMotionAnimation.current = __hasOnlyMotionAnimation;
67
+ return {
68
+ animatedStyle: style,
69
+ progress,
70
+ play,
71
+ };
72
+ };
73
+ exports.useAnimation = useAnimation;
@@ -0,0 +1,4 @@
1
+ import type { ViewStyle } from 'react-native';
2
+ export declare const useAnimationDuration: () => {
3
+ getAnimationDuration: (propertyToAnimate: keyof ViewStyle, duration: number) => number;
4
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useAnimationDuration = void 0;
7
+ const core_1 = require("@react-native-ama/core");
8
+ const react_1 = __importDefault(require("react"));
9
+ const isMotionAnimation_1 = require("../utils/isMotionAnimation");
10
+ const useAnimationDuration = () => {
11
+ const { isReduceMotionEnabled } = (0, core_1.useAMAContext)();
12
+ const getAnimationDuration = react_1.default.useCallback((propertyToAnimate, duration) => {
13
+ return isReduceMotionEnabled && (0, isMotionAnimation_1.isMotionAnimation)(propertyToAnimate)
14
+ ? 0
15
+ : duration;
16
+ }, [isReduceMotionEnabled]);
17
+ return {
18
+ getAnimationDuration,
19
+ };
20
+ };
21
+ exports.useAnimationDuration = useAnimationDuration;
@@ -0,0 +1,63 @@
1
+ import type { ViewProps, ViewStyle } from 'react-native';
2
+ import { EntryAnimationsValues, EntryExitAnimationFunction, ExitAnimationsValues } from 'react-native-reanimated';
3
+ export type ToAnimation = ViewProps['style'];
4
+ type UseReanimatedAnimationBuilder = {
5
+ from: AnimatedEntryViewStyle;
6
+ to: ToAnimation;
7
+ exitFrom?: AnimatedExitViewStyle;
8
+ exitTo?: ToAnimation;
9
+ duration: number;
10
+ };
11
+ export declare const useReanimatedAnimationBuilder: ({ from, to, exitFrom, exitTo, duration, }: UseReanimatedAnimationBuilder) => {
12
+ entering: EntryExitAnimationFunction;
13
+ exiting: EntryExitAnimationFunction;
14
+ };
15
+ export type AnimatedEntryViewStyle = ReanimatedStyle<ReanimatedEntryValues>;
16
+ export type AnimatedExitViewStyle = ReanimatedStyle<ReanimatedExitValues>;
17
+ type ReanimatedStyle<K> = {
18
+ [key in keyof Omit<ViewStyle, 'transform'>]: ViewStyle[key] | K;
19
+ } & {
20
+ transform?: (PerpectiveTransform<K> | RotateTransform<K> | RotateXTransform<K> | RotateYTransform<K> | RotateZTransform<K> | ScaleTransform<K> | ScaleXTransform<K> | ScaleYTransform<K> | TranslateXTransform<K> | TranslateYTransform<K> | SkewXTransform<K> | SkewYTransform<K> | MatrixTransform<K>)[] | undefined;
21
+ };
22
+ type PerpectiveTransform<K> = {
23
+ c: string | K;
24
+ };
25
+ type RotateTransform<K> = {
26
+ rotate: string | K;
27
+ };
28
+ type RotateXTransform<K> = {
29
+ rotateX: string | K;
30
+ };
31
+ type RotateYTransform<K> = {
32
+ rotateY: string | K;
33
+ };
34
+ type RotateZTransform<K> = {
35
+ rotateZ: string | K;
36
+ };
37
+ type ScaleTransform<K> = {
38
+ scale: number | K;
39
+ };
40
+ type ScaleXTransform<K> = {
41
+ scaleX: number | K;
42
+ };
43
+ type ScaleYTransform<K> = {
44
+ scaleY: number | K;
45
+ };
46
+ type TranslateXTransform<K> = {
47
+ translateX: number | K;
48
+ };
49
+ type TranslateYTransform<K> = {
50
+ translateY: number | K;
51
+ };
52
+ type SkewXTransform<K> = {
53
+ skewX: string | K;
54
+ };
55
+ type SkewYTransform<K> = {
56
+ skewY: string | K;
57
+ };
58
+ type MatrixTransform<K> = {
59
+ matrix: number[] | K;
60
+ };
61
+ type ReanimatedEntryValues = keyof EntryAnimationsValues;
62
+ type ReanimatedExitValues = keyof ExitAnimationsValues;
63
+ export {};
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useReanimatedAnimationBuilder = void 0;
4
+ const core_1 = require("@react-native-ama/core");
5
+ const internal_1 = require("@react-native-ama/internal");
6
+ const react_native_reanimated_1 = require("react-native-reanimated");
7
+ const useReanimatedAnimationBuilder = ({ from, to, exitFrom, exitTo, duration, }) => {
8
+ const { isReduceMotionEnabled } = (0, core_1.useAMAContext)();
9
+ const animationBuilder = (initial, final) => {
10
+ return (values) => {
11
+ 'worklet';
12
+ const animations = (function generateAnimations(startValues, endValues) {
13
+ return Object.keys(startValues).reduce((outputAnimation, key) => {
14
+ const k = key;
15
+ const toValue = endValues[key];
16
+ const value = startValues[k];
17
+ const mappedToValue =
18
+ // @ts-ignore
19
+ typeof toValue === 'string' ? values[toValue] || 0 : toValue;
20
+ const realDuration = isReduceMotionEnabled &&
21
+ internal_1.MOTION_ANIMATIONS.includes(key)
22
+ ? 0
23
+ : duration;
24
+ const newValue = Array.isArray(value)
25
+ ? value.map((item, index) => {
26
+ var _a;
27
+ return generateAnimations(item,
28
+ // @ts-ignore
29
+ (_a = endValues === null || endValues === void 0 ? void 0 : endValues[k]) === null || _a === void 0 ? void 0 : _a[index]);
30
+ })
31
+ : (0, react_native_reanimated_1.withTiming)(mappedToValue, {
32
+ duration: realDuration,
33
+ });
34
+ outputAnimation[k] = newValue;
35
+ return outputAnimation;
36
+ }, {});
37
+ })(initial, final);
38
+ const initialValues = (function generateInitialValues(startValues) {
39
+ return Object.entries(startValues).reduce((newList, [key, value]) => {
40
+ const mappedValue =
41
+ // @ts-ignore
42
+ typeof value === 'string' ? values[value] : value;
43
+ const newValue = Array.isArray(value)
44
+ ? value.map(item => generateInitialValues(item))
45
+ : mappedValue;
46
+ newList[key] = newValue;
47
+ return newList;
48
+ }, {});
49
+ })(initial);
50
+ return {
51
+ initialValues,
52
+ animations,
53
+ };
54
+ };
55
+ };
56
+ return {
57
+ entering: animationBuilder(from, to),
58
+ exiting: animationBuilder(exitTo || to, exitFrom || from),
59
+ };
60
+ };
61
+ exports.useReanimatedAnimationBuilder = useReanimatedAnimationBuilder;
@@ -0,0 +1,6 @@
1
+ import type { MotionAnimationKey } from '@react-native-ama/internal';
2
+ import { AnimationCallback, WithSpringConfig, WithTimingConfig } from 'react-native-reanimated';
3
+ export declare const useReanimatedTiming: () => {
4
+ withTiming: (propertyKey: MotionAnimationKey, toValue: number, config?: WithTimingConfig, callback?: AnimationCallback) => number;
5
+ withSpring: (propertyKey: MotionAnimationKey, toValue: number, config?: WithSpringConfig, callback?: AnimationCallback) => number;
6
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useReanimatedTiming = void 0;
7
+ const core_1 = require("@react-native-ama/core");
8
+ const react_1 = __importDefault(require("react"));
9
+ const react_native_reanimated_1 = require("react-native-reanimated");
10
+ const isMotionAnimation_1 = require("../utils/isMotionAnimation");
11
+ const useReanimatedTiming = () => {
12
+ const { isReduceMotionEnabled } = (0, core_1.useAMAContext)();
13
+ const withTiming = react_1.default.useCallback((propertyKey, toValue, config = {}, callback) => {
14
+ if (isReduceMotionEnabled && (0, isMotionAnimation_1.isMotionAnimation)(propertyKey)) {
15
+ config.duration = 0;
16
+ }
17
+ return (0, react_native_reanimated_1.withTiming)(toValue, config, callback);
18
+ }, [isReduceMotionEnabled]);
19
+ const withSpring = react_1.default.useCallback((propertyKey, toValue, config, callback) => {
20
+ if (isReduceMotionEnabled && (0, isMotionAnimation_1.isMotionAnimation)(propertyKey)) {
21
+ return (0, react_native_reanimated_1.withTiming)(toValue, { duration: 0 });
22
+ }
23
+ return (0, react_native_reanimated_1.withSpring)(toValue, config, callback);
24
+ }, [isReduceMotionEnabled]);
25
+ return {
26
+ withTiming,
27
+ withSpring,
28
+ };
29
+ };
30
+ exports.useReanimatedTiming = useReanimatedTiming;
@@ -0,0 +1,5 @@
1
+ export { AnimatedContainer } from './components/AnimatedContainer';
2
+ export { useAnimation } from './hooks/useAnimation';
3
+ export { useAnimationDuration } from './hooks/useAnimationDuration';
4
+ export { useReanimatedAnimationBuilder } from './hooks/useReanimatedAnimationBuilder';
5
+ export { useReanimatedTiming } from './hooks/useReanimatedTiming';
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useReanimatedTiming = exports.useReanimatedAnimationBuilder = exports.useAnimationDuration = exports.useAnimation = exports.AnimatedContainer = void 0;
4
+ // Components
5
+ var AnimatedContainer_1 = require("./components/AnimatedContainer");
6
+ Object.defineProperty(exports, "AnimatedContainer", { enumerable: true, get: function () { return AnimatedContainer_1.AnimatedContainer; } });
7
+ // Hooks
8
+ var useAnimation_1 = require("./hooks/useAnimation");
9
+ Object.defineProperty(exports, "useAnimation", { enumerable: true, get: function () { return useAnimation_1.useAnimation; } });
10
+ var useAnimationDuration_1 = require("./hooks/useAnimationDuration");
11
+ Object.defineProperty(exports, "useAnimationDuration", { enumerable: true, get: function () { return useAnimationDuration_1.useAnimationDuration; } });
12
+ var useReanimatedAnimationBuilder_1 = require("./hooks/useReanimatedAnimationBuilder");
13
+ Object.defineProperty(exports, "useReanimatedAnimationBuilder", { enumerable: true, get: function () { return useReanimatedAnimationBuilder_1.useReanimatedAnimationBuilder; } });
14
+ var useReanimatedTiming_1 = require("./hooks/useReanimatedTiming");
15
+ Object.defineProperty(exports, "useReanimatedTiming", { enumerable: true, get: function () { return useReanimatedTiming_1.useReanimatedTiming; } });
@@ -0,0 +1,2 @@
1
+ import { type MotionAnimationKey } from '@react-native-ama/internal';
2
+ export declare const isMotionAnimation: (key: MotionAnimationKey) => boolean;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isMotionAnimation = void 0;
4
+ const internal_1 = require("@react-native-ama/internal");
5
+ const isMotionAnimation = (key) => {
6
+ return internal_1.MOTION_ANIMATIONS.includes(key);
7
+ };
8
+ exports.isMotionAnimation = isMotionAnimation;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-ama/animations",
3
- "version": "0.0.1",
3
+ "version": "1.0.0",
4
4
  "private": false,
5
5
  "react-native": "src/index",
6
6
  "types": "dist/index.d.ts",
@@ -45,8 +45,8 @@
45
45
  },
46
46
  "homepage": "https://github.com/FormidableLabs/react-native-ama#readme",
47
47
  "publishConfig": {
48
- "provenance": false
48
+ "provenance": true
49
49
  },
50
50
  "author": "",
51
51
  "license": "MIT"
52
- }
52
+ }
@@ -68,7 +68,7 @@ export const useReanimatedAnimationBuilder = ({
68
68
  },
69
69
  {} as InitialValues,
70
70
  );
71
- })(initial, final);
71
+ })(initial, final) as StyleProps;
72
72
 
73
73
  const initialValues = (function generateInitialValues(
74
74
  startValues,