@particle-network/ui-native 0.7.0-beta.7 → 0.7.0-beta.9

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,40 +1,71 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { useMemo, useState } from "react";
3
- import { StyleSheet, View } from "react-native";
2
+ import { useCallback, useMemo, useState } from "react";
3
+ import { View } from "react-native";
4
4
  import react_native_svg, { Path } from "react-native-svg";
5
5
  import { useColors, useRadius } from "../../hooks/index.js";
6
6
  import { Flex } from "../layout/Flex/index.js";
7
+ function createPathData(x, y, w, h, r) {
8
+ if (0 === r) return `
9
+ M ${x + w} ${y + h}
10
+ L ${x} ${y + h}
11
+ L ${x} ${y}
12
+ L ${x + w} ${y}
13
+ Z
14
+ `;
15
+ return `
16
+ M ${x + w - r} ${y + h}
17
+ L ${x + r} ${y + h}
18
+ Q ${x} ${y + h} ${x} ${y + h - r}
19
+ L ${x} ${y + r}
20
+ Q ${x} ${y} ${x + r} ${y}
21
+ L ${x + w - r} ${y}
22
+ Q ${x + w} ${y} ${x + w} ${y + r}
23
+ L ${x + w} ${y + h - r}
24
+ Q ${x + w} ${y + h} ${x + w - r} ${y + h}
25
+ Z
26
+ `;
27
+ }
7
28
  const ProgressWrapper = ({ style, svgStyle, value = 0, width, height, radius = 'sm', strokeWidth = 1, color = 'primary', children, ...restProps })=>{
8
29
  const { getColor } = useColors();
9
30
  const { getRadius } = useRadius();
10
31
  const autoLayout = !width && !height;
11
32
  const [childWidth, setChildWidth] = useState(0);
12
33
  const [childHeight, setChildHeight] = useState(0);
13
- const widthValue = useMemo(()=>{
14
- if (width) return width;
15
- return childWidth + 2 * strokeWidth;
16
- }, [
17
- childWidth,
18
- strokeWidth,
19
- width
34
+ const radiusValue = useMemo(()=>getRadius(radius), [
35
+ getRadius,
36
+ radius
20
37
  ]);
21
- const heightValue = useMemo(()=>{
22
- if (height) return height;
23
- return childHeight + 2 * strokeWidth;
38
+ const { widthValue, heightValue, svgWidth, svgHeight, pathData, perimeter, strokeDashoffset } = useMemo(()=>{
39
+ const w = width ?? childWidth + 2 * strokeWidth;
40
+ const h = height ?? childHeight + 2 * strokeWidth;
41
+ const padding = strokeWidth;
42
+ const sw = w + padding;
43
+ const sh = h + padding;
44
+ const rectWidth = w - strokeWidth;
45
+ const rectHeight = h - strokeWidth;
46
+ const rectXY = strokeWidth / 2 + padding / 2;
47
+ const p = 2 * (rectWidth + rectHeight);
48
+ const clamped = Math.max(0, Math.min(100, value));
49
+ const offset = p * (1 - clamped / 100);
50
+ const path = createPathData(rectXY, rectXY, rectWidth, rectHeight, radiusValue);
51
+ return {
52
+ widthValue: w,
53
+ heightValue: h,
54
+ svgWidth: sw,
55
+ svgHeight: sh,
56
+ pathData: path,
57
+ perimeter: p,
58
+ strokeDashoffset: offset
59
+ };
24
60
  }, [
61
+ width,
62
+ height,
63
+ childWidth,
25
64
  childHeight,
26
65
  strokeWidth,
27
- height
66
+ value,
67
+ radiusValue
28
68
  ]);
29
- const clampedProgress = Math.max(0, Math.min(100, value));
30
- const padding = strokeWidth;
31
- const svgWidth = widthValue + padding;
32
- const svgHeight = heightValue + padding;
33
- const rectWidth = widthValue - strokeWidth;
34
- const rectHeight = heightValue - strokeWidth;
35
- const rectXY = strokeWidth / 2 + padding / 2;
36
- const perimeter = 2 * (rectWidth + rectHeight);
37
- const strokeDashoffset = perimeter * (1 - clampedProgress / 100);
38
69
  const colorValue = useMemo(()=>{
39
70
  if ('transparent' === color) return 'transparent';
40
71
  if (color.startsWith('#')) return color;
@@ -50,50 +81,30 @@ const ProgressWrapper = ({ style, svgStyle, value = 0, width, height, radius = '
50
81
  color,
51
82
  colorValue
52
83
  ]);
53
- const radiusValue = getRadius(radius);
54
- const createPathData = (x, y, w, h, r)=>{
55
- if (0 === r) return `
56
- M ${x + w} ${y + h}
57
- L ${x} ${y + h}
58
- L ${x} ${y}
59
- L ${x + w} ${y}
60
- Z
61
- `;
62
- return `
63
- M ${x + w - r} ${y + h}
64
- L ${x + r} ${y + h}
65
- Q ${x} ${y + h} ${x} ${y + h - r}
66
- L ${x} ${y + r}
67
- Q ${x} ${y} ${x + r} ${y}
68
- L ${x + w - r} ${y}
69
- Q ${x + w} ${y} ${x + w} ${y + r}
70
- L ${x + w} ${y + h - r}
71
- Q ${x + w} ${y + h} ${x + w - r} ${y + h}
72
- Z
73
- `;
74
- };
75
- const pathData = createPathData(rectXY, rectXY, rectWidth, rectHeight, radiusValue);
76
- const styles = StyleSheet.create({
77
- container: {
84
+ const containerStyle = useMemo(()=>({
78
85
  width: widthValue,
79
86
  height: heightValue
80
- },
81
- svg: {
87
+ }), [
88
+ widthValue,
89
+ heightValue
90
+ ]);
91
+ const svgPositionStyle = useMemo(()=>({
82
92
  position: 'absolute',
83
- left: -padding / 2,
84
- top: -padding / 2
85
- }
86
- });
87
- const handleLayout = (event)=>{
88
- const { width, height } = event.nativeEvent.layout;
89
- setChildWidth(width);
90
- setChildHeight(height);
91
- };
93
+ left: -strokeWidth / 2,
94
+ top: -strokeWidth / 2
95
+ }), [
96
+ strokeWidth
97
+ ]);
98
+ const handleLayout = useCallback((event)=>{
99
+ const { width: w, height: h } = event.nativeEvent.layout;
100
+ setChildWidth(w);
101
+ setChildHeight(h);
102
+ }, []);
92
103
  return /*#__PURE__*/ jsxs(Flex, {
93
104
  center: true,
94
105
  h: heightValue,
95
106
  style: [
96
- styles.container,
107
+ containerStyle,
97
108
  style
98
109
  ],
99
110
  w: widthValue,
@@ -102,7 +113,7 @@ const ProgressWrapper = ({ style, svgStyle, value = 0, width, height, radius = '
102
113
  /*#__PURE__*/ jsxs(react_native_svg, {
103
114
  height: svgHeight,
104
115
  style: [
105
- styles.svg,
116
+ svgPositionStyle,
106
117
  svgStyle
107
118
  ],
108
119
  width: svgWidth,
@@ -40,8 +40,8 @@ const useStyles = (props)=>{
40
40
  ]);
41
41
  const borderColor = useMemo(()=>{
42
42
  if (isInvalid) return getColor('danger');
43
- if (isFocused) return getColor('default' === color ? 'secondary' : color);
44
- if ('bordered' === variant) return getColor('default' === color ? 'secondary' : color);
43
+ if (isFocused) return getColor(color);
44
+ if ('bordered' === variant) return getColor(color);
45
45
  return 'transparent';
46
46
  }, [
47
47
  color,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@particle-network/ui-native",
3
- "version": "0.7.0-beta.7",
3
+ "version": "0.7.0-beta.9",
4
4
  "main": "./entry.js",
5
5
  "react-native": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -53,8 +53,8 @@
53
53
  "react-native-size-matters": "^0.4.2",
54
54
  "react-native-toast-message": "^2.3.3",
55
55
  "react-native-worklets": "0.5.1",
56
- "@particle-network/icons": "0.7.0-beta.5",
57
- "@particle-network/ui-shared": "0.5.0"
56
+ "@particle-network/ui-shared": "0.5.0",
57
+ "@particle-network/icons": "0.7.0-beta.5"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@babel/core": "^7.24.0",