react-ui-animate 1.4.6 → 2.0.0-rc.1
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.
- package/.vscode/settings.json +3 -0
- package/dist/animation/animationType.d.ts +7 -0
- package/dist/animation/getInitialConfig.d.ts +3 -3
- package/dist/animation/index.d.ts +5 -4
- package/dist/animation/interpolation.d.ts +3 -11
- package/dist/animation/modules.d.ts +18 -10
- package/dist/animation/useAnimatedValue.d.ts +11 -23
- package/dist/animation/useMountedValue.d.ts +5 -14
- package/dist/index.js +58 -106
- package/dist/index.js.map +1 -1
- package/dist/utils/delay.d.ts +5 -0
- package/dist/utils/index.d.ts +2 -1
- package/package.json +2 -2
- package/src/animation/animationType.ts +9 -0
- package/src/animation/getInitialConfig.ts +12 -13
- package/src/animation/index.ts +9 -4
- package/src/animation/interpolation.ts +5 -38
- package/src/animation/modules.tsx +12 -12
- package/src/animation/useAnimatedValue.ts +22 -92
- package/src/animation/useMountedValue.ts +25 -41
- package/src/utils/delay.ts +9 -0
- package/src/utils/index.ts +2 -1
|
@@ -1,55 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
useTransition,
|
|
4
|
-
TransitionValue,
|
|
5
|
-
ResultType,
|
|
6
|
-
} from "@raidipesh78/re-motion";
|
|
7
|
-
import { InitialConfigType, getInitialConfig } from "./getInitialConfig";
|
|
1
|
+
import { useTransition, UseTransitionConfig } from '@raidipesh78/re-motion';
|
|
8
2
|
|
|
9
3
|
// useAnimatedValue value type
|
|
10
4
|
type AnimatedValueType = number | string;
|
|
5
|
+
export interface UseAnimatedValueConfig extends UseTransitionConfig {}
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const getValue = (value: AnimatedValueType) => {
|
|
17
|
-
if (typeof value === "number" || typeof value === "string") {
|
|
18
|
-
return value;
|
|
19
|
-
} else {
|
|
20
|
-
throw new Error(
|
|
21
|
-
"Invalid Value! Animated value only accepts string or number."
|
|
22
|
-
);
|
|
23
|
-
}
|
|
7
|
+
type Length = number | string;
|
|
8
|
+
type AssignValue = {
|
|
9
|
+
toValue: Length;
|
|
10
|
+
config?: UseAnimatedValueConfig;
|
|
24
11
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
mass?: number;
|
|
30
|
-
friction?: number;
|
|
31
|
-
tension?: number;
|
|
32
|
-
easing?: (t: number) => number;
|
|
33
|
-
delay?: number;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface UseAnimatedValueConfig extends GenericAnimationConfig {
|
|
37
|
-
animationType?: InitialConfigType;
|
|
38
|
-
onAnimationEnd?: (value: ResultType) => void;
|
|
39
|
-
listener?: (value: number) => void;
|
|
40
|
-
immediate?: boolean;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type ValueReturnType =
|
|
44
|
-
| TransitionValue
|
|
45
|
-
| number
|
|
46
|
-
| string
|
|
47
|
-
| { toValue: number | string; immediate?: boolean };
|
|
48
|
-
|
|
49
|
-
interface UseAnimatedValueReturn {
|
|
50
|
-
value: ValueReturnType;
|
|
51
|
-
currentValue: number | string;
|
|
52
|
-
}
|
|
12
|
+
export type ValueType =
|
|
13
|
+
| Length
|
|
14
|
+
| AssignValue
|
|
15
|
+
| ((update: (next: AssignValue) => Promise<any>) => void);
|
|
53
16
|
|
|
54
17
|
/**
|
|
55
18
|
* useAnimatedValue for animated transitions
|
|
@@ -57,75 +20,42 @@ interface UseAnimatedValueReturn {
|
|
|
57
20
|
export function useAnimatedValue(
|
|
58
21
|
initialValue: AnimatedValueType,
|
|
59
22
|
config?: UseAnimatedValueConfig
|
|
60
|
-
)
|
|
61
|
-
const
|
|
62
|
-
const _initialValue: number | string = getValue(initialValue);
|
|
63
|
-
|
|
64
|
-
const animationType = config?.animationType ?? "ease"; // Defines default animation
|
|
65
|
-
const onAnimationEnd = config?.onAnimationEnd;
|
|
66
|
-
const listener = config?.listener;
|
|
67
|
-
|
|
68
|
-
const [animation, setAnimation] = useTransition(_initialValue, {
|
|
69
|
-
...getInitialConfig(animationType),
|
|
70
|
-
...config,
|
|
71
|
-
onRest: function (result: any) {
|
|
72
|
-
if (result.finished) {
|
|
73
|
-
onAnimationEnd && onAnimationEnd(result.value);
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
onChange: function (value: number) {
|
|
77
|
-
listener && listener(value);
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// doesn't fire on initial render
|
|
82
|
-
React.useEffect(() => {
|
|
83
|
-
if (!_isInitial.current) {
|
|
84
|
-
setAnimation({ toValue: _initialValue });
|
|
85
|
-
}
|
|
86
|
-
_isInitial.current = false;
|
|
87
|
-
}, [_initialValue]);
|
|
23
|
+
) {
|
|
24
|
+
const [animation, setAnimation] = useTransition(initialValue, config);
|
|
88
25
|
|
|
89
26
|
const targetObject: {
|
|
90
27
|
value: any;
|
|
91
|
-
currentValue:
|
|
28
|
+
currentValue: number | string;
|
|
92
29
|
} = {
|
|
93
30
|
value: animation,
|
|
94
31
|
currentValue: animation.get(),
|
|
95
32
|
};
|
|
96
33
|
|
|
97
34
|
return new Proxy(targetObject, {
|
|
98
|
-
set: function (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
value: number | string | { toValue: number | string; immediate?: boolean }
|
|
102
|
-
) {
|
|
103
|
-
if (key === "value") {
|
|
104
|
-
if (typeof value === "number" || typeof value === "string") {
|
|
35
|
+
set: function (_, key, value: ValueType) {
|
|
36
|
+
if (key === 'value') {
|
|
37
|
+
if (typeof value === 'number' || typeof value === 'string') {
|
|
105
38
|
setAnimation({ toValue: value });
|
|
106
|
-
} else if (typeof value ===
|
|
107
|
-
setAnimation(
|
|
108
|
-
toValue: value.toValue,
|
|
109
|
-
config: { immediate: value.immediate },
|
|
110
|
-
});
|
|
39
|
+
} else if (typeof value === 'object' || typeof value === 'function') {
|
|
40
|
+
setAnimation(value);
|
|
111
41
|
}
|
|
112
42
|
|
|
113
43
|
return true;
|
|
114
44
|
}
|
|
115
45
|
|
|
116
|
-
throw new Error(
|
|
46
|
+
throw new Error('You cannot set any other property to animation node.');
|
|
117
47
|
},
|
|
118
48
|
get: function (_, key) {
|
|
119
|
-
if (key ===
|
|
49
|
+
if (key === 'value') {
|
|
120
50
|
return animation;
|
|
121
51
|
}
|
|
122
52
|
|
|
123
|
-
if (key ===
|
|
53
|
+
if (key === 'currentValue') {
|
|
124
54
|
return animation.get();
|
|
125
55
|
}
|
|
126
56
|
|
|
127
57
|
throw new Error(
|
|
128
|
-
|
|
58
|
+
'You cannot access any other property from animation node.'
|
|
129
59
|
);
|
|
130
60
|
},
|
|
131
61
|
});
|
|
@@ -1,50 +1,41 @@
|
|
|
1
|
-
import * as React from
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
import {
|
|
3
3
|
useTransition,
|
|
4
4
|
TransitionValue,
|
|
5
|
-
|
|
6
|
-
} from
|
|
5
|
+
UseMountConfig,
|
|
6
|
+
} from '@raidipesh78/re-motion';
|
|
7
7
|
|
|
8
|
-
export interface
|
|
9
|
-
enterDuration?: number;
|
|
10
|
-
exitDuration?: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface UseMountedValueConfig {
|
|
14
|
-
from: number;
|
|
15
|
-
enter: number;
|
|
16
|
-
exit: number;
|
|
17
|
-
config?: InnerUseMountedValueConfig;
|
|
18
|
-
}
|
|
8
|
+
export interface UseMountedValueConfig extends UseMountConfig {}
|
|
19
9
|
|
|
20
10
|
/**
|
|
21
11
|
* useMountedValue handles mounting and unmounting of a component
|
|
22
12
|
* @param state - boolean
|
|
23
13
|
* @param config - useTransitionConfig
|
|
24
|
-
* @returns mountedValueFunction with a callback with argument ( animationNode, mounted )
|
|
14
|
+
* @returns mountedValueFunction with a callback with argument ( { value: animationNode }, mounted )
|
|
25
15
|
*/
|
|
26
16
|
export function useMountedValue(state: boolean, config: UseMountedValueConfig) {
|
|
27
|
-
const
|
|
17
|
+
const initial = React.useRef(true);
|
|
28
18
|
const [mounted, setMounted] = React.useState(state);
|
|
29
|
-
const {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
19
|
+
const {
|
|
20
|
+
from,
|
|
21
|
+
enter,
|
|
22
|
+
exit,
|
|
23
|
+
config: innerConfig,
|
|
24
|
+
enterConfig,
|
|
25
|
+
exitConfig,
|
|
26
|
+
} = React.useRef(config).current;
|
|
27
|
+
const [animation, setAnimation] = useTransition(from, innerConfig);
|
|
35
28
|
|
|
36
29
|
React.useEffect(() => {
|
|
37
30
|
if (state) {
|
|
38
|
-
|
|
31
|
+
initial.current = true;
|
|
39
32
|
setMounted(true);
|
|
40
33
|
} else {
|
|
41
|
-
|
|
34
|
+
initial.current = false;
|
|
42
35
|
setAnimation(
|
|
43
36
|
{
|
|
44
37
|
toValue: exit,
|
|
45
|
-
config:
|
|
46
|
-
duration: exitDuration,
|
|
47
|
-
},
|
|
38
|
+
config: exitConfig,
|
|
48
39
|
},
|
|
49
40
|
function ({ finished }) {
|
|
50
41
|
if (finished) {
|
|
@@ -56,24 +47,17 @@ export function useMountedValue(state: boolean, config: UseMountedValueConfig) {
|
|
|
56
47
|
}, [state]);
|
|
57
48
|
|
|
58
49
|
React.useEffect(() => {
|
|
59
|
-
if (mounted && initial) {
|
|
60
|
-
setAnimation(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
duration: enterDuration,
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
function () {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
);
|
|
50
|
+
if (mounted && initial.current) {
|
|
51
|
+
setAnimation({
|
|
52
|
+
toValue: enter,
|
|
53
|
+
config: enterConfig,
|
|
54
|
+
});
|
|
71
55
|
}
|
|
72
|
-
}, [mounted, initial]);
|
|
56
|
+
}, [mounted, initial.current]);
|
|
73
57
|
|
|
74
58
|
return function (
|
|
75
59
|
callback: (
|
|
76
|
-
{ value }: { value: TransitionValue },
|
|
60
|
+
{ value: animation }: { value: TransitionValue },
|
|
77
61
|
mounted: boolean
|
|
78
62
|
) => React.ReactNode
|
|
79
63
|
) {
|
package/src/utils/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './isDefined';
|
|
2
|
+
export * from './delay';
|