11import React , { forwardRef } from "react" ;
22import { StyleSheet } from "react-native" ;
33import Animated , {
4+ cancelAnimation ,
45 Easing ,
56 interpolate ,
67 useAnimatedProps ,
@@ -128,9 +129,10 @@ const RNCircularProgress: React.FC<Partial<CircularProgressProps>> = forwardRef<
128129 } ;
129130 } ) ;
130131
131- // Indeterminate Progress
132+ // Indeterminate Progress Code
132133 const progress = useSharedValue ( 0 ) ;
133134 const rotate = useSharedValue ( 0 ) ;
135+
134136 const animatedSvgStyle = useAnimatedStyle ( ( ) => {
135137 const rotateValue = interpolate ( rotate . value , [ 0 , 1 ] , [ 0 , 360 ] ) ;
136138 return {
@@ -141,6 +143,7 @@ const RNCircularProgress: React.FC<Partial<CircularProgressProps>> = forwardRef<
141143 ] ,
142144 } ;
143145 } ) ;
146+
144147 const indeterminateAnimatedCircularProgress = useAnimatedProps ( ( ) => {
145148 return {
146149 strokeDashoffset : interpolate (
@@ -152,23 +155,40 @@ const RNCircularProgress: React.FC<Partial<CircularProgressProps>> = forwardRef<
152155 } ) ;
153156
154157 React . useEffect ( ( ) => {
155- progress . value = withRepeat (
156- withTiming ( 1 , {
157- duration : 1500 ,
158- easing : Easing . linear ,
159- } ) ,
160- - 1 ,
161- false ,
162- ) ;
163- rotate . value = withRepeat (
164- withTiming ( 1 , {
165- duration : 1000 ,
166- easing : Easing . bezier ( 0.4 , 0 , 0.2 , 1 ) ,
167- } ) ,
168- - 1 ,
169- false ,
170- ) ;
171- } , [ progress , rotate ] ) ;
158+ if ( isIndeterminate ) {
159+ progress . value = withRepeat (
160+ withTiming ( 1 , {
161+ duration : 1500 ,
162+ easing : Easing . linear ,
163+ } ) ,
164+ - 1 ,
165+ false ,
166+ finished => {
167+ if ( ! finished ) {
168+ progress . value = 0 ;
169+ }
170+ } ,
171+ ) ;
172+ rotate . value = withRepeat (
173+ withTiming ( 1 , {
174+ duration : 1000 ,
175+ easing : Easing . bezier ( 0.4 , 0 , 0.2 , 1 ) ,
176+ } ) ,
177+ - 1 ,
178+ false ,
179+ finished => {
180+ if ( ! finished ) {
181+ rotate . value = 0 ;
182+ }
183+ } ,
184+ ) ;
185+ } else {
186+ cancelAnimation ( progress ) ;
187+ cancelAnimation ( rotate ) ;
188+ }
189+ } , [ isIndeterminate , progress , rotate ] ) ;
190+
191+ // Indeterminate Progress Code
172192
173193 const circularProgressBoxDimensions = {
174194 width : hint
@@ -185,7 +205,7 @@ const RNCircularProgress: React.FC<Partial<CircularProgressProps>> = forwardRef<
185205 style = { [
186206 circularProgressBoxDimensions ,
187207 styleAdapter ( style ) ,
188- isIndeterminate && animatedSvgStyle ,
208+ isIndeterminate ? animatedSvgStyle : { } ,
189209 ] }
190210 { ...otherProps }
191211 >
0 commit comments