motion-on-native 1.0.6 → 1.1.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.
- package/LICENSE +20 -0
- package/lib/index.d.ts +53 -19
- package/lib/index.js +183 -272
- package/package.json +54 -53
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Mohd Bilal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/lib/index.d.ts
CHANGED
|
@@ -1,31 +1,68 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ViewStyle } from 'react-native';
|
|
2
|
+
import { View, ViewStyle } from 'react-native';
|
|
3
3
|
export interface AnimationProps {
|
|
4
4
|
opacity?: number;
|
|
5
5
|
x?: number;
|
|
6
6
|
y?: number;
|
|
7
|
+
z?: number;
|
|
7
8
|
scale?: number;
|
|
9
|
+
scaleX?: number;
|
|
10
|
+
scaleY?: number;
|
|
8
11
|
rotate?: string;
|
|
12
|
+
rotateX?: string;
|
|
13
|
+
rotateY?: string;
|
|
14
|
+
rotateZ?: string;
|
|
15
|
+
skewX?: string;
|
|
16
|
+
skewY?: string;
|
|
9
17
|
width?: number;
|
|
10
18
|
height?: number;
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
minWidth?: number;
|
|
20
|
+
minHeight?: number;
|
|
21
|
+
maxWidth?: number;
|
|
22
|
+
maxHeight?: number;
|
|
13
23
|
margin?: number;
|
|
14
24
|
marginTop?: number;
|
|
15
25
|
marginBottom?: number;
|
|
16
26
|
marginLeft?: number;
|
|
17
27
|
marginRight?: number;
|
|
28
|
+
marginHorizontal?: number;
|
|
29
|
+
marginVertical?: number;
|
|
18
30
|
padding?: number;
|
|
19
31
|
paddingTop?: number;
|
|
20
32
|
paddingBottom?: number;
|
|
21
33
|
paddingLeft?: number;
|
|
22
34
|
paddingRight?: number;
|
|
35
|
+
paddingHorizontal?: number;
|
|
36
|
+
paddingVertical?: number;
|
|
37
|
+
borderRadius?: number;
|
|
38
|
+
borderTopLeftRadius?: number;
|
|
39
|
+
borderTopRightRadius?: number;
|
|
40
|
+
borderBottomLeftRadius?: number;
|
|
41
|
+
borderBottomRightRadius?: number;
|
|
23
42
|
borderWidth?: number;
|
|
43
|
+
borderTopWidth?: number;
|
|
44
|
+
borderBottomWidth?: number;
|
|
45
|
+
borderLeftWidth?: number;
|
|
46
|
+
borderRightWidth?: number;
|
|
24
47
|
borderColor?: string;
|
|
48
|
+
borderTopColor?: string;
|
|
49
|
+
borderBottomColor?: string;
|
|
50
|
+
borderLeftColor?: string;
|
|
51
|
+
borderRightColor?: string;
|
|
52
|
+
backgroundColor?: string;
|
|
53
|
+
color?: string;
|
|
25
54
|
top?: number;
|
|
26
55
|
bottom?: number;
|
|
27
56
|
left?: number;
|
|
28
57
|
right?: number;
|
|
58
|
+
shadowColor?: string;
|
|
59
|
+
shadowOffset?: {
|
|
60
|
+
width: number;
|
|
61
|
+
height: number;
|
|
62
|
+
};
|
|
63
|
+
shadowOpacity?: number;
|
|
64
|
+
shadowRadius?: number;
|
|
65
|
+
elevation?: number;
|
|
29
66
|
}
|
|
30
67
|
export interface TransitionProps {
|
|
31
68
|
type?: 'spring' | 'timing';
|
|
@@ -33,31 +70,28 @@ export interface TransitionProps {
|
|
|
33
70
|
damping?: number;
|
|
34
71
|
stiffness?: number;
|
|
35
72
|
mass?: number;
|
|
73
|
+
delay?: number;
|
|
74
|
+
ease?: string;
|
|
36
75
|
}
|
|
37
76
|
export interface MotionComponentProps {
|
|
38
|
-
initial?: AnimationProps;
|
|
77
|
+
initial?: AnimationProps | false;
|
|
39
78
|
animate?: AnimationProps;
|
|
40
79
|
exit?: AnimationProps;
|
|
41
80
|
transition?: TransitionProps;
|
|
42
81
|
shouldExit?: boolean;
|
|
43
82
|
onExitComplete?: () => void;
|
|
83
|
+
whileHover?: AnimationProps;
|
|
84
|
+
whileTap?: AnimationProps;
|
|
85
|
+
whileFocus?: AnimationProps;
|
|
86
|
+
layout?: boolean;
|
|
87
|
+
layoutId?: string;
|
|
44
88
|
style?: ViewStyle;
|
|
45
89
|
children?: React.ReactNode;
|
|
46
90
|
}
|
|
47
91
|
export declare const NativeMotion: {
|
|
48
|
-
View: (props: MotionComponentProps & import("react-native").ViewProps) => React.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
} & Omit<MotionComponentProps & import("react-native").TextProps, "style" | "animate" | "initial" | "exit" | "transition" | "children" | "shouldExit" | "onExitComplete">> | null;
|
|
54
|
-
Image: (props: MotionComponentProps & import("react-native").ImageProps) => React.FunctionComponentElement<{
|
|
55
|
-
style: any[];
|
|
56
|
-
} & Omit<MotionComponentProps & import("react-native").ImageProps, "style" | "animate" | "initial" | "exit" | "transition" | "children" | "shouldExit" | "onExitComplete">> | null;
|
|
57
|
-
TextInput: (props: MotionComponentProps & import("react-native").TextInputProps) => React.FunctionComponentElement<{
|
|
58
|
-
style: any[];
|
|
59
|
-
} & Omit<MotionComponentProps & import("react-native").TextInputProps, "style" | "animate" | "initial" | "exit" | "transition" | "children" | "shouldExit" | "onExitComplete">> | null;
|
|
60
|
-
TouchableOpacity: (props: MotionComponentProps & import("react-native").TouchableOpacityProps) => React.FunctionComponentElement<{
|
|
61
|
-
style: any[];
|
|
62
|
-
} & Omit<MotionComponentProps & import("react-native").TouchableOpacityProps, "style" | "animate" | "initial" | "exit" | "transition" | "children" | "shouldExit" | "onExitComplete">> | null;
|
|
92
|
+
View: (props: MotionComponentProps & import("react-native").ViewProps) => React.ReactElement<import("react-native-reanimated").AnimateProps<any>, string | React.JSXElementConstructor<any>> | null;
|
|
93
|
+
Text: (props: MotionComponentProps & import("react-native").TextProps) => React.ReactElement<import("react-native-reanimated").AnimateProps<any>, string | React.JSXElementConstructor<any>> | null;
|
|
94
|
+
Image: (props: MotionComponentProps & import("react-native").ImageProps) => React.ReactElement<import("react-native-reanimated").AnimateProps<any>, string | React.JSXElementConstructor<any>> | null;
|
|
95
|
+
TextInput: (props: MotionComponentProps & import("react-native").TextInputProps) => React.ReactElement<import("react-native-reanimated").AnimateProps<any>, string | React.JSXElementConstructor<any>> | null;
|
|
96
|
+
TouchableOpacity: (props: MotionComponentProps & import("react-native").TouchableOpacityProps & React.RefAttributes<View>) => React.ReactElement<import("react-native-reanimated").AnimateProps<any>, string | React.JSXElementConstructor<any>> | null;
|
|
63
97
|
};
|
package/lib/index.js
CHANGED
|
@@ -47,292 +47,172 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
47
47
|
exports.NativeMotion = void 0;
|
|
48
48
|
const react_1 = __importStar(require("react"));
|
|
49
49
|
const react_native_1 = require("react-native");
|
|
50
|
-
// @ts-ignore
|
|
51
50
|
const react_native_reanimated_1 = __importStar(require("react-native-reanimated"));
|
|
51
|
+
const DEFAULT_TRANSITION = {
|
|
52
|
+
type: 'spring',
|
|
53
|
+
damping: 15,
|
|
54
|
+
stiffness: 100,
|
|
55
|
+
duration: 300,
|
|
56
|
+
};
|
|
52
57
|
function createMotionComponent(Component) {
|
|
53
58
|
return function MotionComponent(props) {
|
|
54
|
-
|
|
55
|
-
const { initial = {}, animate = {}, exit = {}, transition = {}, style = {}, children, shouldExit = false, onExitComplete = () => { } } = props, rest = __rest(props, ["initial", "animate", "exit", "transition", "style", "children", "shouldExit", "onExitComplete"]);
|
|
59
|
+
const { initial = {}, animate = {}, exit = {}, transition = DEFAULT_TRANSITION, shouldExit = false, onExitComplete, whileHover, whileTap, whileFocus, layout, layoutId, style = {}, children } = props, rest = __rest(props, ["initial", "animate", "exit", "transition", "shouldExit", "onExitComplete", "whileHover", "whileTap", "whileFocus", "layout", "layoutId", "style", "children"]);
|
|
56
60
|
const [isPresent, setIsPresent] = (0, react_1.useState)(true);
|
|
57
|
-
const [
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
61
|
+
const [hasAnimated, setHasAnimated] = (0, react_1.useState)(false);
|
|
62
|
+
const isExitingRef = (0, react_1.useRef)(false);
|
|
63
|
+
// Create shared values
|
|
64
|
+
const opacity = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('opacity', initial));
|
|
65
|
+
const x = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('x', initial));
|
|
66
|
+
const y = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('y', initial));
|
|
67
|
+
const scale = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('scale', initial));
|
|
68
|
+
const rotate = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('rotate', initial));
|
|
69
|
+
const width = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('width', initial));
|
|
70
|
+
const height = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('height', initial));
|
|
71
|
+
const backgroundColor = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('backgroundColor', initial));
|
|
72
|
+
const borderRadius = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('borderRadius', initial));
|
|
73
|
+
// Animation helper
|
|
74
|
+
const animateToValues = (targetValues, transitionConfig = transition) => {
|
|
75
|
+
Object.entries(targetValues).forEach(([key, value]) => {
|
|
76
|
+
var _a, _b, _c, _d;
|
|
77
|
+
if (value !== undefined) {
|
|
78
|
+
const sharedValue = getSharedValue(key);
|
|
79
|
+
if (sharedValue) {
|
|
80
|
+
const config = transitionConfig.type === 'spring'
|
|
81
|
+
? (0, react_native_reanimated_1.withSpring)(value, {
|
|
82
|
+
damping: (_a = transitionConfig.damping) !== null && _a !== void 0 ? _a : DEFAULT_TRANSITION.damping,
|
|
83
|
+
stiffness: (_b = transitionConfig.stiffness) !== null && _b !== void 0 ? _b : DEFAULT_TRANSITION.stiffness,
|
|
84
|
+
mass: (_c = transitionConfig.mass) !== null && _c !== void 0 ? _c : 1,
|
|
85
|
+
})
|
|
86
|
+
: (0, react_native_reanimated_1.withTiming)(value, {
|
|
87
|
+
duration: (_d = transitionConfig.duration) !== null && _d !== void 0 ? _d : DEFAULT_TRANSITION.duration,
|
|
88
|
+
});
|
|
89
|
+
if (transitionConfig.delay) {
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
sharedValue.value = config;
|
|
92
|
+
}, transitionConfig.delay);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
sharedValue.value = config;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
// Get shared value by key
|
|
102
|
+
const getSharedValue = (key) => {
|
|
103
|
+
switch (key) {
|
|
104
|
+
case 'opacity': return opacity;
|
|
105
|
+
case 'x': return x;
|
|
106
|
+
case 'y': return y;
|
|
107
|
+
case 'scale': return scale;
|
|
108
|
+
case 'rotate': return rotate;
|
|
109
|
+
case 'width': return width;
|
|
110
|
+
case 'height': return height;
|
|
111
|
+
case 'backgroundColor': return backgroundColor;
|
|
112
|
+
case 'borderRadius': return borderRadius;
|
|
113
|
+
default: return null;
|
|
114
|
+
}
|
|
87
115
|
};
|
|
116
|
+
// Mount animation: initial -> animate
|
|
88
117
|
(0, react_1.useEffect)(() => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
top.value = (_x = initial.top) !== null && _x !== void 0 ? _x : null;
|
|
112
|
-
bottom.value = (_y = initial.bottom) !== null && _y !== void 0 ? _y : null;
|
|
113
|
-
left.value = (_z = initial.left) !== null && _z !== void 0 ? _z : null;
|
|
114
|
-
right.value = (_0 = initial.right) !== null && _0 !== void 0 ? _0 : null;
|
|
115
|
-
}, [initial.opacity, initial.x, initial.y, initial.scale, initial.rotate, initial.width, initial.height, initial.borderRadius, initial.backgroundColor, initial.margin, initial.marginTop, initial.marginBottom, initial.marginLeft, initial.marginRight, initial.padding, initial.paddingTop, initial.paddingBottom, initial.paddingLeft, initial.paddingRight, initial.borderWidth, initial.borderColor, initial.top, initial.bottom, initial.left, initial.right]);
|
|
118
|
+
if (!hasAnimated && !isExitingRef.current) {
|
|
119
|
+
// Set initial values immediately
|
|
120
|
+
if (initial !== false) {
|
|
121
|
+
Object.entries(initial).forEach(([key, value]) => {
|
|
122
|
+
const sharedValue = getSharedValue(key);
|
|
123
|
+
if (sharedValue && value !== undefined) {
|
|
124
|
+
sharedValue.value = value;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
// Animate to target values
|
|
129
|
+
const timer = setTimeout(() => {
|
|
130
|
+
if (!isExitingRef.current) {
|
|
131
|
+
animateToValues(animate);
|
|
132
|
+
setHasAnimated(true);
|
|
133
|
+
}
|
|
134
|
+
}, 16);
|
|
135
|
+
return () => clearTimeout(timer);
|
|
136
|
+
}
|
|
137
|
+
return undefined;
|
|
138
|
+
}, []);
|
|
139
|
+
// Handle animate prop changes
|
|
116
140
|
(0, react_1.useEffect)(() => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
runAnim(rotate, (_e = animate.rotate) !== null && _e !== void 0 ? _e : rotate.value);
|
|
123
|
-
if (animate.width !== undefined)
|
|
124
|
-
runAnim(width, animate.width);
|
|
125
|
-
if (animate.height !== undefined)
|
|
126
|
-
runAnim(height, animate.height);
|
|
127
|
-
if (animate.borderRadius !== undefined)
|
|
128
|
-
runAnim(borderRadius, animate.borderRadius);
|
|
129
|
-
if (animate.backgroundColor !== undefined)
|
|
130
|
-
runAnim(backgroundColor, animate.backgroundColor);
|
|
131
|
-
if (animate.margin !== undefined)
|
|
132
|
-
runAnim(margin, animate.margin);
|
|
133
|
-
if (animate.marginTop !== undefined)
|
|
134
|
-
runAnim(marginTop, animate.marginTop);
|
|
135
|
-
if (animate.marginBottom !== undefined)
|
|
136
|
-
runAnim(marginBottom, animate.marginBottom);
|
|
137
|
-
if (animate.marginLeft !== undefined)
|
|
138
|
-
runAnim(marginLeft, animate.marginLeft);
|
|
139
|
-
if (animate.marginRight !== undefined)
|
|
140
|
-
runAnim(marginRight, animate.marginRight);
|
|
141
|
-
if (animate.padding !== undefined)
|
|
142
|
-
runAnim(padding, animate.padding);
|
|
143
|
-
if (animate.paddingTop !== undefined)
|
|
144
|
-
runAnim(paddingTop, animate.paddingTop);
|
|
145
|
-
if (animate.paddingBottom !== undefined)
|
|
146
|
-
runAnim(paddingBottom, animate.paddingBottom);
|
|
147
|
-
if (animate.paddingLeft !== undefined)
|
|
148
|
-
runAnim(paddingLeft, animate.paddingLeft);
|
|
149
|
-
if (animate.paddingRight !== undefined)
|
|
150
|
-
runAnim(paddingRight, animate.paddingRight);
|
|
151
|
-
if (animate.borderWidth !== undefined)
|
|
152
|
-
runAnim(borderWidth, animate.borderWidth);
|
|
153
|
-
if (animate.borderColor !== undefined)
|
|
154
|
-
runAnim(borderColor, animate.borderColor);
|
|
155
|
-
if (animate.top !== undefined)
|
|
156
|
-
runAnim(top, animate.top);
|
|
157
|
-
if (animate.bottom !== undefined)
|
|
158
|
-
runAnim(bottom, animate.bottom);
|
|
159
|
-
if (animate.left !== undefined)
|
|
160
|
-
runAnim(left, animate.left);
|
|
161
|
-
if (animate.right !== undefined)
|
|
162
|
-
runAnim(right, animate.right);
|
|
163
|
-
}, [animate.opacity, animate.x, animate.y, animate.scale, animate.rotate, animate.width, animate.height, animate.borderRadius, animate.backgroundColor, animate.margin, animate.marginTop, animate.marginBottom, animate.marginLeft, animate.marginRight, animate.padding, animate.paddingTop, animate.paddingBottom, animate.paddingLeft, animate.paddingRight, animate.borderWidth, animate.borderColor, animate.top, animate.bottom, animate.left, animate.right]);
|
|
141
|
+
if (hasAnimated && !isExitingRef.current) {
|
|
142
|
+
animateToValues(animate);
|
|
143
|
+
}
|
|
144
|
+
}, [animate]);
|
|
145
|
+
// Handle shouldExit
|
|
164
146
|
(0, react_1.useEffect)(() => {
|
|
165
|
-
var _a
|
|
166
|
-
if (shouldExit && !
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
runAnim(marginTop, exit.marginTop);
|
|
185
|
-
if (exit.marginBottom !== undefined)
|
|
186
|
-
runAnim(marginBottom, exit.marginBottom);
|
|
187
|
-
if (exit.marginLeft !== undefined)
|
|
188
|
-
runAnim(marginLeft, exit.marginLeft);
|
|
189
|
-
if (exit.marginRight !== undefined)
|
|
190
|
-
runAnim(marginRight, exit.marginRight);
|
|
191
|
-
if (exit.padding !== undefined)
|
|
192
|
-
runAnim(padding, exit.padding);
|
|
193
|
-
if (exit.paddingTop !== undefined)
|
|
194
|
-
runAnim(paddingTop, exit.paddingTop);
|
|
195
|
-
if (exit.paddingBottom !== undefined)
|
|
196
|
-
runAnim(paddingBottom, exit.paddingBottom);
|
|
197
|
-
if (exit.paddingLeft !== undefined)
|
|
198
|
-
runAnim(paddingLeft, exit.paddingLeft);
|
|
199
|
-
if (exit.paddingRight !== undefined)
|
|
200
|
-
runAnim(paddingRight, exit.paddingRight);
|
|
201
|
-
if (exit.borderWidth !== undefined)
|
|
202
|
-
runAnim(borderWidth, exit.borderWidth);
|
|
203
|
-
if (exit.borderColor !== undefined)
|
|
204
|
-
runAnim(borderColor, exit.borderColor);
|
|
205
|
-
if (exit.top !== undefined)
|
|
206
|
-
runAnim(top, exit.top);
|
|
207
|
-
if (exit.bottom !== undefined)
|
|
208
|
-
runAnim(bottom, exit.bottom);
|
|
209
|
-
if (exit.left !== undefined)
|
|
210
|
-
runAnim(left, exit.left);
|
|
211
|
-
if (exit.right !== undefined)
|
|
212
|
-
runAnim(right, exit.right);
|
|
213
|
-
setTimeout(() => { setIsPresent(false); onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete(); }, (_f = transition.duration) !== null && _f !== void 0 ? _f : 300);
|
|
147
|
+
var _a;
|
|
148
|
+
if (shouldExit && !isExitingRef.current) {
|
|
149
|
+
isExitingRef.current = true;
|
|
150
|
+
if (exit && Object.keys(exit).length > 0) {
|
|
151
|
+
animateToValues(exit, transition);
|
|
152
|
+
const exitDuration = (_a = transition.duration) !== null && _a !== void 0 ? _a : 300;
|
|
153
|
+
setTimeout(() => {
|
|
154
|
+
setIsPresent(false);
|
|
155
|
+
if (onExitComplete) {
|
|
156
|
+
onExitComplete();
|
|
157
|
+
}
|
|
158
|
+
}, exitDuration);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
setIsPresent(false);
|
|
162
|
+
if (onExitComplete) {
|
|
163
|
+
onExitComplete();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
214
166
|
}
|
|
215
|
-
else if (!shouldExit &&
|
|
216
|
-
|
|
167
|
+
else if (!shouldExit && isExitingRef.current) {
|
|
168
|
+
// Re-entering: reset everything
|
|
169
|
+
isExitingRef.current = false;
|
|
217
170
|
setIsPresent(true);
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
marginBottom.value = (_t = initial.marginBottom) !== null && _t !== void 0 ? _t : null;
|
|
230
|
-
marginLeft.value = (_u = initial.marginLeft) !== null && _u !== void 0 ? _u : null;
|
|
231
|
-
marginRight.value = (_v = initial.marginRight) !== null && _v !== void 0 ? _v : null;
|
|
232
|
-
padding.value = (_w = initial.padding) !== null && _w !== void 0 ? _w : null;
|
|
233
|
-
paddingTop.value = (_x = initial.paddingTop) !== null && _x !== void 0 ? _x : null;
|
|
234
|
-
paddingBottom.value = (_y = initial.paddingBottom) !== null && _y !== void 0 ? _y : null;
|
|
235
|
-
paddingLeft.value = (_z = initial.paddingLeft) !== null && _z !== void 0 ? _z : null;
|
|
236
|
-
paddingRight.value = (_0 = initial.paddingRight) !== null && _0 !== void 0 ? _0 : null;
|
|
237
|
-
borderWidth.value = (_1 = initial.borderWidth) !== null && _1 !== void 0 ? _1 : null;
|
|
238
|
-
borderColor.value = (_2 = initial.borderColor) !== null && _2 !== void 0 ? _2 : null;
|
|
239
|
-
top.value = (_3 = initial.top) !== null && _3 !== void 0 ? _3 : null;
|
|
240
|
-
bottom.value = (_4 = initial.bottom) !== null && _4 !== void 0 ? _4 : null;
|
|
241
|
-
left.value = (_5 = initial.left) !== null && _5 !== void 0 ? _5 : null;
|
|
242
|
-
right.value = (_6 = initial.right) !== null && _6 !== void 0 ? _6 : null;
|
|
171
|
+
setHasAnimated(false);
|
|
172
|
+
// Reset to initial values
|
|
173
|
+
if (initial !== false) {
|
|
174
|
+
Object.entries(initial).forEach(([key, value]) => {
|
|
175
|
+
const sharedValue = getSharedValue(key);
|
|
176
|
+
if (sharedValue && value !== undefined) {
|
|
177
|
+
sharedValue.value = value;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
// Animate to target after a frame
|
|
243
182
|
setTimeout(() => {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
runAnim(rotate, (_e = animate.rotate) !== null && _e !== void 0 ? _e : rotate.value);
|
|
250
|
-
if (animate.width !== undefined)
|
|
251
|
-
runAnim(width, animate.width);
|
|
252
|
-
if (animate.height !== undefined)
|
|
253
|
-
runAnim(height, animate.height);
|
|
254
|
-
if (animate.borderRadius !== undefined)
|
|
255
|
-
runAnim(borderRadius, animate.borderRadius);
|
|
256
|
-
if (animate.backgroundColor !== undefined)
|
|
257
|
-
runAnim(backgroundColor, animate.backgroundColor);
|
|
258
|
-
if (animate.margin !== undefined)
|
|
259
|
-
runAnim(margin, animate.margin);
|
|
260
|
-
if (animate.marginTop !== undefined)
|
|
261
|
-
runAnim(marginTop, animate.marginTop);
|
|
262
|
-
if (animate.marginBottom !== undefined)
|
|
263
|
-
runAnim(marginBottom, animate.marginBottom);
|
|
264
|
-
if (animate.marginLeft !== undefined)
|
|
265
|
-
runAnim(marginLeft, animate.marginLeft);
|
|
266
|
-
if (animate.marginRight !== undefined)
|
|
267
|
-
runAnim(marginRight, animate.marginRight);
|
|
268
|
-
if (animate.padding !== undefined)
|
|
269
|
-
runAnim(padding, animate.padding);
|
|
270
|
-
if (animate.paddingTop !== undefined)
|
|
271
|
-
runAnim(paddingTop, animate.paddingTop);
|
|
272
|
-
if (animate.paddingBottom !== undefined)
|
|
273
|
-
runAnim(paddingBottom, animate.paddingBottom);
|
|
274
|
-
if (animate.paddingLeft !== undefined)
|
|
275
|
-
runAnim(paddingLeft, animate.paddingLeft);
|
|
276
|
-
if (animate.paddingRight !== undefined)
|
|
277
|
-
runAnim(paddingRight, animate.paddingRight);
|
|
278
|
-
if (animate.borderWidth !== undefined)
|
|
279
|
-
runAnim(borderWidth, animate.borderWidth);
|
|
280
|
-
if (animate.borderColor !== undefined)
|
|
281
|
-
runAnim(borderColor, animate.borderColor);
|
|
282
|
-
if (animate.top !== undefined)
|
|
283
|
-
runAnim(top, animate.top);
|
|
284
|
-
if (animate.bottom !== undefined)
|
|
285
|
-
runAnim(bottom, animate.bottom);
|
|
286
|
-
if (animate.left !== undefined)
|
|
287
|
-
runAnim(left, animate.left);
|
|
288
|
-
if (animate.right !== undefined)
|
|
289
|
-
runAnim(right, animate.right);
|
|
290
|
-
}, 50);
|
|
183
|
+
if (!isExitingRef.current) {
|
|
184
|
+
animateToValues(animate);
|
|
185
|
+
setHasAnimated(true);
|
|
186
|
+
}
|
|
187
|
+
}, 16);
|
|
291
188
|
}
|
|
292
189
|
}, [shouldExit]);
|
|
190
|
+
// Animated style
|
|
293
191
|
const animatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => {
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
if (
|
|
310
|
-
|
|
311
|
-
if (
|
|
312
|
-
|
|
313
|
-
if (
|
|
314
|
-
|
|
315
|
-
if (
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
styleObj.paddingBottom = paddingBottom.value;
|
|
319
|
-
if (paddingLeft.value !== null)
|
|
320
|
-
styleObj.paddingLeft = paddingLeft.value;
|
|
321
|
-
if (paddingRight.value !== null)
|
|
322
|
-
styleObj.paddingRight = paddingRight.value;
|
|
323
|
-
if (borderWidth.value !== null)
|
|
324
|
-
styleObj.borderWidth = borderWidth.value;
|
|
325
|
-
if (borderColor.value !== null)
|
|
326
|
-
styleObj.borderColor = borderColor.value;
|
|
327
|
-
if (top.value !== null)
|
|
328
|
-
styleObj.top = top.value;
|
|
329
|
-
if (bottom.value !== null)
|
|
330
|
-
styleObj.bottom = bottom.value;
|
|
331
|
-
if (left.value !== null)
|
|
332
|
-
styleObj.left = left.value;
|
|
333
|
-
if (right.value !== null)
|
|
334
|
-
styleObj.right = right.value;
|
|
335
|
-
return styleObj;
|
|
192
|
+
const style = {};
|
|
193
|
+
const transform = [];
|
|
194
|
+
// Transform properties
|
|
195
|
+
style.opacity = opacity.value;
|
|
196
|
+
if (x.value !== 0)
|
|
197
|
+
transform.push({ translateX: x.value });
|
|
198
|
+
if (y.value !== 0)
|
|
199
|
+
transform.push({ translateY: y.value });
|
|
200
|
+
if (scale.value !== 1)
|
|
201
|
+
transform.push({ scale: scale.value });
|
|
202
|
+
if (rotate.value !== '0deg')
|
|
203
|
+
transform.push({ rotate: rotate.value });
|
|
204
|
+
if (transform.length > 0)
|
|
205
|
+
style.transform = transform;
|
|
206
|
+
// Layout properties
|
|
207
|
+
if (width.value !== 0)
|
|
208
|
+
style.width = width.value;
|
|
209
|
+
if (height.value !== 0)
|
|
210
|
+
style.height = height.value;
|
|
211
|
+
if (backgroundColor.value !== 0)
|
|
212
|
+
style.backgroundColor = backgroundColor.value;
|
|
213
|
+
if (borderRadius.value !== 0)
|
|
214
|
+
style.borderRadius = borderRadius.value;
|
|
215
|
+
return style;
|
|
336
216
|
});
|
|
337
217
|
const AnimatedComponent = react_native_reanimated_1.default.createAnimatedComponent(Component);
|
|
338
218
|
if (!isPresent)
|
|
@@ -340,6 +220,37 @@ function createMotionComponent(Component) {
|
|
|
340
220
|
return react_1.default.createElement(AnimatedComponent, Object.assign({ style: [style, animatedStyle] }, rest), children);
|
|
341
221
|
};
|
|
342
222
|
}
|
|
223
|
+
function getInitialValue(key, initial) {
|
|
224
|
+
if (initial === false) {
|
|
225
|
+
return getDefaultValue(key);
|
|
226
|
+
}
|
|
227
|
+
const value = initial[key];
|
|
228
|
+
return value !== undefined ? value : getDefaultValue(key);
|
|
229
|
+
}
|
|
230
|
+
function getDefaultValue(key) {
|
|
231
|
+
switch (key) {
|
|
232
|
+
case 'opacity':
|
|
233
|
+
case 'scale':
|
|
234
|
+
case 'scaleX':
|
|
235
|
+
case 'scaleY':
|
|
236
|
+
return 1;
|
|
237
|
+
case 'x':
|
|
238
|
+
case 'y':
|
|
239
|
+
case 'z':
|
|
240
|
+
return 0;
|
|
241
|
+
case 'rotate':
|
|
242
|
+
case 'rotateX':
|
|
243
|
+
case 'rotateY':
|
|
244
|
+
case 'rotateZ':
|
|
245
|
+
case 'skewX':
|
|
246
|
+
case 'skewY':
|
|
247
|
+
return '0deg';
|
|
248
|
+
case 'shadowOffset':
|
|
249
|
+
return { width: 0, height: 0 };
|
|
250
|
+
default:
|
|
251
|
+
return 0;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
343
254
|
exports.NativeMotion = {
|
|
344
255
|
View: createMotionComponent(react_native_1.View),
|
|
345
256
|
Text: createMotionComponent(react_native_1.Text),
|
package/package.json
CHANGED
|
@@ -1,53 +1,54 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "motion-on-native",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "Framer Motion-inspired animation library for React Native with Reanimated. Easy spring animations, gestures, and transitions for mobile apps.",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"types": "lib/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"prepare": "npm run build",
|
|
10
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
-
},
|
|
12
|
-
"keywords": [
|
|
13
|
-
"react-native",
|
|
14
|
-
"framer-motion",
|
|
15
|
-
"animation",
|
|
16
|
-
"reanimated",
|
|
17
|
-
"motion",
|
|
18
|
-
"spring-animation",
|
|
19
|
-
"mobile-animation",
|
|
20
|
-
"react-native-animation",
|
|
21
|
-
"gesture",
|
|
22
|
-
"transition",
|
|
23
|
-
"ui-animation",
|
|
24
|
-
"native-animation",
|
|
25
|
-
"ios",
|
|
26
|
-
"android",
|
|
27
|
-
"typescript"
|
|
28
|
-
],
|
|
29
|
-
"author": "Mohd Bilal",
|
|
30
|
-
"license": "MIT",
|
|
31
|
-
"peerDependencies": {
|
|
32
|
-
"react": ">=16.8.0",
|
|
33
|
-
"react-native": ">=0.60.0",
|
|
34
|
-
"react-native-reanimated": ">=3.0.0"
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@types/react": "^19.1.9",
|
|
38
|
-
"@types/react-native": "^0.72.8",
|
|
39
|
-
"typescript": "^5.0.0"
|
|
40
|
-
},
|
|
41
|
-
"files": [
|
|
42
|
-
"lib",
|
|
43
|
-
"README.md"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "motion-on-native",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Framer Motion-inspired animation library for React Native with Reanimated. Easy spring animations, gestures, and transitions for mobile apps.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepare": "npm run build",
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"react-native",
|
|
14
|
+
"framer-motion",
|
|
15
|
+
"animation",
|
|
16
|
+
"reanimated",
|
|
17
|
+
"motion",
|
|
18
|
+
"spring-animation",
|
|
19
|
+
"mobile-animation",
|
|
20
|
+
"react-native-animation",
|
|
21
|
+
"gesture",
|
|
22
|
+
"transition",
|
|
23
|
+
"ui-animation",
|
|
24
|
+
"native-animation",
|
|
25
|
+
"ios",
|
|
26
|
+
"android",
|
|
27
|
+
"typescript"
|
|
28
|
+
],
|
|
29
|
+
"author": "Mohd Bilal",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": ">=16.8.0",
|
|
33
|
+
"react-native": ">=0.60.0",
|
|
34
|
+
"react-native-reanimated": ">=3.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/react": "^19.1.9",
|
|
38
|
+
"@types/react-native": "^0.72.8",
|
|
39
|
+
"typescript": "^5.0.0"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"lib",
|
|
43
|
+
"README.md",
|
|
44
|
+
"LICENSE"
|
|
45
|
+
],
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "https://github.com/mohd-Bilal-exe/motion-on-native.git"
|
|
49
|
+
},
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/mohd-Bilal-exe/motion-on-native/issues"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://github.com/mohd-Bilal-exe/motion-on-native#readme"
|
|
54
|
+
}
|