stream-chat-react-native-core
Version:
The official React Native and Expo components for Stream Chat, a service for building chat applications
135 lines • 5.12 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CircularProgressIndicator = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
var _reactNativeSvg = _interopRequireWildcard(require("react-native-svg"));
var _jsxRuntime = require("react/jsx-runtime");
var _jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/components/Attachment/CircularProgressIndicator.tsx";
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 (var _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); }
var AnimatedCircle = _reactNativeReanimated.default.createAnimatedComponent(_reactNativeSvg.Circle);
var SPIN_DURATION_MS = 900;
var PROGRESS_ANIMATION_DURATION_MS = 1200;
var CircularProgressIndicator = ({
backgroundColor,
filledColor,
progress,
size = 16,
strokeWidth = 2,
style,
testID,
unfilledColor
}) => {
var animatedProgress = (0, _reactNativeReanimated.useSharedValue)(0);
var rotation = (0, _reactNativeReanimated.useSharedValue)(0);
var _useMemo = (0, _react.useMemo)(() => {
var pad = strokeWidth / 2;
var rInner = size / 2 - pad;
return {
cx: size / 2,
cy: size / 2,
r: rInner,
circumference: 2 * Math.PI * rInner
};
}, [size, strokeWidth]),
cx = _useMemo.cx,
cy = _useMemo.cy,
r = _useMemo.r,
circumference = _useMemo.circumference;
var fraction = progress === undefined || Number.isNaN(progress) ? undefined : Math.min(100, Math.max(0, progress)) / 100;
(0, _react.useEffect)(() => {
if (fraction === undefined) {
animatedProgress.value = 0;
return;
}
animatedProgress.value = (0, _reactNativeReanimated.withTiming)(fraction, {
duration: PROGRESS_ANIMATION_DURATION_MS,
easing: _reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.cubic)
});
}, [animatedProgress, fraction]);
(0, _react.useEffect)(() => {
if (fraction !== undefined) {
(0, _reactNativeReanimated.cancelAnimation)(rotation);
rotation.value = 0;
return;
}
rotation.value = (0, _reactNativeReanimated.withRepeat)((0, _reactNativeReanimated.withTiming)(360, {
duration: SPIN_DURATION_MS,
easing: _reactNativeReanimated.Easing.linear
}), -1, false);
return () => {
(0, _reactNativeReanimated.cancelAnimation)(rotation);
};
}, [fraction, rotation]);
var animatedCircleProps = (0, _reactNativeReanimated.useAnimatedProps)(() => ({
strokeDashoffset: circumference * (1 - animatedProgress.value)
}));
var animatedSpinStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
transform: [{
rotate: `${rotation.value}deg`
}]
}));
if (fraction !== undefined) {
return (0, _jsxRuntime.jsxs)(_reactNativeSvg.default, {
height: size,
style: style,
testID: testID,
viewBox: `0 0 ${size} ${size}`,
width: size,
children: [(0, _jsxRuntime.jsx)(_reactNativeSvg.Circle, {
cx: cx,
cy: cy,
fill: backgroundColor,
r: r,
stroke: unfilledColor,
strokeWidth: strokeWidth
}), (0, _jsxRuntime.jsx)(AnimatedCircle, {
animatedProps: animatedCircleProps,
cx: cx,
cy: cy,
fill: "none",
r: r,
stroke: filledColor,
strokeDasharray: `${circumference}`,
strokeLinecap: "round",
strokeWidth: strokeWidth,
transform: `rotate(-90 ${cx} ${cy})`
})]
});
}
var arc = circumference * 0.22;
var gap = circumference - arc;
return (0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
style: [{
height: size,
width: size
}, style, animatedSpinStyle],
testID: testID,
children: (0, _jsxRuntime.jsxs)(_reactNativeSvg.default, {
height: size,
viewBox: `0 0 ${size} ${size}`,
width: size,
children: [(0, _jsxRuntime.jsx)(_reactNativeSvg.Circle, {
cx: cx,
cy: cy,
fill: backgroundColor,
r: r,
stroke: unfilledColor,
strokeWidth: strokeWidth
}), (0, _jsxRuntime.jsx)(_reactNativeSvg.Circle, {
cx: cx,
cy: cy,
fill: "none",
r: r,
stroke: filledColor,
strokeDasharray: `${arc} ${gap}`,
strokeLinecap: "round",
strokeWidth: strokeWidth,
transform: `rotate(-90 ${cx} ${cy})`
})]
})
});
};
exports.CircularProgressIndicator = CircularProgressIndicator;
//# sourceMappingURL=CircularProgressIndicator.js.map