1- import { createElement , Dispatch , SetStateAction , FunctionComponent , useState , Fragment , useCallback } from "react" ;
2- import { Modal , Pressable , LayoutChangeEvent , View , ImageStyle } from "react-native" ;
1+ import {
2+ createElement ,
3+ Dispatch ,
4+ SetStateAction ,
5+ FunctionComponent ,
6+ useState ,
7+ Fragment ,
8+ useCallback ,
9+ useMemo
10+ } from "react" ;
11+ import { Modal , Pressable , LayoutChangeEvent , View , ImageStyle , useWindowDimensions } from "react-native" ;
312import { SvgUri } from "react-native-svg" ;
413import { extractStyles } from "@mendix/pluggable-widgets-tools" ;
514import { OnClickTypeEnum } from "../../typings/ImageProps" ;
6- import { CustomImageObjectProps , onLayoutSetDimensions } from "../utils/imageUtils" ;
15+ import { CustomImageObjectProps , onLayoutSetDimensions , getScaledDimensions } from "../utils/imageUtils" ;
716import { DimensionsType , ImageIconSVG } from "./ImageIconSVG" ;
817import { DefaultImageStyle } from "../ui/Styles.js" ;
918import { DynamicValue } from "mendix" ;
@@ -209,7 +218,6 @@ export const ImageSmall: FunctionComponent<ImageSmallProps> = props => {
209218} ;
210219
211220export const ImageEnlarged : FunctionComponent < ImageEnlargedProps > = props => {
212- const [ dimensions , setDimensions ] = useState < DimensionsType > ( ) ;
213221 const {
214222 visible,
215223 setEnlarged,
@@ -222,12 +230,11 @@ export const ImageEnlarged: FunctionComponent<ImageEnlargedProps> = props => {
222230 screenReaderHint
223231 } = props ;
224232 const [ svgProps ] = extractStyles ( styles . image as ImageStyle , [ "width" , "height" ] ) ;
225- const onLayoutSetDimensionsCallback = useCallback (
226- ( { nativeEvent : { layout } } : LayoutChangeEvent ) => {
227- onLayoutSetDimensions ( layout . width , layout . height , setDimensions , initialDimensions ) ;
228- } ,
229- [ initialDimensions ]
230- ) ;
233+
234+ const { width, height } = useWindowDimensions ( ) ;
235+ const dimensions = useMemo ( ( ) => {
236+ return getScaledDimensions ( width , height , initialDimensions ) ;
237+ } , [ width , height , initialDimensions ] ) ;
231238
232239 return visible && initialDimensions ?. width && initialDimensions ?. height ? (
233240 < Modal
@@ -251,19 +258,11 @@ export const ImageEnlarged: FunctionComponent<ImageEnlargedProps> = props => {
251258 < Pressable
252259 testID = { `${ name } $ImageEnlargedPressable` }
253260 onPress = { ( ) => setEnlarged ( false ) }
254- onLayout = {
255- source . type !== "icon" &&
256- ( ( ! dimensions ?. width && ! svgProps ?. width ) || ( ! dimensions ?. height && ! svgProps ?. height ) )
257- ? onLayoutSetDimensionsCallback
258- : undefined
259- }
260261 style = { styles . backdrop }
261262 >
262- < Pressable
263- onPress = { null }
263+ < View
264+ pointerEvents = "none"
264265 style = { {
265- // The child (FastImage) needs "flexGrow: 1" so images on Android are not blurry.
266- // Therefore we explicitly have to set width / height here to prevent the image from taking up the whole screen, which in turn prevents the user from closing the modal (bc parent Pressable will not be clickable).
267266 width : ( svgProps ?. width ?? dimensions ?. width ) as number ,
268267 height : ( svgProps ?. height ?? dimensions ?. height ) as number
269268 } }
@@ -276,7 +275,7 @@ export const ImageEnlarged: FunctionComponent<ImageEnlargedProps> = props => {
276275 initialDimensions = { initialDimensions }
277276 styles = { styles . image }
278277 />
279- </ Pressable >
278+ </ View >
280279 </ Pressable >
281280 </ Modal >
282281 ) : null ;
0 commit comments