Wire up known dimensions to the lightbox

This commit is contained in:
Dan Abramov
2024-11-01 02:30:38 +00:00
parent 0ae5033147
commit 79a61adef7
9 changed files with 38 additions and 13 deletions
@@ -16,4 +16,9 @@ export type Position = {
y: number
}
export type ImageSource = {uri: string; thumbUri: string; alt?: string}
export type ImageSource = {
uri: string
thumbUri: string
alt?: string
dimensions: Dimensions | null
}
@@ -54,7 +54,7 @@ const ImageItem = ({
const [isScaled, setIsScaled] = useState(false)
const imageDimensions = useImageDimensions({
src: imageSrc.uri,
knownDimensions: undefined, // TODO: We have those.
knownDimensions: imageSrc.dimensions,
})
const committedTransform = useSharedValue(initialTransform)
const panTranslation = useSharedValue({x: 0, y: 0})
@@ -49,7 +49,7 @@ const ImageItem = ({
const [scaled, setScaled] = useState(false)
const imageDimensions = useImageDimensions({
src: imageSrc.uri,
knownDimensions: undefined, // TODO: We have those.
knownDimensions: imageSrc.dimensions,
})
const maxZoomScale = imageDimensions
? (imageDimensions.width / SCREEN.width) * MAX_ORIGINAL_IMAGE_ZOOM
@@ -182,7 +182,7 @@ const styles = StyleSheet.create({
})
const getZoomRectAfterDoubleTap = (
imageDimensions: ImageDimensions | undefined,
imageDimensions: ImageDimensions | null,
touchX: number,
touchY: number,
): {
+9 -1
View File
@@ -32,7 +32,15 @@ export function Lightbox() {
return (
<ImageView
images={[
{uri: opts.profile.avatar || '', thumbUri: opts.profile.avatar || ''},
{
uri: opts.profile.avatar || '',
thumbUri: opts.profile.avatar || '',
dimensions: {
// It's fine if it's actually smaller but we know it's 1:1.
height: 1000,
width: 1000,
},
},
]}
initialImageIndex={0}
thumbDims={opts.thumbDims}
+11 -1
View File
@@ -72,7 +72,17 @@ export function ProfileSubpageHeader({
) {
openLightbox({
type: 'images',
images: [{uri: avatar, thumbUri: avatar}],
images: [
{
uri: avatar,
thumbUri: avatar,
dimensions: {
// It's fine if it's actually smaller but we know it's 1:1.
height: 1000,
width: 1000,
},
},
],
index: 0,
thumbDims: null,
})
+2 -2
View File
@@ -19,7 +19,7 @@ function useImageAspectRatio({
knownDimensions,
}: {
src: string
knownDimensions: Dimensions | undefined
knownDimensions: Dimensions | null
}) {
const dims = useImageDimensions({src, knownDimensions})
let constrained: number | undefined
@@ -106,7 +106,7 @@ export function AutoSizedImage({
isCropped: rawIsCropped,
} = useImageAspectRatio({
src: image.thumb,
knownDimensions: image.aspectRatio,
knownDimensions: image.aspectRatio ?? null,
})
const cropDisabled = crop === 'none'
const isCropped = rawIsCropped && !cropDisabled
+1 -1
View File
@@ -145,7 +145,7 @@ export function PostEmbeds({
uri: img.fullsize,
thumbUri: img.thumb,
alt: img.alt,
aspectRatio: img.aspectRatio,
dimensions: img.aspectRatio ?? null,
}))
const _openLightbox = (
index: number,