英文:
How can i change the centre colour of my progress circle
问题
<View style={styles.loadingBar}>
<Progress.CircleSnail color={'#5719a8'} indeterminate={true}/>
</View>
英文:
<View style={styles.loadingBar}>
<Progress.CircleSnail color={'#5719a8'} indeterminate={true}/>
</View>
I have read the documentation and cant find a property to change this color, please see the below image
答案1
得分: 1
我不知道为什么会出现这个错误,但我在查看源代码后找到了以下解决方法:
在 /node_modules/react-native-progress/CircleSnail.js 文件中,在 render()
函数中,在 ...restProps
之前添加 fill = 'transparent'
:
render() {
const {
animating,
children,
color,
...,
strokeCap,
fill = 'transparent', // <---
...restProps
} = this.props;
...
}
并在返回的 <AnimatedArc>
组件中添加 fill
属性:
<Svg width={size} height={size}>
<AnimatedArc
direction={
direction === 'counter-clockwise'
? 'clockwise'
: 'counter-clockwise'
}
radius={radius}
...
strokeWidth={thickness}
fill={fill} // <---
/>
</Svg>
现在你可以简单地使用:
import * as Progress from 'react-native-progress'
// 或者 import ProgressCircleSnail from 'react-native-progress/CircleSnail'
<Progress.CircleSnail // 或者 ProgressCircleSnail(取决于你选择如何导入)
thickness={12}
size={160}
color="#f00"
strokeCap="round"
fill="yellow" // 如果要透明填充,可以完全跳过此属性
/>
英文:
I have no idea why this bug happens, but the workaround I figured out (after looking in the source code) is the following:
Inside /node_modules/react-native-progress/CircleSnail.js, in the render()
function, add fill = 'transparent'
(before the ...restProps
):
render() {
const {
animating,
children,
color,
...,
strokeCap,
fill = 'transparent', // <---
...restProps
} = this.props;
...
}
and in the <AnimatedArc>
component that's being returned add the fill
property:
<Svg width={size} height={size}>
<AnimatedArc
direction={
direction === 'counter-clockwise'
? 'clockwise'
: 'counter-clockwise'
}
radius={radius}
...
strokeWidth={thickness}
fill={fill} // <---
/>
</Svg>
You can now simply use:
import * as Progress from 'react-native-progress'
// or import ProgressCircleSnail from 'react-native-progress/CircleSnail'
<Progress.CircleSnail // or ProgressCircleSnail (depending how you chose to import)
thickness={12}
size={160}
color="#f00"
strokeCap="round"
fill="yellow" // skip this prop altogether for a transparent fill
/>
答案2
得分: 0
你可以使用 Circle Progress 替代 CircleSnail -
import React from 'react';
import { StyleSheet, View } from 'react-native';
import * as Progress from 'react-native-progress'
const MyComponent = () => {
return (
<View style={styles.container}>
<Progress.Circle size={40} indeterminate={true} unfilledColor={"#ff0000"} fill={"#00ff00"} />
<Progress.Circle size={40} indeterminate={true} unfilledColor={"None"} fill={"None"} />
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
}
});
export default MyComponent;
你可以在这里检查这段代码 -
https://snack.expo.dev/fc0Gg2NlQ
英文:
You can use Circle Progress instead of CircleSnail -
import React from 'react';
import { StyleSheet, View } from 'react-native';
import * as Progress from 'react-native-progress'
const MyComponent = () => {
return (
<View style={styles.container}>
<Progress.Circle size={40} indeterminate={true} unfilledColor={"#ff0000"} fill={"#00ff00"} />
<Progress.Circle size={40} indeterminate={true} unfilledColor={"None"} fill={"None"} />
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
}
});
export default MyComponent;
You can try check this code here -
https://snack.expo.dev/fc0Gg2NlQ
答案3
得分: 0
我遇到这个问题的原因是因为我使用的是"react-native-svg@13.9.0",而根据我写这篇文章时的建议,这不是我正在使用的 SDK 的推荐版本;因此,降级到推荐版本解决了我的问题。
从"react-native-svg@13.9.0" ---> 到"react-native-svg@13.4.0"
你可能需要检查你正在使用的版本,并确保它与你正在使用的 SDK 的当前版本兼容。
英文:
The reason I got this bug was because, I was using "react-native-svg@13.9.0" which as of the time of this writing, was not the recommended version for the SDK I was using; thus, downgrading to a recommended version solved this issue for me.
from "react-native-svg@13.9.0" ---> to "react-native-svg@13.4.0"
You might want to check the version you're using and ensure that its compatible with the current version of the SDK you're using.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论