@cdx-ui/primitives 0.3.6 → 0.3.7
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/lib/commonjs/progress-bar/ProgressBarIndicator.js +56 -3
- package/lib/commonjs/progress-bar/ProgressBarIndicator.js.map +1 -1
- package/lib/module/progress-bar/ProgressBarIndicator.js +57 -5
- package/lib/module/progress-bar/ProgressBarIndicator.js.map +1 -1
- package/lib/typescript/progress-bar/ProgressBarIndicator.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/progress-bar/ProgressBarIndicator.tsx +85 -6
|
@@ -6,13 +6,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.ProgressBarIndicator = void 0;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
|
+
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
10
|
+
var _utils = require("@cdx-ui/utils");
|
|
9
11
|
var _slot = require("../slot");
|
|
10
12
|
var _dataAttributes = require("../utils/dataAttributes");
|
|
11
13
|
var _context = require("./context");
|
|
12
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
16
|
+
/**
|
|
17
|
+
* HeroUI indeterminate fill: a 2/5 segment translates from -100% to 350% of its
|
|
18
|
+
* own width over 1.5s (`progress-bar.css`). It enters off the start edge and
|
|
19
|
+
* exits off the end edge; the ease holds the slow parts of that travel off-screen.
|
|
20
|
+
*/
|
|
21
|
+
const INDETERMINATE_WIDTH = '40%';
|
|
22
|
+
const INDETERMINATE_DURATION_MS = 1500;
|
|
23
|
+
const INDETERMINATE_FROM = -1;
|
|
24
|
+
const INDETERMINATE_TO = 3.5;
|
|
13
25
|
const ProgressBarIndicator = exports.ProgressBarIndicator = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
14
26
|
asChild,
|
|
15
27
|
style,
|
|
28
|
+
onLayout,
|
|
16
29
|
...rest
|
|
17
30
|
}, ref) => {
|
|
18
31
|
const {
|
|
@@ -21,7 +34,46 @@ const ProgressBarIndicator = exports.ProgressBarIndicator = /*#__PURE__*/(0, _re
|
|
|
21
34
|
max,
|
|
22
35
|
value
|
|
23
36
|
} = (0, _context.useProgressContext)();
|
|
24
|
-
const
|
|
37
|
+
const isIndeterminate = state === 'indeterminate';
|
|
38
|
+
const reducedMotion = (0, _reactNativeReanimated.useReducedMotion)();
|
|
39
|
+
const travel = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
40
|
+
const segmentWidth = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
41
|
+
const direction = _reactNative.I18nManager.isRTL ? -1 : 1;
|
|
42
|
+
(0, _react.useEffect)(() => {
|
|
43
|
+
if (!isIndeterminate) {
|
|
44
|
+
travel.set(0);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (reducedMotion) {
|
|
48
|
+
travel.set(0);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
travel.set(0);
|
|
52
|
+
travel.set((0, _reactNativeReanimated.withRepeat)((0, _reactNativeReanimated.withTiming)(1, {
|
|
53
|
+
duration: INDETERMINATE_DURATION_MS,
|
|
54
|
+
easing: _reactNativeReanimated.Easing.bezier(0.65, 0, 0.35, 1)
|
|
55
|
+
}), -1, false));
|
|
56
|
+
}, [isIndeterminate, reducedMotion, travel]);
|
|
57
|
+
const handleLayout = event => {
|
|
58
|
+
if (!isIndeterminate) return;
|
|
59
|
+
const next = event.nativeEvent.layout.width;
|
|
60
|
+
if (segmentWidth.get() !== next) {
|
|
61
|
+
segmentWidth.set(next);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const indeterminateStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
65
|
+
const width = segmentWidth.get();
|
|
66
|
+
const span = INDETERMINATE_TO - INDETERMINATE_FROM;
|
|
67
|
+
const offset = reducedMotion ? 0 : width * (INDETERMINATE_FROM + travel.get() * span);
|
|
68
|
+
return {
|
|
69
|
+
width: INDETERMINATE_WIDTH,
|
|
70
|
+
height: '100%',
|
|
71
|
+
transform: [{
|
|
72
|
+
translateX: direction * offset
|
|
73
|
+
}]
|
|
74
|
+
};
|
|
75
|
+
}, [segmentWidth, travel, direction, reducedMotion]);
|
|
76
|
+
const determinateStyle = (0, _react.useMemo)(() => {
|
|
25
77
|
const pct = `${String(percent)}%`;
|
|
26
78
|
return {
|
|
27
79
|
width: pct,
|
|
@@ -33,12 +85,13 @@ const ProgressBarIndicator = exports.ProgressBarIndicator = /*#__PURE__*/(0, _re
|
|
|
33
85
|
value: value === null ? undefined : String(value),
|
|
34
86
|
max: String(max)
|
|
35
87
|
});
|
|
36
|
-
const Comp = asChild ? _slot.Slot :
|
|
88
|
+
const Comp = asChild ? _slot.Slot : _reactNativeReanimated.default.View;
|
|
37
89
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {
|
|
38
90
|
ref: ref,
|
|
39
91
|
...rest,
|
|
40
92
|
...dataAttrs,
|
|
41
|
-
|
|
93
|
+
onLayout: (0, _utils.composeEventHandlers)(onLayout, handleLayout),
|
|
94
|
+
style: [isIndeterminate ? indeterminateStyle : determinateStyle, style]
|
|
42
95
|
});
|
|
43
96
|
});
|
|
44
97
|
ProgressBarIndicator.displayName = 'ProgressBarIndicator';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_reactNative","_slot","_dataAttributes","_context","_jsxRuntime","ProgressBarIndicator","exports","forwardRef","asChild","style","rest","ref","percent","state","max","value","useProgressContext","
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_reactNativeReanimated","_interopRequireWildcard","_utils","_slot","_dataAttributes","_context","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","INDETERMINATE_WIDTH","INDETERMINATE_DURATION_MS","INDETERMINATE_FROM","INDETERMINATE_TO","ProgressBarIndicator","exports","forwardRef","asChild","style","onLayout","rest","ref","percent","state","max","value","useProgressContext","isIndeterminate","reducedMotion","useReducedMotion","travel","useSharedValue","segmentWidth","direction","I18nManager","isRTL","useEffect","withRepeat","withTiming","duration","easing","Easing","bezier","handleLayout","event","next","nativeEvent","layout","width","indeterminateStyle","useAnimatedStyle","span","offset","height","transform","translateX","determinateStyle","useMemo","pct","String","dataAttrs","dataAttributes","undefined","Comp","Slot","Animated","View","jsx","composeEventHandlers","displayName"],"sourceRoot":"../../../src","sources":["progress-bar/ProgressBarIndicator.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAOA,IAAAE,sBAAA,GAAAC,uBAAA,CAAAH,OAAA;AAQA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,eAAA,GAAAN,OAAA;AACA,IAAAO,QAAA,GAAAP,OAAA;AAA+C,IAAAQ,WAAA,GAAAR,OAAA;AAAA,SAAAG,wBAAAM,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAR,uBAAA,YAAAA,CAAAM,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA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
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { forwardRef, useMemo } from 'react';
|
|
4
|
-
import {
|
|
3
|
+
import { forwardRef, useEffect, useMemo } from 'react';
|
|
4
|
+
import { I18nManager } from 'react-native';
|
|
5
|
+
import Animated, { Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withRepeat, withTiming } from 'react-native-reanimated';
|
|
6
|
+
import { composeEventHandlers } from '@cdx-ui/utils';
|
|
5
7
|
import { Slot } from '../slot';
|
|
6
8
|
import { dataAttributes } from '../utils/dataAttributes';
|
|
7
9
|
import { useProgressContext } from './context';
|
|
8
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
/**
|
|
12
|
+
* HeroUI indeterminate fill: a 2/5 segment translates from -100% to 350% of its
|
|
13
|
+
* own width over 1.5s (`progress-bar.css`). It enters off the start edge and
|
|
14
|
+
* exits off the end edge; the ease holds the slow parts of that travel off-screen.
|
|
15
|
+
*/
|
|
16
|
+
const INDETERMINATE_WIDTH = '40%';
|
|
17
|
+
const INDETERMINATE_DURATION_MS = 1500;
|
|
18
|
+
const INDETERMINATE_FROM = -1;
|
|
19
|
+
const INDETERMINATE_TO = 3.5;
|
|
9
20
|
export const ProgressBarIndicator = /*#__PURE__*/forwardRef(({
|
|
10
21
|
asChild,
|
|
11
22
|
style,
|
|
23
|
+
onLayout,
|
|
12
24
|
...rest
|
|
13
25
|
}, ref) => {
|
|
14
26
|
const {
|
|
@@ -17,7 +29,46 @@ export const ProgressBarIndicator = /*#__PURE__*/forwardRef(({
|
|
|
17
29
|
max,
|
|
18
30
|
value
|
|
19
31
|
} = useProgressContext();
|
|
20
|
-
const
|
|
32
|
+
const isIndeterminate = state === 'indeterminate';
|
|
33
|
+
const reducedMotion = useReducedMotion();
|
|
34
|
+
const travel = useSharedValue(0);
|
|
35
|
+
const segmentWidth = useSharedValue(0);
|
|
36
|
+
const direction = I18nManager.isRTL ? -1 : 1;
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!isIndeterminate) {
|
|
39
|
+
travel.set(0);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (reducedMotion) {
|
|
43
|
+
travel.set(0);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
travel.set(0);
|
|
47
|
+
travel.set(withRepeat(withTiming(1, {
|
|
48
|
+
duration: INDETERMINATE_DURATION_MS,
|
|
49
|
+
easing: Easing.bezier(0.65, 0, 0.35, 1)
|
|
50
|
+
}), -1, false));
|
|
51
|
+
}, [isIndeterminate, reducedMotion, travel]);
|
|
52
|
+
const handleLayout = event => {
|
|
53
|
+
if (!isIndeterminate) return;
|
|
54
|
+
const next = event.nativeEvent.layout.width;
|
|
55
|
+
if (segmentWidth.get() !== next) {
|
|
56
|
+
segmentWidth.set(next);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const indeterminateStyle = useAnimatedStyle(() => {
|
|
60
|
+
const width = segmentWidth.get();
|
|
61
|
+
const span = INDETERMINATE_TO - INDETERMINATE_FROM;
|
|
62
|
+
const offset = reducedMotion ? 0 : width * (INDETERMINATE_FROM + travel.get() * span);
|
|
63
|
+
return {
|
|
64
|
+
width: INDETERMINATE_WIDTH,
|
|
65
|
+
height: '100%',
|
|
66
|
+
transform: [{
|
|
67
|
+
translateX: direction * offset
|
|
68
|
+
}]
|
|
69
|
+
};
|
|
70
|
+
}, [segmentWidth, travel, direction, reducedMotion]);
|
|
71
|
+
const determinateStyle = useMemo(() => {
|
|
21
72
|
const pct = `${String(percent)}%`;
|
|
22
73
|
return {
|
|
23
74
|
width: pct,
|
|
@@ -29,12 +80,13 @@ export const ProgressBarIndicator = /*#__PURE__*/forwardRef(({
|
|
|
29
80
|
value: value === null ? undefined : String(value),
|
|
30
81
|
max: String(max)
|
|
31
82
|
});
|
|
32
|
-
const Comp = asChild ? Slot : View;
|
|
83
|
+
const Comp = asChild ? Slot : Animated.View;
|
|
33
84
|
return /*#__PURE__*/_jsx(Comp, {
|
|
34
85
|
ref: ref,
|
|
35
86
|
...rest,
|
|
36
87
|
...dataAttrs,
|
|
37
|
-
|
|
88
|
+
onLayout: composeEventHandlers(onLayout, handleLayout),
|
|
89
|
+
style: [isIndeterminate ? indeterminateStyle : determinateStyle, style]
|
|
38
90
|
});
|
|
39
91
|
});
|
|
40
92
|
ProgressBarIndicator.displayName = 'ProgressBarIndicator';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["forwardRef","useMemo","
|
|
1
|
+
{"version":3,"names":["forwardRef","useEffect","useMemo","I18nManager","Animated","Easing","useAnimatedStyle","useReducedMotion","useSharedValue","withRepeat","withTiming","composeEventHandlers","Slot","dataAttributes","useProgressContext","jsx","_jsx","INDETERMINATE_WIDTH","INDETERMINATE_DURATION_MS","INDETERMINATE_FROM","INDETERMINATE_TO","ProgressBarIndicator","asChild","style","onLayout","rest","ref","percent","state","max","value","isIndeterminate","reducedMotion","travel","segmentWidth","direction","isRTL","set","duration","easing","bezier","handleLayout","event","next","nativeEvent","layout","width","get","indeterminateStyle","span","offset","height","transform","translateX","determinateStyle","pct","String","dataAttrs","undefined","Comp","View","displayName"],"sourceRoot":"../../../src","sources":["progress-bar/ProgressBarIndicator.tsx"],"mappings":";;AAAA,SAASA,UAAU,EAAEC,SAAS,EAAEC,OAAO,QAAQ,OAAO;AACtD,SACEC,WAAW,QAKN,cAAc;AACrB,OAAOC,QAAQ,IACbC,MAAM,EACNC,gBAAgB,EAChBC,gBAAgB,EAChBC,cAAc,EACdC,UAAU,EACVC,UAAU,QACL,yBAAyB;AAChC,SAASC,oBAAoB,QAAQ,eAAe;AACpD,SAASC,IAAI,QAAQ,SAAS;AAC9B,SAASC,cAAc,QAAQ,yBAAyB;AACxD,SAASC,kBAAkB,QAAQ,WAAW;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAI/C;AACA;AACA;AACA;AACA;AACA,MAAMC,mBAAmB,GAAG,KAAK;AACjC,MAAMC,yBA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AE3C,oBACE5C,IAAA,CAAC2C,IAAI;IACHjC,GAAG,EAAEA,GAAI;IAAA,GACLD,IAAI;IAAA,GACJgC,SAAS;IACbjC,QAAQ,EAAEb,oBAAoB,CAACa,QAAQ,EAAEiB,YAAY,CAAE;IACvDlB,KAAK,EAAE,CAACQ,eAAe,GAAGiB,kBAAkB,GAAGM,gBAAgB,EAAE/B,KAAK;EAAE,CACzE,CAAC;AAEN,CACF,CAAC;AAEDF,oBAAoB,CAACwC,WAAW,GAAG,sBAAsB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProgressBarIndicator.d.ts","sourceRoot":"","sources":["../../../src/progress-bar/ProgressBarIndicator.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"ProgressBarIndicator.d.ts","sourceRoot":"","sources":["../../../src/progress-bar/ProgressBarIndicator.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,IAAI,EAEJ,KAAK,SAAS,EAEf,MAAM,cAAc,CAAC;AA0BtB,MAAM,WAAW,yBAA0B,SAAQ,SAAS;IAC1D,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,eAAO,MAAM,oBAAoB,4GAyEhC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdx-ui/primitives",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
"@react-stately/disclosure": "3.1.1",
|
|
70
70
|
"@react-stately/radio": "3.12.0",
|
|
71
71
|
"@react-stately/toggle": "3.9.4",
|
|
72
|
-
"@cdx-ui/formatters": "0.3.
|
|
73
|
-
"@cdx-ui/utils": "0.3.
|
|
72
|
+
"@cdx-ui/formatters": "0.3.7",
|
|
73
|
+
"@cdx-ui/utils": "0.3.7"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/react": "19.2.14",
|
|
@@ -1,20 +1,91 @@
|
|
|
1
|
-
import { forwardRef, useMemo } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { forwardRef, useEffect, useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
I18nManager,
|
|
4
|
+
View,
|
|
5
|
+
type LayoutChangeEvent,
|
|
6
|
+
type ViewProps,
|
|
7
|
+
type ViewStyle,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
import Animated, {
|
|
10
|
+
Easing,
|
|
11
|
+
useAnimatedStyle,
|
|
12
|
+
useReducedMotion,
|
|
13
|
+
useSharedValue,
|
|
14
|
+
withRepeat,
|
|
15
|
+
withTiming,
|
|
16
|
+
} from 'react-native-reanimated';
|
|
17
|
+
import { composeEventHandlers } from '@cdx-ui/utils';
|
|
3
18
|
import { Slot } from '../slot';
|
|
4
19
|
import { dataAttributes } from '../utils/dataAttributes';
|
|
5
20
|
import { useProgressContext } from './context';
|
|
6
21
|
|
|
7
22
|
type PercentString = `${number}%`;
|
|
8
23
|
|
|
24
|
+
/**
|
|
25
|
+
* HeroUI indeterminate fill: a 2/5 segment translates from -100% to 350% of its
|
|
26
|
+
* own width over 1.5s (`progress-bar.css`). It enters off the start edge and
|
|
27
|
+
* exits off the end edge; the ease holds the slow parts of that travel off-screen.
|
|
28
|
+
*/
|
|
29
|
+
const INDETERMINATE_WIDTH = '40%';
|
|
30
|
+
const INDETERMINATE_DURATION_MS = 1500;
|
|
31
|
+
const INDETERMINATE_FROM = -1;
|
|
32
|
+
const INDETERMINATE_TO = 3.5;
|
|
33
|
+
|
|
9
34
|
export interface ProgressBarIndicatorProps extends ViewProps {
|
|
10
35
|
readonly asChild?: boolean;
|
|
11
36
|
}
|
|
12
37
|
|
|
13
38
|
export const ProgressBarIndicator = forwardRef<View, ProgressBarIndicatorProps>(
|
|
14
|
-
({ asChild, style, ...rest }, ref) => {
|
|
39
|
+
({ asChild, style, onLayout, ...rest }, ref) => {
|
|
15
40
|
const { percent, state, max, value } = useProgressContext();
|
|
41
|
+
const isIndeterminate = state === 'indeterminate';
|
|
42
|
+
const reducedMotion = useReducedMotion();
|
|
43
|
+
const travel = useSharedValue(0);
|
|
44
|
+
const segmentWidth = useSharedValue(0);
|
|
45
|
+
const direction = I18nManager.isRTL ? -1 : 1;
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!isIndeterminate) {
|
|
49
|
+
travel.set(0);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (reducedMotion) {
|
|
53
|
+
travel.set(0);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
travel.set(0);
|
|
57
|
+
travel.set(
|
|
58
|
+
withRepeat(
|
|
59
|
+
withTiming(1, {
|
|
60
|
+
duration: INDETERMINATE_DURATION_MS,
|
|
61
|
+
easing: Easing.bezier(0.65, 0, 0.35, 1),
|
|
62
|
+
}),
|
|
63
|
+
-1,
|
|
64
|
+
false,
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
}, [isIndeterminate, reducedMotion, travel]);
|
|
68
|
+
|
|
69
|
+
const handleLayout = (event: LayoutChangeEvent) => {
|
|
70
|
+
if (!isIndeterminate) return;
|
|
71
|
+
const next = event.nativeEvent.layout.width;
|
|
72
|
+
if (segmentWidth.get() !== next) {
|
|
73
|
+
segmentWidth.set(next);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const indeterminateStyle = useAnimatedStyle(() => {
|
|
78
|
+
const width = segmentWidth.get();
|
|
79
|
+
const span = INDETERMINATE_TO - INDETERMINATE_FROM;
|
|
80
|
+
const offset = reducedMotion ? 0 : width * (INDETERMINATE_FROM + travel.get() * span);
|
|
81
|
+
return {
|
|
82
|
+
width: INDETERMINATE_WIDTH,
|
|
83
|
+
height: '100%',
|
|
84
|
+
transform: [{ translateX: direction * offset }],
|
|
85
|
+
};
|
|
86
|
+
}, [segmentWidth, travel, direction, reducedMotion]);
|
|
16
87
|
|
|
17
|
-
const
|
|
88
|
+
const determinateStyle = useMemo((): ViewStyle => {
|
|
18
89
|
const pct = `${String(percent)}%` as PercentString;
|
|
19
90
|
return { width: pct, height: '100%' };
|
|
20
91
|
}, [percent]);
|
|
@@ -25,9 +96,17 @@ export const ProgressBarIndicator = forwardRef<View, ProgressBarIndicatorProps>(
|
|
|
25
96
|
max: String(max),
|
|
26
97
|
});
|
|
27
98
|
|
|
28
|
-
const Comp = asChild ? Slot : View;
|
|
99
|
+
const Comp = asChild ? Slot : Animated.View;
|
|
29
100
|
|
|
30
|
-
return
|
|
101
|
+
return (
|
|
102
|
+
<Comp
|
|
103
|
+
ref={ref}
|
|
104
|
+
{...rest}
|
|
105
|
+
{...dataAttrs}
|
|
106
|
+
onLayout={composeEventHandlers(onLayout, handleLayout)}
|
|
107
|
+
style={[isIndeterminate ? indeterminateStyle : determinateStyle, style]}
|
|
108
|
+
/>
|
|
109
|
+
);
|
|
31
110
|
},
|
|
32
111
|
);
|
|
33
112
|
|