@@ -2,6 +2,7 @@ import delay from 'lodash/delay';
2
2
import React , { useEffect , useMemo , useRef , useState } from 'react' ;
3
3
import type { ImageSourcePropType , StyleProp , ViewStyle } from 'react-native' ;
4
4
import { View } from 'react-native' ;
5
+ import useNetwork from '@hooks/useNetwork' ;
5
6
import useThemeStyles from '@hooks/useThemeStyles' ;
6
7
import Log from '@libs/Log' ;
7
8
import FullscreenLoadingIndicator from './FullscreenLoadingIndicator' ;
@@ -44,16 +45,27 @@ function ImageWithSizeCalculation({url, style, onMeasure, onLoadFailure, isAuthT
44
45
const isLoadedRef = useRef < boolean | null > ( null ) ;
45
46
const [ isImageCached , setIsImageCached ] = useState ( true ) ;
46
47
const [ isLoading , setIsLoading ] = useState ( false ) ;
48
+ const { isOffline} = useNetwork ( ) ;
47
49
48
50
const source = useMemo ( ( ) => ( { uri : url } ) , [ url ] ) ;
49
51
50
52
const onError = ( ) => {
51
53
Log . hmmm ( 'Unable to fetch image to calculate size' , { url} ) ;
52
54
onLoadFailure ?.( ) ;
55
+ if ( isLoadedRef . current ) {
56
+ isLoadedRef . current = false ;
57
+ setIsImageCached ( false ) ;
58
+ }
59
+ if ( isOffline ) {
60
+ return ;
61
+ }
62
+ setIsLoading ( false ) ;
53
63
} ;
54
64
55
65
const imageLoadedSuccessfully = ( event : OnLoadNativeEvent ) => {
56
66
isLoadedRef . current = true ;
67
+ setIsLoading ( false ) ;
68
+ setIsImageCached ( true ) ;
57
69
onMeasure ( {
58
70
width : event . nativeEvent . width ,
59
71
height : event . nativeEvent . height ,
@@ -87,10 +99,6 @@ function ImageWithSizeCalculation({url, style, onMeasure, onLoadFailure, isAuthT
87
99
}
88
100
setIsLoading ( true ) ;
89
101
} }
90
- onLoadEnd = { ( ) => {
91
- setIsLoading ( false ) ;
92
- setIsImageCached ( true ) ;
93
- } }
94
102
onError = { onError }
95
103
onLoad = { imageLoadedSuccessfully }
96
104
/>
0 commit comments