@brijen/react-native-multistep
Version:
A lightweight multi-step view component for React Native with smooth transitions using Reanimated.
71 lines (70 loc) • 2.16 kB
JavaScript
"use strict";
import { useEffect } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import Svg, { Circle } from 'react-native-svg';
import Animated, { useSharedValue, useAnimatedProps, withTiming } from 'react-native-reanimated';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const AnimatedCircle = Animated.createAnimatedComponent(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 = useSharedValue(0);
useEffect(() => {
progress.value = withTiming(currentStep / totalSteps * circumference, {
duration: 500
});
}, [currentStep, totalSteps, progress, circumference]);
const animatedProps = useAnimatedProps(() => ({
strokeDashoffset: circumference - progress.value
}));
return /*#__PURE__*/_jsxs(View, {
style: styles.container,
children: [/*#__PURE__*/_jsxs(Svg, {
width: size,
height: size,
children: [/*#__PURE__*/_jsx(Circle, {
cx: size / 2,
cy: size / 2,
r: radius,
stroke: trackColor,
strokeWidth: progressCircleThickness,
fill: "none"
}), /*#__PURE__*/_jsx(AnimatedCircle, {
cx: size / 2,
cy: size / 2,
r: radius,
stroke: progressColor,
strokeWidth: progressCircleThickness,
fill: "none",
strokeDasharray: circumference,
animatedProps: animatedProps,
strokeLinecap: "round"
})]
}), /*#__PURE__*/_jsxs(Text, {
style: [styles.progressCircleText, progressCircleLabelStyle],
children: [currentStep, " of ", totalSteps]
})]
});
};
export default ProgressCircle;
const styles = StyleSheet.create({
container: {
alignItems: 'center',
justifyContent: 'center'
},
progressCircleText: {
position: 'absolute',
fontSize: 14,
fontWeight: '600'
}
});
//# sourceMappingURL=ProgressCircle.js.map