Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/enhancement/618-ImproveLoadingIn…
Browse files Browse the repository at this point in the history
…dicatorAnimationLoopAndCleanup' into test-branch
  • Loading branch information
oddballdave committed Feb 13, 2025
2 parents 6de9d2f + 2c0e1c6 commit 6aa08ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@department-of-veterans-affairs/mobile-component-library",
"version": "0.30.1-alpha.2",
"version": "0.30.0",
"description": "VA Design System Mobile Component Library",
"main": "src/index.tsx",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Animated, Easing, 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'
import { Text } from '../Text/Text'
import { isAndroid, isIOS } from '../../utils/OSfunctions'
import { useTheme } from '../../utils'

export type LoadingIndicatorProps = {
Expand All @@ -30,19 +31,19 @@ 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
const animation = Animated.loop(
Animated.timing(rotation, {
toValue: 1,
duration: 1500,
easing: Easing.linear,
useNativeDriver: true,
}).start(() => animate()) // Loop the animation
}
animate()
useNativeDriver: isAndroid() || isIOS(),
}),
)
animation.start() // Loop the animation
return () => animation.stop() // Cleanup animation when component unmounts
}, [rotation])

const rotate = rotation.interpolate({
Expand Down

0 comments on commit 6aa08ef

Please sign in to comment.