fix : progress bar

This commit is contained in:
2025-07-14 17:14:17 +08:00
parent 19c0f0dfbc
commit 5f8fac2518
2 changed files with 10 additions and 4 deletions

View File

@@ -12,6 +12,12 @@ type Props = {
export default function ProgressBar({ margin, value, category }: Props) { export default function ProgressBar({ margin, value, category }: Props) {
const [progress, setProgress] = useState(new Animated.Value(0)); const [progress, setProgress] = useState(new Animated.Value(0));
const [totalProgress, setTotalProgress] = useState(category == 'carousel' ? 232 : category == 'page' ? 245 : 290); const [totalProgress, setTotalProgress] = useState(category == 'carousel' ? 232 : category == 'page' ? 245 : 290);
const [componentWidth, setComponentWidth] = useState(0);
const handleLayout = (event: any) => {
const { width } = event.nativeEvent.layout;
setComponentWidth(width);
};
useEffect(() => { useEffect(() => {
@@ -19,16 +25,16 @@ export default function ProgressBar({ margin, value, category }: Props) {
// carousel:: 100% = 255 // carousel:: 100% = 255
// page:: 100% = 290 // page:: 100% = 290
// wrapbar :: 90% // wrapbar :: 90%
toValue: value / 100 * totalProgress, toValue: value / 100 * componentWidth,
duration: 1000, duration: 1000,
useNativeDriver: false useNativeDriver: false
}).start(); }).start();
}, [value]); }, [value, componentWidth]);
return ( return (
<View style={[Styles.contentItemCenter]}> <View style={[Styles.contentItemCenter]}>
<View style={[Styles.wrapBar, { margin: margin && margin }]}> <View style={[Styles.wrapBar, { margin: margin && margin }]} onLayout={handleLayout}>
<Animated.View style={[Styles.contentBar, { width: progress }]} /> <Animated.View style={[Styles.contentBar, { width: progress }]} />
</View> </View>
</View> </View>

View File

@@ -339,7 +339,7 @@ const Styles = StyleSheet.create({
backgroundColor: '#ccc', backgroundColor: '#ccc',
borderRadius: 10, borderRadius: 10,
margin: 0, margin: 0,
width: '90%' width: '100%'
}, },
contentBar: { contentBar: {
height: 20, height: 20,