@momo-kits/foundation 0.77.7 → 0.77.8-beta.1

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,39 @@
1
+ import React, {FC, useContext} from 'react';
2
+ import {View, ViewProps} from 'react-native';
3
+ import AnimatedLottieView from 'lottie-react-native';
4
+ import animation from '../Assets/DotAnimation.json';
5
+ import {ApplicationContext} from '../Application';
6
+ import {hexToRGBA} from './utils';
7
+
8
+ const DotLoader: FC<ViewProps> = ({style}) => {
9
+ const {theme} = useContext(ApplicationContext);
10
+
11
+ const arrayColor = [
12
+ theme.colors.primary,
13
+ theme.colors.secondary,
14
+ theme.colors.primary,
15
+ ];
16
+
17
+ let source = animation;
18
+ source.assets[0].layers[0].shapes[0].it.forEach(item => {
19
+ if (item.ty === 'fl' && item.c) {
20
+ item.c.k.forEach((fillItem, index) => {
21
+ if (typeof fillItem !== 'number') {
22
+ fillItem.s = hexToRGBA(arrayColor[index]);
23
+ }
24
+ });
25
+ }
26
+ });
27
+
28
+ return (
29
+ <View style={style}>
30
+ <AnimatedLottieView
31
+ source={source}
32
+ style={{width: 52, height: 18}}
33
+ autoPlay
34
+ />
35
+ </View>
36
+ );
37
+ };
38
+
39
+ export default DotLoader;
@@ -0,0 +1,14 @@
1
+ import React, {FC} from 'react';
2
+ import {LoaderProps} from './types';
3
+ import DotLoader from './DotLoader';
4
+ import Spinner from './Spinner';
5
+
6
+ const Loader: FC<LoaderProps> = ({type = 'dot', style}) => {
7
+ if (type === 'spinner') {
8
+ return <Spinner style={style} />;
9
+ }
10
+
11
+ return <DotLoader style={style} />;
12
+ };
13
+
14
+ export default Loader;
@@ -0,0 +1,44 @@
1
+ import React, {FC, useContext, useEffect, useRef} from 'react';
2
+ import {Animated, View} from 'react-native';
3
+ import styles from './styles';
4
+ import {ProgressBarProps} from './types';
5
+ import {ApplicationContext} from '../Application';
6
+ import {Radius} from '../Consts';
7
+
8
+ const ProgressBar: FC<ProgressBarProps> = ({percent = 0, style}) => {
9
+ const {theme} = useContext(ApplicationContext);
10
+ const animation = useRef(new Animated.Value(0)).current;
11
+
12
+ useEffect(() => {
13
+ Animated.timing(animation, {
14
+ toValue: percent,
15
+ duration: 200,
16
+ useNativeDriver: false,
17
+ }).start();
18
+ }, [percent, animation]);
19
+
20
+ const width = animation.interpolate({
21
+ inputRange: [0, 100],
22
+ outputRange: ['0%', '100%'],
23
+ });
24
+
25
+ return (
26
+ <View
27
+ style={[
28
+ style,
29
+ styles.progressContainer,
30
+ {backgroundColor: theme.colors.background.default},
31
+ ]}>
32
+ <Animated.View
33
+ style={{
34
+ height: 4,
35
+ borderRadius: Radius.XXS,
36
+ width,
37
+ backgroundColor: theme.colors.primary,
38
+ }}
39
+ />
40
+ </View>
41
+ );
42
+ };
43
+
44
+ export default ProgressBar;
@@ -0,0 +1,31 @@
1
+ import React, {FC, useContext} from 'react';
2
+ import {View, ViewProps} from 'react-native';
3
+ import AnimatedLottieView from 'lottie-react-native';
4
+ import animation from '../Assets/SpinnerAnimation.json';
5
+ import {hexToRGBA} from './utils';
6
+ import {ApplicationContext} from '../Application';
7
+
8
+ const Spinner: FC<ViewProps> = ({style}) => {
9
+ const {theme} = useContext(ApplicationContext);
10
+
11
+ let source = animation;
12
+ source.assets[0].layers.forEach(layer => {
13
+ layer.shapes[0].it.forEach(item => {
14
+ if (item.ty === 'fl' && item.c) {
15
+ item.c.k = hexToRGBA(theme.colors.primary);
16
+ }
17
+ });
18
+ });
19
+
20
+ return (
21
+ <View style={style}>
22
+ <AnimatedLottieView
23
+ source={source}
24
+ style={{width: 24, height: 24}}
25
+ autoPlay
26
+ />
27
+ </View>
28
+ );
29
+ };
30
+
31
+ export default Spinner;
@@ -0,0 +1,4 @@
1
+ import Loader from './Loader';
2
+ import ProgressBar from './ProgressBar';
3
+
4
+ export {Loader, ProgressBar};
@@ -0,0 +1,10 @@
1
+ import {StyleSheet} from 'react-native';
2
+ import {Radius} from '../Consts';
3
+
4
+ export default StyleSheet.create({
5
+ progressContainer: {
6
+ width: '100%',
7
+ height: 4,
8
+ borderRadius: Radius.XXS,
9
+ },
10
+ });
@@ -0,0 +1,11 @@
1
+ import {ViewStyle} from 'react-native';
2
+
3
+ export type LoaderProps = {
4
+ type?: 'dot' | 'spinner';
5
+ style?: ViewStyle | ViewStyle[];
6
+ };
7
+
8
+ export type ProgressBarProps = {
9
+ percent: number;
10
+ style?: ViewStyle | ViewStyle[];
11
+ };
@@ -0,0 +1,26 @@
1
+ export const hexToRGBA = (hex: string) => {
2
+ const normalizedHex = hex.startsWith('#') ? hex.slice(1) : hex;
3
+
4
+ if (!/^([0-9A-Fa-f]{3}){1,2}$/.test(normalizedHex)) {
5
+ console.log(hex);
6
+ throw new Error('Invalid HEX color.');
7
+ }
8
+
9
+ const expandedHex =
10
+ normalizedHex.length === 3
11
+ ? normalizedHex
12
+ .split('')
13
+ .map(val => val + val)
14
+ .join('')
15
+ : normalizedHex;
16
+
17
+ const hexMatch = expandedHex.match(/.{2}/g);
18
+
19
+ if (!hexMatch) {
20
+ throw new Error('HEX parsing failed.');
21
+ }
22
+
23
+ return hexMatch
24
+ .map(val => parseInt(val, 16))
25
+ .map(val => Math.round((val / 255) * 1000) / 1000);
26
+ };
package/index.ts CHANGED
@@ -43,3 +43,5 @@ export * from './Tag';
43
43
  export * from './Tag/types';
44
44
  export * from './Pagination';
45
45
  export * from './Pagination/types';
46
+ export * from './Loader';
47
+ export * from './Loader/types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.77.7",
3
+ "version": "0.77.8-beta.01",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {