Skip to content
Open
Changes from all 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
14 changes: 3 additions & 11 deletions src/components/ImageWithLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ function ImageWithLoading({
const isLoadedRef = useRef<boolean | null>(null);
const [isImageCached, setIsImageCached] = useState(true);
const [isLoading, setIsLoading] = useState(false);
// The full-resolution image is not guaranteed to ever emit `onLoad`/`onError` (e.g. a receipt derivative that is
// still being generated server-side), so `isLoading` can stay `true` indefinitely. Once the low-resolution preview
// is on screen we have something readable to show, so the loading state must stop being visible at that point.
const [isThumbnailLoading, setIsThumbnailLoading] = useState(!!previewUri);
const {isOffline} = useNetwork();

const handleError = () => {
Expand Down Expand Up @@ -101,12 +97,9 @@ function ImageWithLoading({
<Image
{...rest}
source={{uri: previewUri}}
style={[styles.w100, styles.h100, style]}
style={[styles.pAbsolute, styles.w100, styles.h100, styles.opacitySemiTransparent, style]}
resizeMode={resizeMode}
onLoad={(e) => {
setIsThumbnailLoading(false);
onLoad?.(e);
}}
onLoad={onLoad}
loadingIconSize={loadingIconSize}
loadingIndicatorStyles={loadingIndicatorStyles}
/>
Expand All @@ -132,13 +125,12 @@ function ImageWithLoading({
isLoadedRef.current = false;
setIsImageCached(false);
setIsLoading(true);
setIsThumbnailLoading(!!previewUri);
waitForSession?.();
}}
loadingIconSize={loadingIconSize}
loadingIndicatorStyles={loadingIndicatorStyles}
/>
{isLoading && (!previewUri || isThumbnailLoading) && !isImageCached && !isOffline && (
{(previewUri ? isLoading : isLoading && !isImageCached) && !isOffline && (
<LoadingIndicator
iconSize={loadingIconSize}
style={[styles.opacity1, styles.bgTransparent, loadingIndicatorStyles]}
Expand Down
Loading