@shoutem/ui 8.1.0-rc.0 → 8.1.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.
package/README.md CHANGED
@@ -30,7 +30,7 @@ Join [our community](https://www.facebook.com/groups/shoutem.community/) on Face
30
30
 
31
31
  ## UI Toolkit
32
32
 
33
- Shoutem UI is a part of the [Shoutem UI Toolkit](https://shoutem.github.io/ui/) that enables you to build professional looking React Native apps with ease.
33
+ Shoutem UI is a part of the [Shoutem UI Toolkit](https://shoutem.github.io/docs/ui-toolkit/introduction) that enables you to build professional looking React Native apps with ease.
34
34
 
35
35
  It consists of three libraries:
36
36
 
@@ -2,22 +2,26 @@
2
2
  import React from 'react';
3
3
  import _ from 'lodash';
4
4
  import PropTypes from 'prop-types';
5
- import { useColorInterpolation } from '../../hooks';
5
+ import { useColorAndPercentageInterpolation } from '../../hooks';
6
6
  import { DEFAULT_PROGRESS_COLORS, PROGRESS_RING_DEFAULT_PROPS } from './const';
7
7
  import ProgressRing from './ProgressRing';
8
8
 
9
9
  const AnimatedProgressRing = props => {
10
10
  const {
11
- percentage = PROGRESS_RING_DEFAULT_PROPS.percentage,
11
+ progressPercentage = PROGRESS_RING_DEFAULT_PROPS.progressPercentage,
12
12
  progressColors = DEFAULT_PROGRESS_COLORS,
13
13
  } = props;
14
14
 
15
- const interpolatedColor = useColorInterpolation(progressColors, percentage);
15
+ const {
16
+ interpolatedColor,
17
+ interpolatedPercentage,
18
+ } = useColorAndPercentageInterpolation(progressColors, progressPercentage);
16
19
 
17
20
  return (
18
21
  <ProgressRing
19
22
  {..._.omit(props, ['progressColors'])}
20
23
  color={interpolatedColor}
24
+ progressPercentage={interpolatedPercentage}
21
25
  />
22
26
  );
23
27
  };
@@ -8,26 +8,25 @@ import { circlePath } from './svgCalculations';
8
8
 
9
9
  const ProgressRing = ({
10
10
  index,
11
- width = PROGRESS_RING_DEFAULT_PROPS.width,
12
- backgroundWidth = PROGRESS_RING_DEFAULT_PROPS.backgroundWidth,
11
+ progressPercentage = PROGRESS_RING_DEFAULT_PROPS.progressPercentage,
12
+ size = PROGRESS_RING_DEFAULT_PROPS.size,
13
+ color = PROGRESS_RING_DEFAULT_PROPS.color,
14
+ progressLineWidth = PROGRESS_RING_DEFAULT_PROPS.progressLineWidth,
15
+ backgroundLineWidth = PROGRESS_RING_DEFAULT_PROPS.backgroundLineWidth,
13
16
  progressLineCap = PROGRESS_RING_DEFAULT_PROPS.progressLineCap,
14
17
  backgroundLineCap = PROGRESS_RING_DEFAULT_PROPS.backgroundLineCap,
15
- percentage = PROGRESS_RING_DEFAULT_PROPS.percentage,
16
- hasBackgroundColor = PROGRESS_RING_DEFAULT_PROPS.hasBackgroundColor,
17
18
  arcSweepAngle = PROGRESS_RING_DEFAULT_PROPS.arcSweepAngle,
18
- size = PROGRESS_RING_DEFAULT_PROPS.size,
19
- color = PROGRESS_RING_DEFAULT_PROPS.color,
20
19
  }) => {
21
20
  const halfSize = size / 2;
22
21
 
23
- const maxWidthCircle = backgroundWidth
24
- ? Math.max(width, backgroundWidth)
25
- : width;
22
+ const maxWidthCircle = backgroundLineWidth
23
+ ? Math.max(progressLineWidth, backgroundLineWidth)
24
+ : progressLineWidth;
26
25
 
27
26
  const radius = halfSize - maxWidthCircle / 2 - index * maxWidthCircle;
28
27
 
29
28
  const currentFillAngle =
30
- (arcSweepAngle * Math.min(100, Math.max(0, percentage))) / 100;
29
+ (arcSweepAngle * Math.min(100, Math.max(0, progressPercentage))) / 100;
31
30
 
32
31
  const backgroundPath = circlePath(
33
32
  halfSize,
@@ -47,20 +46,20 @@ const ProgressRing = ({
47
46
 
48
47
  return (
49
48
  <>
50
- {hasBackgroundColor && (
49
+ {backgroundLineWidth > 0 && (
51
50
  <Path
52
51
  d={backgroundPath}
53
52
  stroke={changeColorAlpha(color, 0.2)}
54
- strokeWidth={backgroundWidth || width}
53
+ strokeWidth={backgroundLineWidth || progressLineWidth}
55
54
  strokeLinecap={backgroundLineCap}
56
55
  fill="transparent"
57
56
  />
58
57
  )}
59
- {percentage > 0 && (
58
+ {progressPercentage > 0 && (
60
59
  <Path
61
60
  d={progressPath}
62
61
  stroke={color}
63
- strokeWidth={width}
62
+ strokeWidth={progressLineWidth}
64
63
  strokeLinecap={progressLineCap}
65
64
  fill="transparent"
66
65
  />
@@ -73,13 +72,12 @@ ProgressRing.propTypes = {
73
72
  index: PropTypes.number.isRequired,
74
73
  arcSweepAngle: PropTypes.number,
75
74
  backgroundLineCap: PropTypes.string,
76
- backgroundWidth: PropTypes.number,
75
+ backgroundLineWidth: PropTypes.number,
77
76
  color: PropTypes.string,
78
- hasBackgroundColor: PropTypes.bool,
79
- percentage: PropTypes.number,
80
77
  progressLineCap: PropTypes.string,
78
+ progressLineWidth: PropTypes.number,
79
+ progressPercentage: PropTypes.number,
81
80
  size: PropTypes.number,
82
- width: PropTypes.number,
83
81
  };
84
82
 
85
83
  export default ProgressRing;
@@ -8,13 +8,12 @@ export const DEFAULT_PROGRESS_COLORS = [
8
8
  ];
9
9
 
10
10
  export const PROGRESS_RING_DEFAULT_PROPS = {
11
- width: 10,
12
- backgroundWidth: 10,
11
+ progressLineWidth: 10,
12
+ backgroundLineWidth: 10,
13
13
  progressLineCap: 'round',
14
14
  backgroundLineCap: 'round',
15
- percentage: 0.1, // 0.1 so that it shows tiny fill indicator, indicating 0%, better UX/UI than empty.
15
+ progressPercentage: 0.1, // 0.1 so that it shows tiny fill indicator, indicating 0%, better UX/UI than empty.
16
16
  arcSweepAngle: 360,
17
17
  size: 80,
18
- hasBackgroundColor: true,
19
18
  color: '#000',
20
19
  };
package/hooks/index.js CHANGED
@@ -1 +1,4 @@
1
- export { useColorInterpolation } from './useColorInterpolation';
1
+ export {
2
+ useColorAndPercentageInterpolation,
3
+ useColorInterpolation,
4
+ } from './useColorAndPercentageInterpolation';
@@ -29,15 +29,15 @@ const resolveInterpolationRange = colors => {
29
29
  };
30
30
  };
31
31
 
32
- export const useColorInterpolation = (colors, percentage) => {
33
- const animatedPercentage = useRef(new Animated.Value(percentage)).current;
32
+ export const useColorInterpolation = (colors, progressPerecentage) => {
33
+ const animatedPercentage = useRef(new Animated.Value(0)).current;
34
34
 
35
35
  const [interpolatedColor, setInterpolatedColor] = useState(colors[0]);
36
36
 
37
37
  useEffect(() => {
38
38
  Animated.timing(animatedPercentage, {
39
- toValue: percentage,
40
- duration: 100,
39
+ toValue: progressPerecentage,
40
+ duration: 1000,
41
41
  useNativeDriver: false, // Color interpolation requires native driver to be false
42
42
  }).start();
43
43
 
@@ -54,7 +54,42 @@ export const useColorInterpolation = (colors, percentage) => {
54
54
  return () => {
55
55
  animatedPercentage.removeListener(listener);
56
56
  };
57
- }, [percentage, colors, animatedPercentage]);
57
+ }, [progressPerecentage, colors, animatedPercentage]);
58
58
 
59
59
  return interpolatedColor;
60
60
  };
61
+
62
+ export const useColorAndPercentageInterpolation = (
63
+ colors,
64
+ progressPerecentage,
65
+ ) => {
66
+ const animatedPercentage = useRef(new Animated.Value(0)).current;
67
+
68
+ const [interpolatedColor, setInterpolatedColor] = useState(colors[0]);
69
+ const [interpolatedPercentage, setInterpolatedPercentage] = useState(0);
70
+
71
+ useEffect(() => {
72
+ Animated.timing(animatedPercentage, {
73
+ toValue: progressPerecentage,
74
+ duration: 1000,
75
+ useNativeDriver: false, // Color interpolation requires native driver to be false
76
+ }).start();
77
+
78
+ // Listen to animatedPercentage value changes and update the interpolated color
79
+ const listener = animatedPercentage.addListener(({ value }) => {
80
+ const colorInterpolation = animatedPercentage.interpolate(
81
+ resolveInterpolationRange(colors),
82
+ );
83
+
84
+ // Resolve the interpolated color to a valid color string
85
+ setInterpolatedColor(colorInterpolation.__getValue());
86
+ setInterpolatedPercentage(value);
87
+ });
88
+
89
+ return () => {
90
+ animatedPercentage.removeListener(listener);
91
+ };
92
+ }, [progressPerecentage, colors, animatedPercentage]);
93
+
94
+ return { interpolatedColor, interpolatedPercentage };
95
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shoutem/ui",
3
- "version": "8.1.0-rc.0",
3
+ "version": "8.1.0",
4
4
  "description": "Styleable set of components for React Native applications",
5
5
  "scripts": {
6
6
  "lint": "eslint .",