1- import React from 'react' ;
1+ import React , { useMemo } from 'react' ;
22import { TBlock } from '@native-html/transient-render-engine' ;
33import IMGElement , { IMGElementProps } from '../elements/IMGElement' ;
44import { InternalBlockRenderer } from '../render/render-types' ;
55import { useComputeMaxWidthForTag } from '../context/SharedPropsProvider' ;
6- import { ImageStyle } from 'react-native' ;
6+ import { ImageStyle , StyleSheet } from 'react-native' ;
77import { InternalRendererProps } from '../shared-types' ;
88import useNormalizedUrl from '../hooks/useNormalizedUrl' ;
99import { useRendererProps } from '../context/RenderersPropsProvider' ;
1010import useContentWidth from '../hooks/useContentWidth' ;
11+ import getNativePropsForTNode from '../helpers/getNativePropsForTNode' ;
1112
1213/**
1314 * A hook to produce props consumable by {@link IMGElement} component
@@ -16,23 +17,30 @@ import useContentWidth from '../hooks/useContentWidth';
1617export function useIMGElementProps (
1718 props : InternalRendererProps < TBlock >
1819) : IMGElementProps {
19- const { style, tnode, onPress } = props ;
20+ const { tnode } = props ;
21+
2022 const contentWidth = useContentWidth ( ) ;
2123 const { initialDimensions, enableExperimentalPercentWidth } =
2224 useRendererProps ( 'img' ) ;
2325 const computeImagesMaxWidth = useComputeMaxWidthForTag ( 'img' ) ;
2426 const src = tnode . attributes . src || '' ;
27+ const source = { uri : useNormalizedUrl ( src ) } ;
28+ const { style : rawStyle , ...containerProps } = getNativePropsForTNode ( props ) ;
29+ const style = useMemo < ImageStyle > (
30+ ( ) => ( rawStyle ? ( StyleSheet . flatten ( rawStyle ) as ImageStyle ) : { } ) ,
31+ [ rawStyle ]
32+ ) ;
2533 return {
2634 contentWidth,
27- computeMaxWidth : computeImagesMaxWidth ,
35+ containerProps ,
2836 enableExperimentalPercentWidth,
2937 initialDimensions,
30- onPress ,
31- alt : tnode . attributes . alt ,
38+ source ,
39+ style ,
3240 testID : 'img' ,
41+ computeMaxWidth : computeImagesMaxWidth ,
42+ alt : tnode . attributes . alt ,
3343 altColor : tnode . styles . nativeTextFlow . color as string ,
34- source : { uri : useNormalizedUrl ( src ) } ,
35- style : style as ImageStyle ,
3644 width : tnode . attributes . width ,
3745 height : tnode . attributes . height ,
3846 objectFit : tnode . styles . webBlockRet . objectFit
0 commit comments