@@ -272,6 +272,24 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
272272 }
273273 }
274274
275+ function updateImageSize ( width : number , height : number ) {
276+ state . current . imageWidth = width
277+ state . current . imageHeight = height
278+ state . current . ratio = ! width ? 0 : height / width
279+
280+ if ( isWidthFixMode
281+ ? state . current . viewWidth
282+ : isHeightFixMode
283+ ? state . current . viewHeight
284+ : state . current . viewWidth && state . current . viewHeight ) {
285+ setRatio ( state . current . ratio )
286+ setImageWidth ( width )
287+ setImageHeight ( height )
288+ setViewSize ( state . current . viewWidth ! , state . current . viewHeight ! , state . current . ratio )
289+ setLoaded ( true )
290+ }
291+ }
292+
275293 const modeStyle : ImageStyle = useMemo ( ( ) => {
276294 if ( noMeetCalcRule ( isSvg , mode , viewWidth , viewHeight , ratio ) ) return { }
277295 switch ( mode ) {
@@ -370,21 +388,7 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
370388
371389 const onSvgLoad = ( evt : LayoutChangeEvent ) => {
372390 const { width, height } = evt . nativeEvent . layout
373- state . current . imageHeight = height
374- setImageHeight ( height )
375- state . current . ratio = ! width ? 0 : height / width
376-
377- if ( isWidthFixMode
378- ? state . current . viewWidth
379- : isHeightFixMode
380- ? state . current . viewHeight
381- : state . current . viewWidth && state . current . viewHeight ) {
382- setRatio ( state . current . ratio )
383- setImageWidth ( width )
384- setImageHeight ( height )
385- setViewSize ( state . current . viewWidth ! , state . current . viewHeight ! , state . current . ratio )
386- setLoaded ( true )
387- }
391+ updateImageSize ( width , height )
388392
389393 bindload && bindload (
390394 getCustomEvent (
@@ -455,22 +459,7 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
455459 getImageSize (
456460 src ,
457461 ( width : number , height : number ) => {
458- state . current . imageWidth = width
459- state . current . imageHeight = height
460- state . current . ratio = ! width ? 0 : height / width
461-
462- if ( isWidthFixMode
463- ? state . current . viewWidth
464- : isHeightFixMode
465- ? state . current . viewHeight
466- : state . current . viewWidth && state . current . viewHeight ) {
467- setRatio ( state . current . ratio )
468- setImageWidth ( width )
469- setImageHeight ( height )
470- setViewSize ( state . current . viewWidth ! , state . current . viewHeight ! , state . current . ratio ! )
471-
472- setLoaded ( true )
473- }
462+ updateImageSize ( width , height )
474463 } ,
475464 ( ) => {
476465 setLoaded ( true )
0 commit comments