Skip to content

Commit 84d9078

Browse files
authored
Merge pull request Expensify#76498 from apeyada/fix-75095
fix Room - You appear to be offline message appears briefly when view avatar in offline
2 parents bdacdc5 + c145897 commit 84d9078

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/components/ImageView/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ function ImageView({isAuthTokenRequired = false, url, fileName, onError}: ImageV
5454
setContainerSize(e.nativeEvent.layout);
5555
};
5656

57+
const isImageLoaded = imageSize.width > 0 && imageSize.height > 0;
5758
const imageLoadingStart = () => {
58-
if (!isLoading) {
59+
if (isImageLoaded) {
5960
return;
6061
}
6162

@@ -66,6 +67,9 @@ function ImageView({isAuthTokenRequired = false, url, fileName, onError}: ImageV
6667

6768
const imageLoad = ({nativeEvent: size}: ImageOnLoadEvent) => {
6869
setImageSize(size);
70+
};
71+
72+
const imageLoadingEnd = () => {
6973
setIsLoading(false);
7074
};
7175

@@ -189,6 +193,7 @@ function ImageView({isAuthTokenRequired = false, url, fileName, onError}: ImageV
189193
isLocalToUserDeviceFile = false;
190194
}
191195

196+
const shouldShowOfflineIndicator = isOffline && !isLoading && !isLocalToUserDeviceFile;
192197
if (canUseTouchScreen) {
193198
return (
194199
<Lightbox
@@ -207,7 +212,7 @@ function ImageView({isAuthTokenRequired = false, url, fileName, onError}: ImageV
207212
>
208213
<PressableWithoutFeedback
209214
style={{
210-
...StyleUtils.getZoomSizingStyle({imageSize, containerSize, isZoomed, zoomScale, isLoading}),
215+
...StyleUtils.getZoomSizingStyle({imageSize, containerSize, isZoomed, zoomScale, isLoading: !isImageLoaded}),
211216
...StyleUtils.getZoomCursorStyle(isZoomed, isDragging),
212217
...(isZoomed && zoomScale >= 1 ? styles.pRelative : styles.pAbsolute),
213218
...styles.flex1,
@@ -224,6 +229,7 @@ function ImageView({isAuthTokenRequired = false, url, fileName, onError}: ImageV
224229
resizeMode={RESIZE_MODES.contain}
225230
onLoadStart={imageLoadingStart}
226231
onLoad={imageLoad}
232+
onLoadEnd={imageLoadingEnd}
227233
waitForSession={() => {
228234
setImageSize({width: 0, height: 0});
229235
setIsLoading(true);
@@ -233,8 +239,8 @@ function ImageView({isAuthTokenRequired = false, url, fileName, onError}: ImageV
233239
/>
234240
</PressableWithoutFeedback>
235241

236-
{isLoading && (!isOffline || isLocalToUserDeviceFile) && <FullscreenLoadingIndicator style={[styles.opacity1, styles.bgTransparent]} />}
237-
{isLoading && !isLocalToUserDeviceFile && <AttachmentOfflineIndicator />}
242+
{!isImageLoaded && !shouldShowOfflineIndicator && <FullscreenLoadingIndicator style={[styles.opacity1, styles.bgTransparent]} />}
243+
{!isImageLoaded && shouldShowOfflineIndicator && <AttachmentOfflineIndicator />}
238244
</View>
239245
);
240246
}

src/components/Lightbox/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ function Lightbox({attachmentID, isAuthTokenRequired = false, uri, onScaleChange
144144
return !indexOutOfRange;
145145
}, [activePage, hasSiblingCarouselItems, page]);
146146
const [isLightboxImageLoaded, setLightboxImageLoaded] = useState(false);
147+
const [isLoading, setIsLoading] = useState(true);
147148

148149
const [isFallbackVisible, setFallbackVisible] = useState(!isLightboxVisible);
149150
const [isFallbackImageLoaded, setFallbackImageLoaded] = useState(false);
@@ -168,7 +169,7 @@ function Lightbox({attachmentID, isAuthTokenRequired = false, uri, onScaleChange
168169

169170
const isFallbackStillLoading = isFallbackVisible && !isFallbackImageLoaded;
170171
const isLightboxStillLoading = isLightboxVisible && !isLightboxImageLoaded;
171-
const isLoading = isActive && (isCanvasLoading || isFallbackStillLoading || isLightboxStillLoading);
172+
const isImageLoaded = !(isActive && (isCanvasLoading || isFallbackStillLoading || isLightboxStillLoading));
172173

173174
// Resets the lightbox when it becomes inactive
174175
useEffect(() => {
@@ -208,6 +209,7 @@ function Lightbox({attachmentID, isAuthTokenRequired = false, uri, onScaleChange
208209
);
209210

210211
const isALocalFile = isLocalFile(uri);
212+
const shouldShowOfflineIndicator = isOffline && !isLoading && !isALocalFile;
211213

212214
return (
213215
<View
@@ -249,6 +251,9 @@ function Lightbox({attachmentID, isAuthTokenRequired = false, uri, onScaleChange
249251
setContentSize(cachedImageDimensions.get(uri));
250252
setLightboxImageLoaded(false);
251253
}}
254+
onLoadEnd={() => {
255+
setIsLoading(false);
256+
}}
252257
/>
253258
</MultiGestureCanvas>
254259
</View>
@@ -271,13 +276,13 @@ function Lightbox({attachmentID, isAuthTokenRequired = false, uri, onScaleChange
271276
)}
272277

273278
{/* Show activity indicator while the lightbox is still loading the image. */}
274-
{isLoading && (!isOffline || isALocalFile) && (
279+
{!isImageLoaded && !shouldShowOfflineIndicator && (
275280
<ActivityIndicator
276281
size={CONST.ACTIVITY_INDICATOR_SIZE.LARGE}
277282
style={StyleSheet.absoluteFill}
278283
/>
279284
)}
280-
{isLoading && !isALocalFile && <AttachmentOfflineIndicator />}
285+
{!isImageLoaded && shouldShowOfflineIndicator && <AttachmentOfflineIndicator />}
281286
</>
282287
)}
283288
</View>

0 commit comments

Comments
 (0)