Fix for insets on web

This commit is contained in:
Eric Bailey
2026-04-14 11:48:18 -05:00
parent fb29db5a92
commit 7a4460de48
2 changed files with 16 additions and 15 deletions
+16 -15
View File
@@ -109,23 +109,21 @@ export function Gallery({
*/
const {bleedRef, bleedWidth} = useGalleryBleed()
const contentRef = useRef<View>(null)
const [insets, setInsets] = useState<{left: number; right: number}>()
const [contentDims, setContentDims] = useState<{x: number; width: number}>()
const measure = () => {
if (contentRef.current && bleedRef.current && bleedWidth > 0) {
if (contentRef.current && bleedRef.current) {
contentRef.current.measureLayout(
bleedRef.current,
(x, _y, w) => {
setInsets({
left: x,
right: Math.max(0, bleedWidth - x - w),
})
setContentDims({x, width: w})
},
() => {},
)
}
}
const insetLeft = insets?.left ?? 0
const insetRight = insets?.right ?? 0
const insetLeft = contentDims?.x ?? 0
const insetRight =
bleedWidth - (contentDims?.x || 0) - (contentDims?.width || 0) || 0
const width = bleedWidth || Math.min(600, window.width)
/* End container overflow styles */
@@ -151,15 +149,17 @@ export function Gallery({
alwaysBounceVertical={false}
scrollEventThrottle={16}
data={images}
keyExtractor={(item) => item.thumb}
keyExtractor={item => item.thumb}
renderItem={({item}) => {
return <GalleryImage image={item} contentHeight={contentHeight} />
}}
style={[{
height: contentHeight,
marginLeft: -insetLeft,
width,
}]}
style={[
{
height: contentHeight,
marginLeft: -insetLeft,
width,
},
]}
contentContainerStyle={{
gap: ITEM_GAP,
paddingLeft: insetLeft,
@@ -211,7 +211,8 @@ function GalleryImage({
const dims = computeDims({height, aspectRatio})
return (
<Pressable style={[a.rounded_md, a.overflow_hidden, t.atoms.bg_contrast_25]}>
<Pressable
style={[a.rounded_md, a.overflow_hidden, t.atoms.bg_contrast_25]}>
<Image
source={{uri: image.thumb}}
contentFit="cover"