Skip to content

Commit

Permalink
Patched animation loop to fix issue with detox testing
Browse files Browse the repository at this point in the history
  • Loading branch information
oddballdave committed Dec 19, 2024
1 parent 8fd762f commit 52fb659
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
diff --git a/node_modules/@department-of-veterans-affairs/mobile-component-library/src/components/LoadingIndicator/LoadingIndicator.tsx b/node_modules/@department-of-veterans-affairs/mobile-component-library/src/components/LoadingIndicator/LoadingIndicator.tsx
index dabf3c6..a0c31be 100644
--- a/node_modules/@department-of-veterans-affairs/mobile-component-library/src/components/LoadingIndicator/LoadingIndicator.tsx
+++ b/node_modules/@department-of-veterans-affairs/mobile-component-library/src/components/LoadingIndicator/LoadingIndicator.tsx
@@ -6,7 +6,7 @@ import {
View,
ViewStyle,
} from 'react-native'
-import React, { useEffect } from 'react'
+import React, { useEffect, useRef } from 'react'

import { Icon, IconProps } from '../Icon/Icon'
import { Spacer } from '../Spacer/Spacer'
@@ -36,19 +36,17 @@ export const LoadingIndicator: React.FC<LoadingIndicatorProps> = ({
children,
}) => {
const theme = useTheme()
- const rotation = new Animated.Value(0)
+ const rotation = useRef(new Animated.Value(0)).current

useEffect(() => {
- const animate = () => {
- rotation.setValue(0) // Reset the rotation value to 0
- Animated.timing(rotation, {
- toValue: 1,
- duration: 1500,
- easing: Easing.linear,
- useNativeDriver: true,
- }).start(() => animate()) // Loop the animation
- }
- animate()
+ const animation = Animated.loop(Animated.timing(rotation, {
+ toValue: 1,
+ duration: 1500,
+ easing: Easing.linear,
+ useNativeDriver: true,
+ }))
+ animation.start() // Loop the animation
+ return () => animation.stop() // Cleanup animation when component unmounts
}, [rotation])

const rotate = rotation.interpolate({

0 comments on commit 52fb659

Please sign in to comment.