related-ui-components 3.0.5 → 3.0.6
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.
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import React, { useEffect,
|
|
4
|
-
import { View, StyleSheet,
|
|
3
|
+
import React, { useCallback, useEffect, useMemo } from "react";
|
|
4
|
+
import { View, StyleSheet, I18nManager } from "react-native";
|
|
5
|
+
import Animated, { useSharedValue, useAnimatedStyle, withRepeat, withSequence, withTiming, cancelAnimation, Easing } from "react-native-reanimated";
|
|
5
6
|
import { LinearGradient } from "expo-linear-gradient";
|
|
6
7
|
import { useTheme } from "../../theme/index.js";
|
|
7
8
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
+
const AnimatedLinearGradient = Animated.createAnimatedComponent(LinearGradient);
|
|
8
10
|
const Shimmer = ({
|
|
9
11
|
children,
|
|
10
12
|
width,
|
|
@@ -18,25 +20,42 @@ const Shimmer = ({
|
|
|
18
20
|
theme
|
|
19
21
|
} = useTheme();
|
|
20
22
|
const isRTL = I18nManager.isRTL;
|
|
21
|
-
|
|
23
|
+
|
|
24
|
+
// Shared animation values (Reanimated)
|
|
25
|
+
const containerWidth = useSharedValue(typeof width === "number" ? width : 400);
|
|
26
|
+
const translateX = useSharedValue(0);
|
|
27
|
+
const opacity = useSharedValue(1);
|
|
28
|
+
const shimmerColors = useMemo(() => [theme.skeletonBackgroundColor + "00", shimmerColor || theme.skeletonShimmer, theme.skeletonBackgroundColor + "00"], [theme, shimmerColor]);
|
|
29
|
+
|
|
30
|
+
// Define easing
|
|
31
|
+
const easing = Easing.bezier(0.76, 0, 0.24, 1);
|
|
32
|
+
|
|
33
|
+
// Start shimmer animation
|
|
34
|
+
const startAnimation = useCallback(() => {
|
|
35
|
+
"worklet";
|
|
36
|
+
|
|
37
|
+
const direction = isRTL ? -1 : 1;
|
|
38
|
+
translateX.value = withRepeat(withSequence(withTiming(-containerWidth.value * 1.5 * direction, {
|
|
39
|
+
duration: 0
|
|
40
|
+
}), withTiming(containerWidth.value * 1.5 * direction, {
|
|
41
|
+
duration,
|
|
42
|
+
easing
|
|
43
|
+
})), -1);
|
|
44
|
+
opacity.value = withTiming(1, {
|
|
45
|
+
duration: duration / 2,
|
|
46
|
+
easing
|
|
47
|
+
});
|
|
48
|
+
}, [containerWidth, duration, easing, isRTL]);
|
|
22
49
|
useEffect(() => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
const numericWidth = typeof width === "number" ? width : 400;
|
|
33
|
-
const ltrOutputRange = [-shimmerWidth, numericWidth + shimmerWidth];
|
|
34
|
-
const rtlOutputRange = [numericWidth + shimmerWidth, -shimmerWidth];
|
|
35
|
-
const translateX = animatedValue.interpolate({
|
|
36
|
-
inputRange: [0, 1],
|
|
37
|
-
outputRange: isRTL ? rtlOutputRange : ltrOutputRange
|
|
38
|
-
});
|
|
39
|
-
const shimmerColors = ["rgba(255, 255, 255, 0)", shimmerColor || theme.skeletonShimmer, "rgba(255, 255, 255, 0)"];
|
|
50
|
+
startAnimation();
|
|
51
|
+
return () => cancelAnimation(translateX);
|
|
52
|
+
}, [startAnimation, translateX]);
|
|
53
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
54
|
+
opacity: opacity.value,
|
|
55
|
+
transform: [{
|
|
56
|
+
translateX: translateX.value
|
|
57
|
+
}]
|
|
58
|
+
}));
|
|
40
59
|
return /*#__PURE__*/_jsxs(View, {
|
|
41
60
|
style: [{
|
|
42
61
|
width,
|
|
@@ -44,29 +63,20 @@ const Shimmer = ({
|
|
|
44
63
|
overflow: "hidden",
|
|
45
64
|
backgroundColor: theme.skeletonBackgroundColor
|
|
46
65
|
}, style],
|
|
47
|
-
children: [children, /*#__PURE__*/_jsx(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}],
|
|
53
|
-
zIndex: 1
|
|
66
|
+
children: [children, /*#__PURE__*/_jsx(AnimatedLinearGradient, {
|
|
67
|
+
colors: shimmerColors,
|
|
68
|
+
start: {
|
|
69
|
+
x: 0,
|
|
70
|
+
y: 0.5
|
|
54
71
|
},
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
y: 0.5
|
|
64
|
-
},
|
|
65
|
-
end: {
|
|
66
|
-
x: 1,
|
|
67
|
-
y: 0.5
|
|
68
|
-
}
|
|
69
|
-
})
|
|
72
|
+
end: {
|
|
73
|
+
x: 1,
|
|
74
|
+
y: 0.5
|
|
75
|
+
},
|
|
76
|
+
style: [StyleSheet.absoluteFill, {
|
|
77
|
+
width: shimmerWidth,
|
|
78
|
+
zIndex: 1
|
|
79
|
+
}, animatedStyle]
|
|
70
80
|
})]
|
|
71
81
|
});
|
|
72
82
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useEffect","
|
|
1
|
+
{"version":3,"names":["React","useCallback","useEffect","useMemo","View","StyleSheet","I18nManager","Animated","useSharedValue","useAnimatedStyle","withRepeat","withSequence","withTiming","cancelAnimation","Easing","LinearGradient","useTheme","jsx","_jsx","jsxs","_jsxs","AnimatedLinearGradient","createAnimatedComponent","Shimmer","children","width","height","style","shimmerColor","duration","shimmerWidth","theme","isRTL","containerWidth","translateX","opacity","shimmerColors","skeletonBackgroundColor","skeletonShimmer","easing","bezier","startAnimation","direction","value","animatedStyle","transform","overflow","backgroundColor","colors","start","x","y","end","absoluteFill","zIndex"],"sourceRoot":"..\\..\\..\\..\\src","sources":["components/Skeleton/Shimmer.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAC9D,SACEC,IA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AE;MAAI,CAAE;MACxBC,GAAG,EAAE;QAAEF,CAAC,EAAE,CAAC;QAAEC,CAAC,EAAE;MAAI,CAAE;MACtBxB,KAAK,EAAE,CACLtB,UAAU,CAACgD,YAAY,EACvB;QAAE5B,KAAK,EAAEK,YAAY;QAAEwB,MAAM,EAAE;MAAE,CAAC,EAClCV,aAAa;IACb,CACH,CAAC;EAAA,CACE,CAAC;AAEX,CAAC;AAED,eAAerB,OAAO","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Shimmer.d.ts","sourceRoot":"","sources":["../../../../../src/components/Skeleton/Shimmer.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Shimmer.d.ts","sourceRoot":"","sources":["../../../../../src/components/Skeleton/Shimmer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAC/D,OAAO,EAGL,SAAS,EACT,cAAc,EACd,SAAS,EAEV,MAAM,cAAc,CAAC;AAgBtB,UAAU,YAAY;IACpB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,EAAE,cAAc,CAAC;IACvB,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,QAAA,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CA2FnC,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
import React, { useEffect,
|
|
1
|
+
import React, { useCallback, useEffect, useMemo } from "react";
|
|
2
2
|
import {
|
|
3
3
|
View,
|
|
4
4
|
StyleSheet,
|
|
5
|
-
Animated,
|
|
6
|
-
Easing,
|
|
7
5
|
ViewStyle,
|
|
8
6
|
DimensionValue,
|
|
9
7
|
StyleProp,
|
|
10
8
|
I18nManager,
|
|
11
9
|
} from "react-native";
|
|
10
|
+
import Animated, {
|
|
11
|
+
useSharedValue,
|
|
12
|
+
useAnimatedStyle,
|
|
13
|
+
withRepeat,
|
|
14
|
+
withSequence,
|
|
15
|
+
withTiming,
|
|
16
|
+
cancelAnimation,
|
|
17
|
+
Easing,
|
|
18
|
+
useAnimatedReaction,
|
|
19
|
+
} from "react-native-reanimated";
|
|
12
20
|
import { LinearGradient } from "expo-linear-gradient";
|
|
13
21
|
import { useTheme } from "../../theme";
|
|
14
22
|
|
|
23
|
+
const AnimatedLinearGradient = Animated.createAnimatedComponent(LinearGradient);
|
|
24
|
+
|
|
15
25
|
interface ShimmerProps {
|
|
16
26
|
children?: React.ReactNode;
|
|
17
27
|
width: DimensionValue;
|
|
@@ -33,36 +43,58 @@ const Shimmer: React.FC<ShimmerProps> = ({
|
|
|
33
43
|
}) => {
|
|
34
44
|
const { theme } = useTheme();
|
|
35
45
|
const isRTL = I18nManager.isRTL;
|
|
36
|
-
const animatedValue = useRef(new Animated.Value(0)).current;
|
|
37
46
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
// Shared animation values (Reanimated)
|
|
48
|
+
const containerWidth = useSharedValue(
|
|
49
|
+
typeof width === "number" ? width : 400
|
|
50
|
+
);
|
|
51
|
+
const translateX = useSharedValue(0);
|
|
52
|
+
const opacity = useSharedValue(1);
|
|
53
|
+
|
|
54
|
+
const shimmerColors = useMemo(
|
|
55
|
+
() => [
|
|
56
|
+
theme.skeletonBackgroundColor + "00",
|
|
57
|
+
shimmerColor || theme.skeletonShimmer,
|
|
58
|
+
theme.skeletonBackgroundColor + "00",
|
|
59
|
+
],
|
|
60
|
+
[theme, shimmerColor]
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// Define easing
|
|
64
|
+
const easing = Easing.bezier(0.76, 0, 0.24, 1);
|
|
65
|
+
|
|
66
|
+
// Start shimmer animation
|
|
67
|
+
const startAnimation = useCallback(() => {
|
|
68
|
+
"worklet";
|
|
69
|
+
const direction = isRTL ? -1 : 1;
|
|
70
|
+
|
|
71
|
+
translateX.value = withRepeat(
|
|
72
|
+
withSequence(
|
|
73
|
+
withTiming(-containerWidth.value * 1.5 * direction, { duration: 0 }),
|
|
74
|
+
withTiming(containerWidth.value * 1.5 * direction, {
|
|
75
|
+
duration,
|
|
76
|
+
easing,
|
|
77
|
+
})
|
|
78
|
+
),
|
|
79
|
+
-1
|
|
46
80
|
);
|
|
47
|
-
animation.start();
|
|
48
|
-
return () => animation.stop();
|
|
49
|
-
}, [animatedValue, duration]);
|
|
50
81
|
|
|
51
|
-
|
|
82
|
+
opacity.value = withTiming(1, {
|
|
83
|
+
duration: duration / 2,
|
|
84
|
+
easing,
|
|
85
|
+
});
|
|
86
|
+
}, [containerWidth, duration, easing, isRTL]);
|
|
52
87
|
|
|
53
|
-
|
|
54
|
-
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
startAnimation();
|
|
55
90
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
outputRange: isRTL ? rtlOutputRange : ltrOutputRange,
|
|
59
|
-
});
|
|
91
|
+
return () => cancelAnimation(translateX);
|
|
92
|
+
}, [startAnimation, translateX]);
|
|
60
93
|
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
];
|
|
94
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
95
|
+
opacity: opacity.value,
|
|
96
|
+
transform: [{ translateX: translateX.value }],
|
|
97
|
+
}));
|
|
66
98
|
|
|
67
99
|
return (
|
|
68
100
|
<View
|
|
@@ -77,22 +109,20 @@ const Shimmer: React.FC<ShimmerProps> = ({
|
|
|
77
109
|
]}
|
|
78
110
|
>
|
|
79
111
|
{children}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
/>
|
|
93
|
-
</Animated.View>
|
|
112
|
+
|
|
113
|
+
{/* Shimmer Gradient */}
|
|
114
|
+
<AnimatedLinearGradient
|
|
115
|
+
colors={shimmerColors as any}
|
|
116
|
+
start={{ x: 0, y: 0.5 }}
|
|
117
|
+
end={{ x: 1, y: 0.5 }}
|
|
118
|
+
style={[
|
|
119
|
+
StyleSheet.absoluteFill,
|
|
120
|
+
{ width: shimmerWidth, zIndex: 1 },
|
|
121
|
+
animatedStyle,
|
|
122
|
+
]}
|
|
123
|
+
/>
|
|
94
124
|
</View>
|
|
95
125
|
);
|
|
96
126
|
};
|
|
97
127
|
|
|
98
|
-
export default Shimmer;
|
|
128
|
+
export default Shimmer;
|