如何更改我的进度圆的中心颜色。

huangapple go评论67阅读模式
英文:

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} // &lt;---
  />
</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 = &#39;transparent&#39; (before the ...restProps):

render() {
  const {
    animating,
    children,
    color,
    ...,
    strokeCap,
    fill = &#39;transparent&#39;, // &lt;---
    ...restProps
  } = this.props;

  ...
}

and in the &lt;AnimatedArc&gt; component that's being returned add the fill property:

&lt;Svg width={size} height={size}&gt;
  &lt;AnimatedArc
    direction={
      direction === &#39;counter-clockwise&#39;
        ? &#39;clockwise&#39;
        : &#39;counter-clockwise&#39;
      }
    radius={radius}
    ...
    strokeWidth={thickness}
    fill={fill} // &lt;---
  /&gt;
&lt;/Svg&gt;

You can now simply use:

import * as Progress from &#39;react-native-progress&#39;
// or import ProgressCircleSnail from &#39;react-native-progress/CircleSnail&#39;

&lt;Progress.CircleSnail // or ProgressCircleSnail (depending how you chose to import)
  thickness={12}
  size={160}
  color=&quot;#f00&quot;
  strokeCap=&quot;round&quot;
  fill=&quot;yellow&quot; // skip this prop altogether for a transparent fill
/&gt;

答案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 &#39;react&#39;;
import { StyleSheet, View } from &#39;react-native&#39;;
import * as Progress from &#39;react-native-progress&#39;

const MyComponent = () =&gt; {
  return (
    &lt;View style={styles.container}&gt;
      &lt;Progress.Circle size={40} indeterminate={true} unfilledColor={&quot;#ff0000&quot;} fill={&quot;#00ff00&quot;} /&gt;

      &lt;Progress.Circle size={40} indeterminate={true} unfilledColor={&quot;None&quot;} fill={&quot;None&quot;} /&gt;
    &lt;/View&gt;
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: &#39;column&#39;,
    justifyContent: &#39;center&#39;,
    alignItems: &#39;center&#39;,
    backgroundColor: &#39;white&#39;,
  }
});
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.

huangapple
  • 本文由 发表于 2023年5月29日 21:51:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76357937.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定