@momo-kits/foundation 0.161.2-beta.7 → 0.161.2-beta.8

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,20 +1,13 @@
1
- import React, { useContext, useEffect, useState } from 'react';
1
+ import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
2
2
  import {
3
+ Animated,
4
+ Easing,
3
5
  LayoutAnimation,
4
6
  Platform,
5
7
  StyleSheet,
6
8
  UIManager,
7
9
  View,
8
10
  } from 'react-native';
9
- import Animated, {
10
- cancelAnimation,
11
- Easing,
12
- interpolate,
13
- useAnimatedStyle,
14
- useSharedValue,
15
- withRepeat,
16
- withTiming,
17
- } from 'react-native-reanimated';
18
11
  import LinearGradient from 'react-native-linear-gradient';
19
12
  import { SkeletonTypes } from './types';
20
13
  import { Colors, Styles } from '../Consts';
@@ -27,31 +20,32 @@ const Skeleton: React.FC<SkeletonTypes> = ({ style }) => {
27
20
  const PRIMARY_COLOR = Colors.black_05;
28
21
  const HIGHLIGHT_COLOR1 = Colors.black_05;
29
22
  const HIGHLIGHT_COLOR2 = Colors.black_03;
30
- const progress = useSharedValue(0);
23
+ const beginShimmerPosition = useRef(new Animated.Value(0)).current;
31
24
 
32
25
  const shimmerColors = [HIGHLIGHT_COLOR1, HIGHLIGHT_COLOR2, HIGHLIGHT_COLOR1];
33
-
34
- useEffect(() => {
35
- progress.value = 0;
36
- progress.value = withRepeat(
37
- withTiming(1, {
26
+ const linearTranslate = beginShimmerPosition.interpolate({
27
+ inputRange: [0, 1],
28
+ outputRange: [-width, width],
29
+ });
30
+ const animatedValue = useMemo(() => {
31
+ return Animated.loop(
32
+ Animated.timing(beginShimmerPosition, {
33
+ toValue: 1,
38
34
  duration: 1000,
39
35
  easing: Easing.linear,
36
+ useNativeDriver: Platform.OS !== 'web',
40
37
  }),
41
- -1,
42
- false,
43
38
  );
39
+ }, [beginShimmerPosition]);
40
+
41
+ useEffect(() => {
42
+ animatedValue.start();
44
43
  screen?.onLoading?.(true);
45
44
  return () => {
46
- cancelAnimation(progress);
45
+ animatedValue.stop();
47
46
  screen?.onLoading?.(false);
48
47
  };
49
- }, [progress, screen]);
50
-
51
- const shimmerStyle = useAnimatedStyle(() => {
52
- const translateX = interpolate(progress.value, [0, 1], [-width, width]);
53
- return { transform: [{ translateX }] };
54
- });
48
+ }, [animatedValue, screen]);
55
49
 
56
50
  const onLayout = (newWidth: number) => {
57
51
  if (newWidth !== width) {
@@ -66,13 +60,11 @@ const Skeleton: React.FC<SkeletonTypes> = ({ style }) => {
66
60
  style={[Styles.flex, { backgroundColor: PRIMARY_COLOR }]}
67
61
  >
68
62
  <Animated.View
69
- style={[
70
- {
71
- width: '60%',
72
- height: '100%',
73
- },
74
- shimmerStyle,
75
- ]}
63
+ style={{
64
+ transform: [{ translateX: linearTranslate }],
65
+ width: '60%',
66
+ height: '100%',
67
+ }}
76
68
  >
77
69
  <LinearGradient
78
70
  style={[StyleSheet.absoluteFill]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.161.2-beta.7",
3
+ "version": "0.161.2-beta.8",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},