Fix for insets on web
This commit is contained in:
@@ -109,23 +109,21 @@ export function Gallery({
|
|||||||
*/
|
*/
|
||||||
const {bleedRef, bleedWidth} = useGalleryBleed()
|
const {bleedRef, bleedWidth} = useGalleryBleed()
|
||||||
const contentRef = useRef<View>(null)
|
const contentRef = useRef<View>(null)
|
||||||
const [insets, setInsets] = useState<{left: number; right: number}>()
|
const [contentDims, setContentDims] = useState<{x: number; width: number}>()
|
||||||
const measure = () => {
|
const measure = () => {
|
||||||
if (contentRef.current && bleedRef.current && bleedWidth > 0) {
|
if (contentRef.current && bleedRef.current) {
|
||||||
contentRef.current.measureLayout(
|
contentRef.current.measureLayout(
|
||||||
bleedRef.current,
|
bleedRef.current,
|
||||||
(x, _y, w) => {
|
(x, _y, w) => {
|
||||||
setInsets({
|
setContentDims({x, width: w})
|
||||||
left: x,
|
|
||||||
right: Math.max(0, bleedWidth - x - w),
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
() => {},
|
() => {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const insetLeft = insets?.left ?? 0
|
const insetLeft = contentDims?.x ?? 0
|
||||||
const insetRight = insets?.right ?? 0
|
const insetRight =
|
||||||
|
bleedWidth - (contentDims?.x || 0) - (contentDims?.width || 0) || 0
|
||||||
const width = bleedWidth || Math.min(600, window.width)
|
const width = bleedWidth || Math.min(600, window.width)
|
||||||
/* End container overflow styles */
|
/* End container overflow styles */
|
||||||
|
|
||||||
@@ -151,15 +149,17 @@ export function Gallery({
|
|||||||
alwaysBounceVertical={false}
|
alwaysBounceVertical={false}
|
||||||
scrollEventThrottle={16}
|
scrollEventThrottle={16}
|
||||||
data={images}
|
data={images}
|
||||||
keyExtractor={(item) => item.thumb}
|
keyExtractor={item => item.thumb}
|
||||||
renderItem={({item}) => {
|
renderItem={({item}) => {
|
||||||
return <GalleryImage image={item} contentHeight={contentHeight} />
|
return <GalleryImage image={item} contentHeight={contentHeight} />
|
||||||
}}
|
}}
|
||||||
style={[{
|
style={[
|
||||||
height: contentHeight,
|
{
|
||||||
marginLeft: -insetLeft,
|
height: contentHeight,
|
||||||
width,
|
marginLeft: -insetLeft,
|
||||||
}]}
|
width,
|
||||||
|
},
|
||||||
|
]}
|
||||||
contentContainerStyle={{
|
contentContainerStyle={{
|
||||||
gap: ITEM_GAP,
|
gap: ITEM_GAP,
|
||||||
paddingLeft: insetLeft,
|
paddingLeft: insetLeft,
|
||||||
@@ -211,7 +211,8 @@ function GalleryImage({
|
|||||||
const dims = computeDims({height, aspectRatio})
|
const dims = computeDims({height, aspectRatio})
|
||||||
|
|
||||||
return (
|
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
|
<Image
|
||||||
source={{uri: image.thumb}}
|
source={{uri: image.thumb}}
|
||||||
contentFit="cover"
|
contentFit="cover"
|
||||||
|
|||||||
Reference in New Issue
Block a user