Skip to content

Commit 6dcf038

Browse files
committed
fix: SquareImage not showing
1 parent 7db6dd2 commit 6dcf038

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

apps/mobile/src/modules/entry-list/templates/EntryNormalItem.tsx

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { tracker } from "@follow/tracker"
88
import { cn, formatEstimatedMins, formatTimeToSeconds } from "@follow/utils"
99
import { useVideoPlayer, VideoView } from "expo-video"
1010
import { memo, useCallback, useMemo, useRef, useState } from "react"
11+
import type { ImageErrorEventData } from "react-native"
1112
import { StyleSheet, Text, View } from "react-native"
1213

1314
import { useActionLanguage } from "@/src/atoms/settings/general"
@@ -223,19 +224,25 @@ const ThumbnailImage = ({
223224
})
224225
}, [audio, entry?.title, feed?.title, image, isLoading, isPlaying, video, videoPlayer])
225226

227+
const [imageError, setImageError] = useState(audio && !image)
228+
const handleImageError = useCallback(() => {
229+
setImageError(true)
230+
}, [])
231+
226232
if (!image && !audio && !video) return null
227233
const isSquare = thumbnailRatio === "square"
228234
return (
229235
<View className={cn("relative ml-4 h-24 overflow-hidden rounded-lg", isSquare ? "h-24" : "")}>
230236
{image &&
231237
(thumbnailRatio === "square" ? (
232-
<SquareImage image={image} blurhash={blurhash} />
238+
<SquareImage image={image} blurhash={blurhash} onError={handleImageError} />
233239
) : (
234240
<AspectRatioImage
235241
blurhash={blurhash}
236242
image={image}
237243
height={mediaModel?.height}
238244
width={mediaModel?.width}
245+
onError={handleImageError}
239246
/>
240247
))}
241248

@@ -260,7 +267,7 @@ const ThumbnailImage = ({
260267
)}
261268

262269
{/* Show feed icon if no image but audio is present */}
263-
{audio && !image && <FeedIcon feed={feed} size={96} />}
270+
{imageError && <FeedIcon feed={feed} size={96} />}
264271

265272
{(video || audio) && (
266273
<NativePressable
@@ -292,16 +299,16 @@ const AspectRatioImage = ({
292299
blurhash,
293300
height = 96,
294301
width = 96,
302+
onError,
295303
}: {
296304
image: string
297305
blurhash?: string
298306
height?: number
299307
width?: number
308+
onError?: (event: ImageErrorEventData) => void
300309
}) => {
301-
const [isLoading, setIsLoading] = useState(true)
302-
303310
if (height === width || !height || !width) {
304-
return <SquareImage image={image} blurhash={blurhash} />
311+
return <SquareImage image={image} blurhash={blurhash} onError={onError} />
305312
}
306313
// Calculate aspect ratio and determine dimensions
307314
// Ensure the larger dimension is capped at 96px while maintaining aspect ratio
@@ -320,22 +327,7 @@ const AspectRatioImage = ({
320327
}
321328

322329
return (
323-
<View
324-
style={{
325-
width: scaledWidth,
326-
height: scaledHeight,
327-
}}
328-
className="ml-auto overflow-hidden rounded-lg"
329-
>
330-
{isLoading && (
331-
<View
332-
style={{
333-
width: scaledWidth,
334-
height: scaledHeight,
335-
}}
336-
className="bg-system-fill absolute animate-pulse rounded-lg"
337-
/>
338-
)}
330+
<View className="ml-auto flex h-full justify-center overflow-hidden rounded-lg">
339331
<Image
340332
proxy={{
341333
width: 96,
@@ -351,31 +343,38 @@ const AspectRatioImage = ({
351343
blurhash={blurhash}
352344
contentFit="cover"
353345
hideOnError
354-
onLoad={() => setIsLoading(false)}
346+
onError={onError}
355347
/>
356348
</View>
357349
)
358350
}
359351

360-
const SquareImage = ({ image, blurhash }: { image: string; blurhash?: string }) => {
361-
const [isLoading, setIsLoading] = useState(true)
352+
const SquareImage = ({
353+
image,
354+
blurhash,
355+
onError,
356+
}: {
357+
image: string
358+
blurhash?: string
359+
onError?: (event: ImageErrorEventData) => void
360+
}) => {
362361
return (
363362
<View className="size-24 overflow-hidden rounded-lg">
364-
{isLoading && <View className="bg-system-fill absolute inset-0 animate-pulse rounded-lg" />}
365363
<Image
366364
proxy={{
367365
width: 96,
368366
height: 96,
369367
}}
368+
style={{
369+
width: 96,
370+
height: 96,
371+
}}
370372
transition={100}
371373
source={{
372374
uri: image,
373375
}}
374376
blurhash={blurhash}
375-
className="size-24 overflow-hidden rounded-lg"
376-
contentFit="cover"
377-
hideOnError
378-
onLoad={() => setIsLoading(false)}
377+
onError={onError}
379378
/>
380379
</View>
381380
)

0 commit comments

Comments
 (0)