@momo-kits/foundation 0.161.1-beta.2 → 0.161.2-beta.5

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,5 +1,12 @@
1
- import React, { FC, useContext, useRef, useState } from 'react';
2
- import { Animated, View } from 'react-native';
1
+ import React, { FC, useContext, useState } from 'react';
2
+ import { View } from 'react-native';
3
+ import Animated, {
4
+ Extrapolation,
5
+ interpolate,
6
+ useAnimatedScrollHandler,
7
+ useAnimatedStyle,
8
+ useSharedValue,
9
+ } from 'react-native-reanimated';
3
10
  import { ScrollIndicatorProps } from './types';
4
11
  import styles from './styles';
5
12
  import { ApplicationContext, MiniAppContext } from '../Context';
@@ -13,40 +20,37 @@ const PaginationScroll: FC<ScrollIndicatorProps> = ({
13
20
  }) => {
14
21
  const { theme } = useContext(ApplicationContext);
15
22
  const context = useContext<any>(MiniAppContext);
16
- const left = useRef(new Animated.Value(0)).current;
23
+ const left = useSharedValue(0);
17
24
  const [scrollViewWidth, setScrollViewWidth] = useState(0);
18
25
  const [scrollContentWidth, setScrollContentWidth] = useState(0);
19
26
 
20
27
  const showBaseLineDebug = context?.designSystemConfig?.isBaselineEnabled;
21
28
 
22
- const translateX = () => {
23
- if (scrollViewWidth && scrollContentWidth) {
24
- const value = left.interpolate({
25
- inputRange: [0, scrollContentWidth - scrollViewWidth],
26
- outputRange: [0, INDICATOR_CONTAINER_WIDTH - INDICATOR_WIDTH],
27
- extrapolate: 'clamp',
28
- });
29
- return { transform: [{ translateX: value }] };
29
+ const onScroll = useAnimatedScrollHandler({
30
+ onScroll: (event) => {
31
+ left.value = event.contentOffset.x;
32
+ },
33
+ });
34
+
35
+ const indicatorStyle = useAnimatedStyle(() => {
36
+ if (!scrollViewWidth || !scrollContentWidth) {
37
+ return {};
30
38
  }
31
- return {};
32
- };
39
+ const value = interpolate(
40
+ left.value,
41
+ [0, scrollContentWidth - scrollViewWidth],
42
+ [0, INDICATOR_CONTAINER_WIDTH - INDICATOR_WIDTH],
43
+ Extrapolation.CLAMP,
44
+ );
45
+ return { transform: [{ translateX: value }] };
46
+ });
33
47
 
34
48
  const renderScrollView = () => {
35
49
  return (
36
50
  <Animated.ScrollView
37
- ref={scrollViewRef}
38
- onScroll={Animated.event(
39
- [
40
- {
41
- nativeEvent: {
42
- contentOffset: {
43
- x: left,
44
- },
45
- },
46
- },
47
- ],
48
- { useNativeDriver: true },
49
- )}
51
+ ref={scrollViewRef as any}
52
+ onScroll={onScroll}
53
+ scrollEventThrottle={16}
50
54
  alwaysBounceHorizontal={false}
51
55
  showsHorizontalScrollIndicator={false}
52
56
  horizontal
@@ -76,7 +80,7 @@ const PaginationScroll: FC<ScrollIndicatorProps> = ({
76
80
  {
77
81
  backgroundColor: theme.colors.primary,
78
82
  },
79
- translateX(),
83
+ indicatorStyle,
80
84
  ]}
81
85
  />
82
86
  </View>
@@ -1,13 +1,20 @@
1
- import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
1
+ import React, { useContext, useEffect, useState } from 'react';
2
2
  import {
3
- Animated,
4
- Easing,
5
3
  LayoutAnimation,
6
4
  Platform,
7
5
  StyleSheet,
8
6
  UIManager,
9
7
  View,
10
8
  } 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';
11
18
  import LinearGradient from 'react-native-linear-gradient';
12
19
  import { SkeletonTypes } from './types';
13
20
  import { Colors, Styles } from '../Consts';
@@ -20,32 +27,31 @@ const Skeleton: React.FC<SkeletonTypes> = ({ style }) => {
20
27
  const PRIMARY_COLOR = Colors.black_05;
21
28
  const HIGHLIGHT_COLOR1 = Colors.black_05;
22
29
  const HIGHLIGHT_COLOR2 = Colors.black_03;
23
- const beginShimmerPosition = useRef(new Animated.Value(0)).current;
30
+ const progress = useSharedValue(0);
24
31
 
25
32
  const shimmerColors = [HIGHLIGHT_COLOR1, HIGHLIGHT_COLOR2, HIGHLIGHT_COLOR1];
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,
33
+
34
+ useEffect(() => {
35
+ progress.value = 0;
36
+ progress.value = withRepeat(
37
+ withTiming(1, {
34
38
  duration: 1000,
35
39
  easing: Easing.linear,
36
- useNativeDriver: Platform.OS !== 'web',
37
40
  }),
41
+ -1,
42
+ false,
38
43
  );
39
- }, [beginShimmerPosition]);
40
-
41
- useEffect(() => {
42
- animatedValue.start();
43
44
  screen?.onLoading?.(true);
44
45
  return () => {
45
- animatedValue.stop();
46
+ cancelAnimation(progress);
46
47
  screen?.onLoading?.(false);
47
48
  };
48
- }, [animatedValue, screen]);
49
+ }, [progress, screen]);
50
+
51
+ const shimmerStyle = useAnimatedStyle(() => {
52
+ const translateX = interpolate(progress.value, [0, 1], [-width, width]);
53
+ return { transform: [{ translateX }] };
54
+ });
49
55
 
50
56
  const onLayout = (newWidth: number) => {
51
57
  if (newWidth !== width) {
@@ -60,11 +66,13 @@ const Skeleton: React.FC<SkeletonTypes> = ({ style }) => {
60
66
  style={[Styles.flex, { backgroundColor: PRIMARY_COLOR }]}
61
67
  >
62
68
  <Animated.View
63
- style={{
64
- transform: [{ translateX: linearTranslate }],
65
- width: '60%',
66
- height: '100%',
67
- }}
69
+ style={[
70
+ {
71
+ width: '60%',
72
+ height: '100%',
73
+ },
74
+ shimmerStyle,
75
+ ]}
68
76
  >
69
77
  <LinearGradient
70
78
  style={[StyleSheet.absoluteFill]}
package/Text/utils.ts CHANGED
@@ -4,7 +4,7 @@ import { MiniAppContext } from '../Context';
4
4
 
5
5
  const deviceWidth = Dimensions.get('window').width;
6
6
  const DEFAULT_SCREEN_SIZE = 375;
7
- const MAX_FONT_SCALE = 1.2;
7
+ const MAX_FONT_SCALE = 1.3;
8
8
 
9
9
  const useScaleSize = (size: number) => {
10
10
  const { width } = useWindowDimensions();
package/package.json CHANGED
@@ -1,35 +1,35 @@
1
1
  {
2
- "name": "@momo-kits/foundation",
3
- "version": "0.161.1-beta.2",
4
- "description": "React Native Component Kits",
5
- "main": "index.ts",
6
- "scripts": {},
7
- "keywords": [
8
- "@momo-kits/foundation"
9
- ],
10
- "dependencies": {
11
- "react-native-fast-image": "git+https://oauth2:TGi6oBj-LdzsKpLXQSoH@gitlab.mservice.com.vn/momo-platform/public/react-native-fast-image.git#v8.11.0",
12
- "@react-navigation/bottom-tabs": "7.4.2",
13
- "@react-navigation/core": "7.12.1",
14
- "@react-navigation/elements": "2.5.2",
15
- "@react-navigation/native": "7.1.14",
16
- "@react-navigation/routers": "7.4.1",
17
- "@react-navigation/stack": "7.4.2",
18
- "react-native-gesture-handler": "2.27.1",
19
- "react-native-linear-gradient": "git+https://oauth2:TGi6oBj-LdzsKpLXQSoH@gitlab.mservice.com.vn/momo-platform/public/react-native-linear-gradient#v3.0.0",
20
- "react-native-reanimated": "4.1.0",
21
- "react-native-safe-area-context": "5.5.2",
22
- "@shopify/flash-list": "2.1.0",
23
- "lottie-react-native": "7.2.4"
24
- },
25
- "peerDependencies": {
26
- "react-native": "*"
27
- },
28
- "devDependencies": {
29
- "@types/color": "3.0.6"
30
- },
31
- "publishConfig": {
32
- "registry": "https://registry.npmjs.org/"
33
- },
34
- "license": "MoMo"
35
- }
2
+ "name": "@momo-kits/foundation",
3
+ "version": "0.161.2-beta.5",
4
+ "description": "React Native Component Kits",
5
+ "main": "index.ts",
6
+ "scripts": {},
7
+ "keywords": [
8
+ "@momo-kits/foundation"
9
+ ],
10
+ "dependencies": {
11
+ "react-native-fast-image": "git+https://oauth2:TGi6oBj-LdzsKpLXQSoH@gitlab.mservice.com.vn/momo-platform/public/react-native-fast-image.git#v8.11.0",
12
+ "@react-navigation/bottom-tabs": "7.4.2",
13
+ "@react-navigation/core": "7.12.1",
14
+ "@react-navigation/elements": "2.5.2",
15
+ "@react-navigation/native": "7.1.14",
16
+ "@react-navigation/routers": "7.4.1",
17
+ "@react-navigation/stack": "7.4.2",
18
+ "react-native-gesture-handler": "2.27.1",
19
+ "react-native-linear-gradient": "git+https://oauth2:TGi6oBj-LdzsKpLXQSoH@gitlab.mservice.com.vn/momo-platform/public/react-native-linear-gradient#v3.0.0",
20
+ "react-native-reanimated": "4.2.2",
21
+ "react-native-safe-area-context": "5.5.2",
22
+ "@shopify/flash-list": "2.1.0",
23
+ "lottie-react-native": "7.2.4"
24
+ },
25
+ "peerDependencies": {
26
+ "react-native": "*"
27
+ },
28
+ "devDependencies": {
29
+ "@types/color": "3.0.6"
30
+ },
31
+ "publishConfig": {
32
+ "registry": "https://registry.npmjs.org/"
33
+ },
34
+ "license": "MoMo"
35
+ }