Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Improve loading indicator animation loop and cleanup #622

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.0",
"version": "0.30.1-alpha.1",
"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(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this not always just be true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, these components also work in a web environment (e.g., the Storybook).

}),
)
animation.start() // Loop the animation
return () => animation.stop() // Cleanup animation when component unmounts
}, [rotation])

const rotate = rotation.interpolate({
Expand Down
Loading