react-native-htmlview icon indicating copy to clipboard operation
react-native-htmlview copied to clipboard

Image size has more than 100% witdh

Open rochapablo opened this issue 6 years ago • 6 comments

I'm trying to render the entire html where it has p, a, img tags, but the images seems to be cropped instead be shown as 100% width.

I tried add img style, like normal css, but without success.

const styles = StyleSheet.create({
      a: {
        color: style.content.link.color,
        fontWeight: '300',
      },
      p: {
        color: this.props.data.color,
        fontSize: this.props.data.fontSize,
        lineHeight: this.props.data.lineHeight,
        marginBottom: 0,
        marginTop: 0,
        paddingBottom: 0,
        paddingTop: 0,
      },
    });
<HTMLView
addLineBreaks={false}
value={this.props.data.item.content}
stylesheet={styles}
/>

Imgur

Is there anything to fix this?

"react-native": "0.57.4",
"react-native-htmlview": "^0.13.0",

rochapablo avatar Nov 15 '18 11:11 rochapablo

Having exactly the same issue here. Bump.

3mpetri avatar Nov 28 '18 13:11 3mpetri

Have you solved it

dltjiangfeipeng avatar Apr 16 '19 11:04 dltjiangfeipeng

Noop

rochapablo avatar May 07 '19 16:05 rochapablo

any workaround ?

fmurtadho avatar Oct 14 '19 07:10 fmurtadho

Just add renderNode attribute in HTMLView tag like this <HTMLView value={this.state.content} stylesheet={styles} renderNode={this.renderNode} <-- this line /> Copy and paste renderNode function with your custom styling renderNode(node, index, siblings, parent, defaultRenderer) { if (node.name == 'img') { const a = node.attribs; return ( <Image style={{width: 100, height:100}} source={{uri: a.src}}/> ); } }

HaseemUlHaq avatar Jan 24 '20 20:01 HaseemUlHaq

I did a workaround to solve this issue and it is working fine

import { Image, Dimensions } from 'react-native';

  function renderNode(node) {
    if (node.name === 'img') {
      return (
        <Image
          source={{ uri: node.attribs.src, cache: 'reload' }}
          style={{
            width: 'auto',
            height: node.attribs.height || Dimensions.get('window').height, 
            resizeMode: 'contain',
          }}
        />
      );
    }
  }

 <HTMLView 
   value={content}
 renderNode={renderNode} />

MrOttimista avatar Nov 06 '20 19:11 MrOttimista