@cleartrip/ct-design-animate 4.0.0-SNAPSHOT-rnfinaltest25.0 → 4.0.0-SNAPSHOT-rnfinaltest30.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,5 @@
1
+ import React from 'react';
2
+ import { EntranceAnimationProps } from '../type';
3
+ declare const EntranceAnimation: React.FC<EntranceAnimationProps>;
4
+ export default EntranceAnimation;
5
+ //# sourceMappingURL=EntranceAnimation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntranceAnimation.d.ts","sourceRoot":"","sources":["../../packages/components/Animate/src/components/EntranceAnimation.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAIjD,OAAO,EAA8B,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAE7E,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CA6DvD,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { EntranceAnimationProps } from '../type';
3
+ declare const EntranceAnimation: React.FC<EntranceAnimationProps>;
4
+ export default EntranceAnimation;
5
+ //# sourceMappingURL=EntranceAnimation.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntranceAnimation.native.d.ts","sourceRoot":"","sources":["../../packages/components/Animate/src/components/EntranceAnimation.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAIjD,OAAO,EAA8B,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAE7E,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CA6DvD,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ interface IShakeAnimationProps extends PropsWithChildren {
3
+ animate?: boolean;
4
+ style?: object;
5
+ }
6
+ declare const StyledAnimation: React.FC<IShakeAnimationProps>;
7
+ export default StyledAnimation;
8
+ //# sourceMappingURL=Shake.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Shake.native.d.ts","sourceRoot":"","sources":["../../packages/components/Animate/src/components/Shake.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAIjD,UAAU,oBAAqB,SAAQ,iBAAiB;IACtD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAsBD,QAAA,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CASnD,CAAC;AAEF,eAAe,eAAe,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleartrip/ct-design-animate",
3
- "version": "4.0.0-SNAPSHOT-rnfinaltest25.0",
3
+ "version": "4.0.0-SNAPSHOT-rnfinaltest30.0",
4
4
  "description": "HOC component that will render animation to children",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "./dist/ct-design-animate.cjs.js",
