skip to Main Content

The darker translucent ring should be the same thickness as the brighter one but for some reason isn’t The issue starts when I take off the opacity form the ‘foregroung’ circle. I’m not sure why and would appreciate any input! Thanks in advance!

import { View, Text } from 'react-native'
import SVG, { Circle } from 'react-native-svg';

type RingProgressProps = {
    radius?: number;
    strokeWidth?: number;
}

const color = '#EE0F55';

const RingProgress = ({radius = 100, strokeWidth = 20 }: RingProgressProps) => {
    const innerRadius = radius - strokeWidth/2;
    const circumference = 2 * Math.PI * innerRadius;


    return (
        <View 
        style={{
            width: radius*2, 
            height: radius*2, 
            alignSelf: 'center',
            //backgroundColor: 'green'
            }}
            >
                <SVG>
                    {/*Background*/}
                    <Circle 
                    cx={radius}
                    cy={radius}
                    r={innerRadius} 
                    //fill={'blue'}
                    strokeWidth={strokeWidth}
                    stroke={color}
                    opacity={ 0.2 }
                    />
                    {/*Foreground*/}
                    <Circle 
                    cx={radius}
                    cy={radius}
                    r={innerRadius} 
                    //fill={'blue'}
                    strokeWidth={strokeWidth}
                    stroke={color}
                    strokeDasharray={[circumference*.5,circumference]}
                    />

            
                </SVG>


        </View>
    )
}

2

Answers


  1. Add fill="none" in both circle prop, This prevents any fill from overlapping or affecting the appearance of the circles.

    Login or Signup to reply.
  2. import { View, Text } from 'react-native'
    import SVG, { Circle } from 'react-native-svg';
    
    type RingProgressProps = {
    radius?: number;
    strokeWidth?: number;
    }
    
    const color = '#EE0F55';
    
    const RingProgress = ({radius = 100, strokeWidth = 20 }: RingProgressProps) => 
    {
    const innerRadius = radius - strokeWidth/2;
    const circumference = 2 * Math.PI * innerRadius;
    
    return (
        <View 
        style={{
            width: radius*2, 
            height: radius*2, 
            alignSelf: 'center',
            //backgroundColor: 'green'
            }} >
                <SVG>
                    {/Background/}
                    <Circle 
                   fill={'none'}
                    cx={radius}
                    cy={radius}
                    r={innerRadius} 
                    strokeWidth={strokeWidth}
                    stroke={color}
                    opacity={ 0.2 }
                    />
                    {/Foreground/}
                    <Circle 
                   fill={'none'}
                    cx={radius}
                    cy={radius}
                    r={innerRadius} 
                    strokeWidth={strokeWidth}
                    stroke={color}
                    strokeDasharray={[circumference*.5,circumference]}
                    />
                </SVG>
        </View>
      )
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search