renderNode return image not working
See original GitHub issuei have a lot of images in my api that has <img style="height:.. ; width=.." />
others has nothing due to my rich text editor when i render html without calling renderNode my images are not displayed and but whaen i use renderNode like this its works but with static height and width codes below
renderNode (node, index, siblings, parent, defaultRenderer) {
if (node.name === 'img') {
const a = node.attribs;
return (
<Image
key={index}
source={{uri: a.src}}
//resizeMode={'stretch'}
style={{
flex:1,
width: Dimensions.get('window').width ,
height:200
}}
/>
);
}
}
renderNode function to return image with calculated width and height but not working because i want to keep my aspect ration and i decided to use Image.getSize
to return original image size and i used promise because with return brock only would execute before Image.getSize
but this renderNode function return nothing i don’t know where am wrong
renderNode(node, index, siblings, parent, defaultRenderer) {
return new Promise((resolve, reject) => {
let finalwidth;
let finalheight;
if (node.name === 'img') {
const a = node.attribs;
Image.getSize(a.src, (width, height) => {
let screenSize = Dimensions.get('window');
let hRatio = screenSize.width / width;
let vRatio = screenSize.height / height;
let ratio = Math.min(hRatio, vRatio);
let rat = hRatio / vRatio;
finalwidth = parseInt(width * ratio);
finalheight = parseInt(height * ratio);
resolve( <Image key = { index }
source = {{ uri: a.src }}
style = {{
width: finalwidth, //finalwidth is null here
height: finalheight, //finalheight is null here
}}
/>
)
});
}
});
}
this how i render html
<HTMLView
value={data.content.replace(/\r?\n|\r/g, '')}
addLineBreaks={true}
renderNode={this.renderNode}
stylesheet={htmlstyles}
textComponentProps={{ style: styles.defaultStyle }} />
Issue Analytics
- State:
- Created 6 years ago
- Comments:13
Top Results From Across the Web
Render Node issues with Deadline - We Suck Less
Hi, I have been going insane with a deadline setup that worked before, but now refuses to work. I got a laptop connected...
Read more >Contentful: documentToHtmlString doesn't include embedded ...
This is the original answer and hardcoded dynamic values, I hope it can help the reader to have an immediate answer to the...
Read more >RenderNode - Android Developers
Driver. On this page; Hardware acceleration; Creating a RenderNode ... Returns whether or not the RenderNode is clipping to its bounds.
Read more >python - Blender not rendering Background
The scene is showing up on the rendered image, the HDRi image was not. A common recommendation here on SE to fix this...
Read more >Distributed Rendering Troubleshooting Guide
Render Server has not finished loading yet. After starting the render server, it needs some time to fully load and get ready to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello, this is my code. I hope it can help you
PixelRatio.get()
returns the device pixel density.@jaychenjun No, I ended up using my solution.