File tree Expand file tree Collapse file tree 2 files changed +19
-9
lines changed
Expand file tree Collapse file tree 2 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -16,15 +16,22 @@ import { Text, TextProps } from "../Text"
1616 */
1717export const Skeleton : FC < { children : ReactNode } > = ( { children } ) => {
1818 const opacity = useRef ( new Animated . Value ( 0.5 ) )
19+ const animationRef = useRef < Animated . CompositeAnimation | null > ( null )
1920
2021 useEffect ( ( ) => {
21- Animated . loop (
22+ animationRef . current = Animated . loop (
2223 Animated . timing ( opacity . current , {
2324 toValue : 1 ,
2425 duration : 1000 ,
2526 useNativeDriver : true ,
2627 } )
27- ) . start ( )
28+ )
29+
30+ animationRef . current . start ( )
31+
32+ return ( ) => {
33+ animationRef . current . stop ( )
34+ }
2835 } , [ ] )
2936
3037 return (
Original file line number Diff line number Diff line change 1- import { useEffect , useMemo } from "react"
1+ import { useEffect , useMemo , useRef } from "react"
22import { Animated , Easing , ViewProps } from "react-native"
33import styled from "styled-components/native"
44import { Color } from "../../types"
@@ -58,9 +58,10 @@ export const Spinner: React.FC<SpinnerProps> = ({
5858} ) => {
5959 const color = useColor ( )
6060 const rotation = useMemo ( ( ) => new Animated . Value ( 0 ) , [ ] )
61+ const animationRef = useRef < Animated . CompositeAnimation | null > ( null )
6162
62- const startRotation = ( ) => {
63- Animated . loop (
63+ useEffect ( ( ) => {
64+ animationRef . current = Animated . loop (
6465 Animated . timing ( rotation , {
6566 toValue : 1 ,
6667 duration : 1000 ,
@@ -70,11 +71,13 @@ export const Spinner: React.FC<SpinnerProps> = ({
7071 {
7172 iterations : - 1 ,
7273 }
73- ) . start ( )
74- }
74+ )
7575
76- useEffect ( ( ) => {
77- startRotation ( )
76+ animationRef . current . start ( )
77+
78+ return ( ) => {
79+ animationRef . current . stop ( )
80+ }
7881 } , [ ] )
7982
8083 const style = [
You can’t perform that action at this time.
0 commit comments