Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 0 additions & 6 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2259,12 +2259,6 @@ const CONST = {
INITIAL: 'initial',
},

IMAGE_LOADING_PRIORITY: {
LOW: 'low',
NORMAL: 'normal',
HIGH: 'high',
},

FILE_TYPE_REGEX: {
// Image MimeTypes allowed by iOS photos app.
IMAGE: /\.(jpg|jpeg|png|webp|gif|tiff|bmp|heic|heif)$/,
Expand Down
5 changes: 0 additions & 5 deletions src/components/Image/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ type BaseImageProps = {

/** The image cache policy */
cachePolicy?: ImagePrefetchOptions['cachePolicy'];

/** Priorities for completing loads. If more than one load is queued at a time,
* the load with the higher priority will be started first.
* Maps to SDWebImageHighPriority (iOS) and Glide.Priority.IMMEDIATE (Android). */
priority?: ValueOf<typeof CONST.IMAGE_LOADING_PRIORITY> | null;
};

type ImageOwnProps = BaseImageProps & {
Expand Down
32 changes: 4 additions & 28 deletions src/components/Lightbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,8 @@ import CONST from '@src/CONST';
import type {Dimensions} from '@src/types/utils/Layout';
import NUMBER_OF_CONCURRENT_LIGHTBOXES from './numberOfConcurrentLightboxes';

const FALLBACK_OFFSET = 2;

const cachedImageDimensions = new Map<string, Dimensions | undefined>();

function getImagePriority(isActive: boolean, isLightboxVisible: boolean) {
if (isActive) {
return CONST.IMAGE_LOADING_PRIORITY.HIGH;
}
if (isLightboxVisible) {
return CONST.IMAGE_LOADING_PRIORITY.NORMAL;
}
return CONST.IMAGE_LOADING_PRIORITY.LOW;
}

type LightboxProps = Pick<Attachment, 'attachmentID'> & {
/** Whether source url requires authentication */
isAuthTokenRequired?: boolean;
Expand Down Expand Up @@ -158,16 +146,10 @@ function Lightbox({attachmentID, isAuthTokenRequired = false, uri, onScaleChange
const indexOutOfRange = page > activePage + indexCanvasOffset || page < activePage - indexCanvasOffset;
return !indexOutOfRange;
}, [activePage, hasSiblingCarouselItems, page]);

// Limits fallback image rendering to only a few pages around the active page.
// This prevents distant carousel items from queuing unnecessary image downloads,
// which would starve the active image of network bandwidth.
const isFallbackInRange = !hasSiblingCarouselItems || Math.abs(page - activePage) <= FALLBACK_OFFSET;

const [isLightboxImageLoaded, setLightboxImageLoaded] = useState(false);
const [isLoading, setIsLoading] = useState(true);

const [isFallbackVisible, setFallbackVisible] = useState(!isLightboxVisible && isFallbackInRange);
const [isFallbackVisible, setFallbackVisible] = useState(!isLightboxVisible);
const [isFallbackImageLoaded, setFallbackImageLoaded] = useState(false);
const previousUri = usePrevious(uri);

Expand Down Expand Up @@ -234,11 +216,10 @@ function Lightbox({attachmentID, isAuthTokenRequired = false, uri, onScaleChange
}

// If the carousel item has become inactive and the lightbox is not continued to be rendered, we want to show the fallback image
// but only if the page is within the fallback range to avoid unnecessary image downloads
if (!isActive && !isLightboxVisible) {
setFallbackVisible(isFallbackInRange);
setFallbackVisible(true);
}
}, [hasSiblingCarouselItems, isActive, isFallbackInRange, isFallbackVisible, isLightboxImageLoaded, isLightboxVisible]);
}, [hasSiblingCarouselItems, isActive, isFallbackVisible, isLightboxImageLoaded, isLightboxVisible]);

const scaleChange = useCallback(
(scale: number) => {
Expand All @@ -248,14 +229,11 @@ function Lightbox({attachmentID, isAuthTokenRequired = false, uri, onScaleChange
[onScaleChangedContext, onScaleChangedProp],
);

const imagePriority = getImagePriority(isActive, isLightboxVisible);

const isALocalFile = isLocalFile(uri);
const shouldShowOfflineIndicator = isOffline && !isLoading && !isALocalFile;

return (
<View
testID="lightbox-wrapper"
style={[StyleSheet.absoluteFill, style]}
onLayout={updateCanvasSize}
>
Expand All @@ -281,7 +259,6 @@ function Lightbox({attachmentID, isAuthTokenRequired = false, uri, onScaleChange
source={{uri}}
style={[contentSize ?? styles.invisibleImage]}
isAuthTokenRequired={isAuthTokenRequired}
priority={imagePriority}
onError={onError}
onLoad={(e) => {
updateContentSize(e);
Expand All @@ -304,14 +281,13 @@ function Lightbox({attachmentID, isAuthTokenRequired = false, uri, onScaleChange
)}

{/* Keep rendering the image without gestures as fallback if the carousel item is not active and while the lightbox is loading the image */}
{isFallbackVisible && isFallbackInRange && (
{isFallbackVisible && (
<View style={StyleUtils.getFullscreenCenteredContentStyles()}>
<Image
source={{uri}}
resizeMode="contain"
style={[fallbackSize ?? styles.invisibleImage]}
isAuthTokenRequired={isAuthTokenRequired}
priority={imagePriority}
onLoad={(e) => {
updateContentSize(e);
setFallbackImageLoaded(true);
Expand Down
176 changes: 0 additions & 176 deletions tests/unit/LightboxTest.tsx

This file was deleted.

Loading