@tra-tech/react-native-kitra
Version:
UI kit for React Native
50 lines • 1.53 kB
JavaScript
import { useState } from 'react';
import { StyleSheet, View } from 'react-native';
import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
import { applyDefaults } from '../../core/KitraProvider';
const ProgressBar = _ref => {
let {
theme,
progress = 0,
barColor,
progressColor,
progressStyle,
testID
} = _ref;
const offset = useSharedValue(progress);
const [barWidth, setBarWidth] = useState(0);
offset.value = progress;
const animatedStyle = useAnimatedStyle(() => ({
width: withTiming(offset.value / 100 * barWidth, {
duration: 400
})
}));
return /*#__PURE__*/React.createElement(View, {
testID: testID,
onLayout: x => setBarWidth(x.nativeEvent.layout.width),
style: [Style.container, {
backgroundColor: barColor || (theme === null || theme === void 0 ? void 0 : theme.primary15)
}]
}, /*#__PURE__*/React.createElement(Animated.View, {
testID: "progressBarAnimation",
style: [animatedStyle, Style.progressStyle, {
backgroundColor: progressColor || (theme === null || theme === void 0 ? void 0 : theme.primary)
}, progressStyle]
}));
};
export default applyDefaults(ProgressBar);
export const Style = StyleSheet.create({
container: {
backgroundColor: 'transparent',
height: 2,
width: '100%',
overflow: 'visible',
justifyContent: 'center'
},
progressStyle: {
borderRadius: 14,
position: 'absolute',
height: 4
}
});
//# sourceMappingURL=ProgressBar.js.map