Closed gaetandezeiraud closed 2 years ago
@Brouilles Sorry about the delays, I'll get into this before next week!
@Brouilles I have not forgotten you! Still busy with 6.2 refinements and blog post, but I will take a dive after that.
@Brouilles Thanks again for your report and sorry for my late response! I could reproduce the issue with this minimal example (this is actually minimal, just one tag to render):
import React from 'react';
import {StyleSheet, ScrollView, useWindowDimensions} from 'react-native';
import {Colors} from 'react-native/Libraries/NewAppScreen';
import {MixedStyleRecord, RenderHTML} from 'react-native-render-html';
const renderersProps = {
img: {
enableExperimentalPercentWidth: true,
},
};
const tagsStyles: MixedStyleRecord = {
img: {
width: '100%',
},
};
const htmlToConvert = `
<img
src="https://www.halo.fr/wp-content/uploads/2021/09/haloinfinite_fragmentation_01_watermarked_1920x1080.jpg"
alt=""
width="750"
height="422"
/>
`;
const App = () => {
const {width} = useWindowDimensions();
return (
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={styles.scrollView}>
<RenderHTML
contentWidth={width}
renderersProps={renderersProps}
source={{html: htmlToConvert}}
tagsStyles={tagsStyles}
enableCSSInlineProcessing={false}
/>
</ScrollView>
);
};
const styles = StyleSheet.create({
scrollView: {
flex: 1,
backgroundColor: Colors.lighter,
},
body: {
backgroundColor: Colors.white,
},
});
export default App;
The aspect ratio is back to normal when we either:
height
attribute on the img
tagwidth: '100%'
styleenableExperimentalPercentWidth: true
I am going to implement regression tests and provide a fix.
@Brouilles I tested the minimal example that I had created in a web browser, and actually I found this library behavior being very close. This HTML:
<img
src="https://www.halo.fr/wp-content/uploads/2021/09/haloinfinite_fragmentation_01_watermarked_1920x1080.jpg"
alt=""
width="750"
height="422"
style="width: 100%;object-fit: cover;"
/>
Renders in a 400x600 Firefox windows with no body margins like this:
If we remove object-fit: cover
, it is instead stretched:
In the end, the resolved box model for the image element is:
width: '100%'
from the inline style;height: 422
from the height attribute.So the only differences with this library is that:
computeEmbeddedMaxWidth
.object-fit: contain
resize behavior instead of object-fit: fill
.What you were trying to achieve, is to override the height from the attribute. And indeed, the behavior you are looking for can be achieved in a browser with height: auto
:
<img
src="https://www.halo.fr/wp-content/uploads/2021/09/haloinfinite_fragmentation_01_watermarked_1920x1080.jpg"
alt=""
width="750"
height="422"
style="width: 100%; height: auto;"
/>
Unfortunately, our CSS processor doesn't yet understand such keywords. I suggest you submit a feature request to bring support for inherit, auto, initial, unset... etc. See https://native-html.canny.io/features I am going to close now, as it appears this issue is caused by a limitation of the CSS engine and will be best tracked in our feature tracker, but the legitimacy for such feature remains.
Decision Table
<yyy>
is not rendered”Good Faith Declaration
Description
I have set enableExperimentalPercentWidth to true and style with the tagsStyles the image width width: '90%'. But how I can conserve the image ratio? For the height.
I think it is because of height and width on the tag. But don't found a way to disable it. But not sure.
objectFit
orresizeMode
don't help.React Native Information
RNRH Version
6.1.0
Tested Platforms
Reproduction Platforms
Minimal, Reproducible Example
https://github.com/Brouilles/renderhtml-image-reproduction
Additional Notes
No response