@@ -25,12 +25,12 @@
25
25
  "dependencies": {
26
26
  "@emotion/react": "^11.14.0",
27
27
  "@emotion/styled": "^11.14.0",
28
- "@cleartrip/ct-design-style-manager": "4.0.0-SNAPSHOT-rnfinaltest25.0",
29
- "@cleartrip/ct-design-theme": "4.0.0-SNAPSHOT-rnfinaltest25.0"
28
+ "@cleartrip/ct-design-style-manager": "4.0.0-SNAPSHOT-rnfinaltest30.0",
29
+ "@cleartrip/ct-design-theme": "4.0.0-SNAPSHOT-rnfinaltest30.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@emotion/babel-plugin": "^11.12.0",
33
- "@cleartrip/ct-design-types": "4.0.0-SNAPSHOT-rnfinaltest25.0"
33
+ "@cleartrip/ct-design-types": "4.0.0-SNAPSHOT-rnfinaltest30.0"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "react": ">=16.8.0",
@@ -0,0 +1,70 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+
3
+ import Animated, { useAnimatedStyle, useSharedValue, withDelay, withTiming } from 'react-native-reanimated';
4
+
5
+ import { EntranceAnimationDirection, EntranceAnimationProps } from '../type';
6
+
7
+ const EntranceAnimation: React.FC<EntranceAnimationProps> = ({
8
+ direction,
9
+ index = 0,
10
+ children,
11
+ staggerDelay = 80,
12
+ maxStaggerIndex = 5,
13
+ initialOffset = 200,
14
+ duration = 200,
15
+ containerStyle,
16
+ fillContainer = false,
17
+ opacityAnimation = true,
18
+ startAnimation = true,
19
+ onAnimationComplete = () => void 0,
20
+ }) => {
21
+ // Wrap index for staggered effect
22
+ const wrappedIndex = index % (maxStaggerIndex + 1);
23
+
24
+ // Track if animation has already been executed
25
+ const hasAnimated = useRef(false);
26
+
27
+ const translate = useSharedValue(initialOffset);
28
+ const opacity = useSharedValue(opacityAnimation ? 0.5 : 1);
29
+
30
+ // Callback to emit animation complete event
31
+ useEffect(() => {
32
+ if (!hasAnimated.current && startAnimation) {
33
+ hasAnimated.current = true;
34
+ translate.value = withDelay(wrappedIndex * staggerDelay, withTiming(0, { duration }));
35
+ opacity.value = withDelay(wrappedIndex * staggerDelay + duration, withTiming(1, { duration: duration * 0.5 }));
36
+
37
+ // Emit animation complete event after animation duration
38
+ const totalDelay = wrappedIndex * staggerDelay + duration + duration * 0.5;
39
+ setTimeout(() => {
40
+ onAnimationComplete();
41
+ }, totalDelay);
42
+ }
43
+ // eslint-disable-next-line react-hooks/exhaustive-deps
44
+ }, [wrappedIndex, staggerDelay, duration, direction, startAnimation, onAnimationComplete]);
45
+
46
+ const animatedStyle = useAnimatedStyle(() => {
47
+ const transform =
48
+ direction === EntranceAnimationDirection.B2T
49
+ ? [{ translateY: translate.value }]
50
+ : [{ translateX: translate.value }];
51
+
52
+ const baseStyle = {
53
+ transform: transform,
54
+ opacity: opacity.value,
55
+ };
56
+
57
+ // Add flex: 1 if fillContainer is true
58
+ const layoutStyle = fillContainer ? { flex: 1 } : {};
59
+
60
+ return {
61
+ ...baseStyle,
62
+ ...layoutStyle,
63
+ ...containerStyle,
64
+ };
65
+ });
66
+
67
+ return <Animated.View style={animatedStyle}>{children}</Animated.View>;
68
+ };
69
+
70
+ export default EntranceAnimation;
@@ -0,0 +1,70 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+
3
+ import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withDelay, withTiming } from 'react-native-reanimated';
4
+
5
+ import { EntranceAnimationDirection, EntranceAnimationProps } from '../type';
6
+
7
+ const EntranceAnimation: React.FC<EntranceAnimationProps> = ({
8
+ direction,
9
+ index = 0,
10
+ children,
11
+ staggerDelay = 80,
12
+ maxStaggerIndex = 5,
13
+ initialOffset = 200,
14
+ duration = 200,
15
+ containerStyle,
16
+ fillContainer = false,
17
+ opacityAnimation = true,
18
+ startAnimation = true,
19
+ onAnimationComplete = () => void 0,
20
+ }) => {
21
+ // Wrap index for staggered effect
22
+ const wrappedIndex = index % (maxStaggerIndex + 1);
23
+
24
+ // Track if animation has already been executed
25
+ const hasAnimated = useRef(false);
26
+
27
+ const translate = useSharedValue(initialOffset);
28
+ const opacity = useSharedValue(opacityAnimation ? 0.5 : 1);
29
+
30
+ // Callback to emit animation complete event
31
+ useEffect(() => {
32
+ if (!hasAnimated.current && startAnimation) {
33
+ hasAnimated.current = true;
34
+ translate.value = withDelay(wrappedIndex * staggerDelay, withTiming(0, { duration }));
35
+ opacity.value = withDelay(wrappedIndex * staggerDelay + duration, withTiming(1, { duration: duration * 0.5 }));
36
+
37
+ // Emit animation complete event after animation duration
38
+ const totalDelay = wrappedIndex * staggerDelay + duration + duration * 0.5;
39
+ setTimeout(() => {
40
+ runOnJS(onAnimationComplete)();
41
+ }, totalDelay);
42
+ }
43
+ // eslint-disable-next-line react-hooks/exhaustive-deps
44
+ }, [wrappedIndex, staggerDelay, duration, direction, startAnimation, onAnimationComplete]);
45
+
46
+ const animatedStyle = useAnimatedStyle(() => {
47
+ const transform =
48
+ direction === EntranceAnimationDirection.B2T
49
+ ? [{ translateY: translate.value }]
50
+ : [{ translateX: translate.value }];
51
+
52
+ const baseStyle = {
53
+ transform: transform,
54
+ opacity: opacity.value,
55
+ };
56
+
57
+ // Add flex: 1 if fillContainer is true
58
+ const layoutStyle = fillContainer ? { flex: 1 } : {};
59
+
60
+ return {
61
+ ...baseStyle,
62
+ ...layoutStyle,
63
+ ...containerStyle,
64
+ };
65
+ });
66
+
67
+ return <Animated.View style={animatedStyle}>{children}</Animated.View>;
68
+ };
69
+
70
+ export default EntranceAnimation;
@@ -0,0 +1,41 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+
3
+ import Animated, { Easing, useAnimatedStyle, useSharedValue, withSequence, withTiming } from 'react-native-reanimated';
4
+
5
+ interface IShakeAnimationProps extends PropsWithChildren {
6
+ animate?: boolean;
7
+ style?: object;
8
+ }
9
+
10
+ const useShakeAnimation = (show: boolean) => {
11
+ const translateX = useSharedValue(0);
12
+
13
+ React.useEffect(() => {
14
+ if (show) {
15
+ translateX.value = withSequence(
16
+ withTiming(-1, { duration: 100, easing: Easing.bezier(0.36, 0.07, 0.19, 0.97) }),
17
+ withTiming(2, { duration: 100, easing: Easing.bezier(0.36, 0.07, 0.19, 0.97) }),
18
+ withTiming(-4, { duration: 100, easing: Easing.bezier(0.36, 0.07, 0.19, 0.97) }),
19
+ withTiming(4, { duration: 100, easing: Easing.bezier(0.36, 0.07, 0.19, 0.97) }),
20
+ withTiming(0, { duration: 100, easing: Easing.bezier(0.36, 0.07, 0.19, 0.97) }),
21
+ );
22
+ } else {
23
+ translateX.value = withTiming(0, { duration: 200 });
24
+ }
25
+ }, [show, translateX]);
26
+
27
+ return translateX;
28
+ };
29
+
30
+ const StyledAnimation: React.FC<IShakeAnimationProps> = ({ children, animate = false, style = {} }) => {
31
+ const translateX = useShakeAnimation(animate);
32
+
33
+ const animatedStyle = useAnimatedStyle(() => ({
34
+ transform: [{ translateX: translateX.value }],
35
+ backfaceVisibility: 'hidden',
36
+ perspective: 1000,
37
+ }));
38
+ return <Animated.View style={[style, animatedStyle]}>{children}</Animated.View>;
39
+ };
40
+
41
+ export default StyledAnimation;