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

Couldn't load large image and how do i scale it?

Open dzpt opened this issue 7 years ago • 17 comments

My HTML text has 1500x1500 image, and it couldn't be load properly the result is the blur images.

screen shot 2017-06-27 at 3 29 16 pm ??!

Then, how do i scale and style image? I've tried

img: {
    	width: 100,
		height: 100,
		marginLeft: -10
  	},

But didn't work.

dzpt avatar Jun 26 '17 19:06 dzpt

@Tom29 I'm having some trouble reproducing your problem. I just dumped a 2560x1600 image into an HTMLView and it displayed in proportion, with no blur. You might need to post some more code, and perhaps the image you're testing with.

bas-ie avatar Jul 03 '17 07:07 bas-ie

@richchurcher here is my simple code:

<HTMLView value={'<img src="https://static01.nyt.com/images/2017/06/01/world/01LondonUber4/01LondonUber4-superJumbo-v2.jpg">'} />

And the result is the blur image, it's blur randomly (80%) , refresh few times if you don't see the blur image at the first time.

dzpt avatar Jul 03 '17 18:07 dzpt

Unfortunately I still cannot reproduce. Your image looks fine to me, testing with RN 0.45 and react-native-htmlview 0.10 on Android, even after many reloads.

The fact that it is an intermittent problem is suspicious of a networking issue or even a low memory state. I note that https://github.com/facebook/react-native/issues/10470 describes someone having difficulty loading moderate-sized images... maybe something similar?

To rule out the obvious stuff, I would: upgrade React Native (if you can, that's not always practical) and use the latest version of react-native-htmlview. Letting us know what platform, versions etc you're using might also be helpful but short of a repo to help reproduce the problem, I'm not sure what else to suggest.

bas-ie avatar Jul 03 '17 19:07 bas-ie

@richchurcher I tested on simulator (iOS) and real device (iPhone 7, and 7 plus release mode) react-native-cli: 2.0.1 react-native: 0.44.0 react-native-htmlview latest version.

Both has the same result, blurred images. Have you tested in on iOS?

dzpt avatar Jul 04 '17 03:07 dzpt

Nope, I can't currently test iOS builds (hopefully after this week though). There is some image size and width manipulation that happens under the hood, so it's possible something is going wrong there but I think the way forward would be to publish a minimal repo that reproduces your problem so others can check it. The process might also reveal to you what's happening, or give us some more clues.

If a minimal sample repo doesn't exhibit the problem, then something else in your project may be interacting with/causing the issue. If it does, then it'll enable us to test it and isolate the issue.

bas-ie avatar Jul 04 '17 05:07 bas-ie

@richchurcher you should test in iOS. Because there is no need more code to investigate. Here is my completed file, there's nothing else to conflict the code:

import React from 'react'
import { View } from 'react-native'
import HTMLView from 'react-native-htmlview'

class MainTab extends React.Component 
{
    render() {
		return (
			<View style={{flex:1}}>
            	<HTMLView value={'<img src="https://static01.nyt.com/images/2017/06/01/world/01LondonUber4/01LondonUber4-superJumbo-v2.jpg" />'} />
			</View>
        )
    }
}
module.exports = MainTab

There's no need to create repo, if you haven't tested it with iOS. I think the issue comes from the resizing mechanism.

dzpt avatar Jul 04 '17 07:07 dzpt

Can confirm, this is an issue on iOS, I am having a similar issue. Image appears to be blurry. How do you specify height and width?

RobertWSaunders avatar Jul 05 '17 20:07 RobertWSaunders

Thanks @RobertWSaunders that's useful! Width and height can be passed the old fashioned way, as image attributes I believe (https://github.com/jsdf/react-native-htmlview/blob/master/htmlToElement.js#L18-L24). Try setting an explicit value there and see what happens:

<img src="" width="100" height="100">

I don't think I can explain why the failure is intermittent though :confused:

bas-ie avatar Jul 05 '17 20:07 bas-ie

Thanks @richchurcher, that seems to work! It looks like a strange issue, in some scenarios it starts out blurry and then loads in properly, it does occur with smaller image files as well.

RobertWSaunders avatar Jul 05 '17 20:07 RobertWSaunders

Good. Maybe the docs should make reference to setting width and height explicitly. @Tom29 can you try this and see if it resolves the issue for you?

bas-ie avatar Jul 05 '17 20:07 bas-ie

@richchurcher Yes, it works with specified width and height. But this is hard to use, how do i know size of each one to set width / height for them

dzpt avatar Jul 06 '17 03:07 dzpt

I think the real solution is to allow styles to be set for images, but that'll take a minor-ish PR to sort out.

bas-ie avatar Jul 06 '17 08:07 bas-ie

@richchurcher have you done it yet?

dzpt avatar Jul 19 '17 17:07 dzpt

Nope. PR welcome though! :wink:

bas-ie avatar Jul 22 '17 02:07 bas-ie

I found a solution for me in this issue: https://github.com/jsdf/react-native-htmlview/issues/271

replacing images with components so we can handle widths and heights.

djimenezsi2 avatar Nov 27 '19 14:11 djimenezsi2

how did you replace the image with components?

Aung-Myint-Thein avatar May 07 '21 10:05 Aung-Myint-Thein

how did you replace the image with components?

@Aung-Myint-Thein I just follow the code that you can see also in #271

_renderNode(node, index, siblings, parent, defaultRenderer) {
	if (node.name === 'img') {
            const data = node.attribs;
		return (
                <Image
                      key={index}
                      source={{uri: data.src}}
                      resizeMode="contain"
                      style={{ height: 500, width: 500}}
                    />
                );

		}
    }

djimenezsi2 avatar May 07 '21 11:05 djimenezsi2