@@ -36,12 +36,13 @@ const AnimatedImage = (props: AnimatedImageProps) => {
36
36
loader,
37
37
style,
38
38
onLoad : propsOnLoad ,
39
+ onLoadStart : propsOnLoadStart ,
39
40
animationDuration = 300 ,
40
41
testID,
41
42
...others
42
43
} = props ;
43
44
44
- const [ isLoading , setIsLoading ] = useState ( true ) ;
45
+ const [ isLoading , setIsLoading ] = useState ( false ) ;
45
46
const opacity = useSharedValue ( 0 ) ;
46
47
47
48
useDidUpdate ( ( ) => {
@@ -50,16 +51,23 @@ const AnimatedImage = (props: AnimatedImageProps) => {
50
51
}
51
52
} , [ loader ] ) ;
52
53
53
- const onLoad = useCallback ( ( event : NativeSyntheticEvent < ImageLoadEventData > ) => {
54
- setIsLoading ( false ) ;
55
- propsOnLoad ?.( event ) ;
56
- // did not start the animation already
57
- if ( opacity . value === 0 ) {
58
- opacity . value = withTiming ( 1 , { duration : animationDuration } ) ;
59
- }
60
- } ,
61
- // eslint-disable-next-line react-hooks/exhaustive-deps
62
- [ setIsLoading , propsOnLoad , animationDuration ] ) ;
54
+ const onLoad = useCallback (
55
+ ( event : NativeSyntheticEvent < ImageLoadEventData > ) => {
56
+ setIsLoading ( false ) ;
57
+ propsOnLoad ?.( event ) ;
58
+ // did not start the animation already
59
+ if ( opacity . value === 0 ) {
60
+ opacity . value = withTiming ( 1 , { duration : animationDuration } ) ;
61
+ }
62
+ } ,
63
+ // eslint-disable-next-line react-hooks/exhaustive-deps
64
+ [ setIsLoading , propsOnLoad , animationDuration ]
65
+ ) ;
66
+
67
+ const onLoadStart = useCallback ( ( ) => {
68
+ setIsLoading ( true ) ;
69
+ propsOnLoadStart ?.( ) ;
70
+ } , [ setIsLoading , propsOnLoadStart , animationDuration ] ) ;
63
71
64
72
const fadeInStyle = useAnimatedStyle ( ( ) => {
65
73
return { opacity : opacity . value } ;
@@ -75,6 +83,7 @@ const AnimatedImage = (props: AnimatedImageProps) => {
75
83
style = { _style }
76
84
source = { source }
77
85
onLoad = { onLoad }
86
+ onLoadStart = { onLoadStart }
78
87
testID = { testID }
79
88
imageStyle = { undefined }
80
89
/>
0 commit comments