@brijen/react-native-multistep
Version:
A lightweight multi-step view component for React Native with smooth transitions using Reanimated.
77 lines (76 loc) • 3.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _reactNativeSvg = _interopRequireWildcard(require("react-native-svg"));
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
const AnimatedCircle = _reactNativeReanimated.default.createAnimatedComponent(_reactNativeSvg.Circle);
const ProgressCircle = props => {
const {
currentStep,
totalSteps,
size = 65,
progressCircleThickness = 5,
progressColor = '#DE3163',
trackColor = '#E0E0E0',
progressCircleLabelStyle
} = props;
const radius = (size - progressCircleThickness) / 2;
const circumference = 2 * Math.PI * radius;
const progress = (0, _reactNativeReanimated.useSharedValue)(0);
(0, _react.useEffect)(() => {
progress.value = (0, _reactNativeReanimated.withTiming)(currentStep / totalSteps * circumference, {
duration: 500
});
}, [currentStep, totalSteps, progress, circumference]);
const animatedProps = (0, _reactNativeReanimated.useAnimatedProps)(() => ({
strokeDashoffset: circumference - progress.value
}));
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
style: styles.container,
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNativeSvg.default, {
width: size,
height: size,
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.Circle, {
cx: size / 2,
cy: size / 2,
r: radius,
stroke: trackColor,
strokeWidth: progressCircleThickness,
fill: "none"
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(AnimatedCircle, {
cx: size / 2,
cy: size / 2,
r: radius,
stroke: progressColor,
strokeWidth: progressCircleThickness,
fill: "none",
strokeDasharray: circumference,
animatedProps: animatedProps,
strokeLinecap: "round"
})]
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Text, {
style: [styles.progressCircleText, progressCircleLabelStyle],
children: [currentStep, " of ", totalSteps]
})]
});
};
var _default = exports.default = ProgressCircle;
const styles = _reactNative.StyleSheet.create({
container: {
alignItems: 'center',
justifyContent: 'center'
},
progressCircleText: {
position: 'absolute',
fontSize: 14,
fontWeight: '600'
}
});
//# sourceMappingURL=ProgressCircle.js.map