-
-
Notifications
You must be signed in to change notification settings - Fork 588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
image getting blur issue #141
Comments
Hello, I had the same issue (only tested on iOS 10 on iPhone 6S). I spent a lot of time aimlessly debugging and I think I figured it out.
In other words, if we avoid rendering the image until we know the actual size to render it, it doesn't get blurred. 10c10,11
< height: props.imagesInitialDimensions.height
---
> height: props.imagesInitialDimensions.height,
> indeterminate: (!props.style || !props.style.width || !props.style.height)
80c81,82
< height: typeof styleHeight === 'string' && styleHeight.search('%') !== -1 ? styleHeight : parseInt(styleHeight, 10)
---
> height: typeof styleHeight === 'string' && styleHeight.search('%') !== -1 ? styleHeight : parseInt(styleHeight, 10),
> indeterminate: false
92c94
< this.setState({ width: optimalWidth, height: optimalHeight, error: false });
---
> this.setState({ width: optimalWidth, height: optimalHeight, indeterminate: false, error: false });
117a120,125
> get placeholderImage () {
> return (
> <View style={{width: this.props.imagesInitialDimensions.width, height: this.props.imagesInitialDimensions.height}} />
> );
> }
>
120,121c128,134
<
< return !this.state.error ? this.validImage(source, style, passProps) : this.errorImage;
---
> if (this.state.error) {
> return this.errorImage;
> }
> if (this.state.indeterminate) {
> return this.placeholderImage;
> }
> return this.validImage(source, style, passProps); I'm not sure if this is a React Native bug or an issue with this library. I'm a React Native noob so I'm not really sure what I'm doing. Shall I submit a PR? BTW here's a screenshot of the bug in action, the upper image is given fixed dimensions via style props and the bottom one has its dimensions automatically determined, they are the same size (800x600 real pixels) and imagesMaxWidth is set to 360. After applying this diff to HTMLImage.js this bug no longer occurs Edit: applied the diff to this fork: https://github.com/guregu/react-native-render-html |
Thanks for your input @guregu, this makes a lot of sense. I'll take a look into this later and maybe try to trigger a re-render instead of waiting for the image to be loaded to render it. I don't think the UX would be very good if the height of the content changes while the user is reading it. |
Thanks @guregu it worked perfect, i have also done with little hack, i did edit HTMLimage.js and gave to static height, but now i am happy with your code |
Here is the patch content you can use with https://www.npmjs.com/package/patch-package
|
This really work well!! |
@JaeWangL
|
@guregu Thanks you for your proposition! You don't mind if I cherry-pick your patch and integrate it to the next 5.0 release? You'll be credited of course, since I'll be using the |
@guregu It is my understanding that your solution had a small bug, because diff --git a/src/HTMLImage.js b/src/HTMLImage.js
index 558c7c3..ca1fec8 100644
--- a/src/HTMLImage.js
+++ b/src/HTMLImage.js
@@ -5,10 +5,11 @@ import PropTypes from 'prop-types';
export default class HTMLImage extends PureComponent {
constructor (props) {
super(props);
+ const { styleWidth, styleHeight } = this.getDimensionsFromStyle(props.style, props.height, props.width);
this.state = {
width: props.imagesInitialDimensions.width,
height: props.imagesInitialDimensions.height,
- indeterminate: (!props.style || !props.style.width || !props.style.height)
+ indeterminate: !(styleWidth && styleHeight)
};
} |
@jsamr Hello, feel free to use my code however you’d like. |
@guregu Awesome! Thank you. |
BREAKING: imagesMaxWidth prop is discontinued in favor of contentWidth and computeImagesMaxWidth. See RFC001 for an exhaustive description. This patch offers a rewrite of the HTMLImage component to get a close match with RFC001, “a deterministic approach to images scaling”. The only part of this RFC which is unsupported is the unitConverter behavior, which is planned for a later major release. In addition to the capabilities defined in the RFC, this patch provides the new property enableExperimentalPercentWidth. It allows percent width for <img> tags, computed relatively to contentWidth. This patch also fixes #141, #172 and provides the features offered in PR #242 and #315. fixes #141 fixes #172 closes #315 closes #242
BREAKING: imagesMaxWidth prop is discontinued in favor of contentWidth and computeImagesMaxWidth. See RFC001 for an exhaustive description. This patch offers a rewrite of the HTMLImage component to get a close match with RFC001, “a deterministic approach to images scaling”. The only part of this RFC which is unsupported is the unitConverter behavior, which is planned for a later major release. In addition to the capabilities defined in the RFC, this patch provides the new property enableExperimentalPercentWidth. It allows percent width for <img> tags, computed relatively to contentWidth. This patch also fixes #141, #172 and provides the features offered in PR #242 and #315. fixes #141 fixes #172 closes #315 closes #242
BREAKING: imagesMaxWidth prop is discontinued in favor of contentWidth and computeImagesMaxWidth. See RFC001 for an exhaustive description. This patch offers a rewrite of the HTMLImage component to get a close match with RFC001, “a deterministic approach to images scaling”. The only part of this RFC which is unsupported is the unitConverter behavior, which is planned for a later major release. In addition to the capabilities defined in the RFC, this patch provides the following features and behaviors: - new property enableExperimentalPercentWidth. It allows percent width for <img> tags, computed relatively to contentWidth. - take margins into account when scaling down images; - support for overriding image styles, including resizeMode; - support for minWidth, minHeight, maxWidth, maxHeight styles. This patch also fixes #141, #172 and provides the features offered in PR #242 and #315. fixes #141 fixes #172 closes #315 closes #242
BREAKING: imagesMaxWidth prop is discontinued in favor of contentWidth and computeImagesMaxWidth. See RFC001 for an exhaustive description. This patch offers a rewrite of the HTMLImage component to get a close match with RFC001, “a deterministic approach to images scaling”. The only part of this RFC which is unsupported is the unitConverter behavior, which is planned for a later major release. In addition to the capabilities defined in the RFC, this patch provides the following features and behaviors: - new property enableExperimentalPercentWidth. It allows percent width for <img> tags, computed relatively to contentWidth. - take margins into account when scaling down images; - support for overriding image styles, including resizeMode; - support for minWidth, minHeight, maxWidth, maxHeight styles. This patch also fixes #141, #172 and provides the features offered in PR #242 and #315. fixes #141 fixes #172 closes #315 closes #242
BREAKING: imagesMaxWidth prop is discontinued in favor of contentWidth and computeImagesMaxWidth. See RFC001 for an exhaustive description. This patch offers a rewrite of the HTMLImage component to get a close match with RFC001, “a deterministic approach to images scaling”. The only part of this RFC which is unsupported is the unitConverter behavior, which is planned for a later major release. In addition to the capabilities defined in the RFC, this patch provides the following features and behaviors: - new property enableExperimentalPercentWidth. It allows percent width for <img> tags, computed relatively to contentWidth. - take margins into account when scaling down images; - support for overriding image styles, including resizeMode; - support for minWidth, minHeight, maxWidth, maxHeight styles. This patch also fixes #141, #172 and provides the features offered in PR #242 and #315. fixes #141 fixes #172 closes #315 closes #242
BREAKING: imagesMaxWidth prop is discontinued in favor of contentWidth and computeImagesMaxWidth. See RFC001 for an exhaustive description. This patch offers a rewrite of the HTMLImage component to get a close match with RFC001, “a deterministic approach to images scaling”. The only part of this RFC which is unsupported is the unitConverter behavior, which is planned for a later major release. In addition to the capabilities defined in the RFC, this patch provides the following features and behaviors: - new property enableExperimentalPercentWidth. It allows percent width for <img> tags, computed relatively to contentWidth. - take margins into account when scaling down images; - support for overriding image styles, including resizeMode; - support for minWidth, minHeight, maxWidth, maxHeight styles. This patch also fixes #141, #172 and provides the features offered in PR #242 and #315. fixes #141 fixes #172 closes #315 closes #242
BREAKING: imagesMaxWidth prop is discontinued in favor of contentWidth and computeImagesMaxWidth. See RFC001 for an exhaustive description. This patch offers a rewrite of the HTMLImage component to get a close match with RFC001, “a deterministic approach to images scaling”. The only part of this RFC which is unsupported is the unitConverter behavior, which is planned for a later major release. In addition to the capabilities defined in the RFC, this patch provides the following features and behaviors: - new property enableExperimentalPercentWidth. It allows percent width for <img> tags, computed relatively to contentWidth. - take margins into account when scaling down images; - support for overriding image styles, including resizeMode; - support for minWidth, minHeight, maxWidth, maxHeight styles. This patch also fixes #141, #172 and provides the features offered in PR #242 and #315. fixes #141 fixes #172 closes #315 closes #242
BREAKING: imagesMaxWidth prop is discontinued in favor of contentWidth and computeImagesMaxWidth. See RFC001 for an exhaustive description. This patch offers a rewrite of the HTMLImage component to get a close match with RFC001, “a deterministic approach to images scaling”. The only part of this RFC which is unsupported is the unitConverter behavior, which is planned for a later major release. In addition to the capabilities defined in the RFC, this patch provides the following features and behaviors: - new property enableExperimentalPercentWidth. It allows percent width for <img> tags, computed relatively to contentWidth. - take margins into account when scaling down images; - support for overriding image styles, including resizeMode; - support for minWidth, minHeight, maxWidth, maxHeight styles. This patch also fixes #141, #172 and provides the features offered in PR #242 and #315. fixes #141 fixes #172 closes #315 closes #242
BREAKING: imagesMaxWidth prop is discontinued in favor of contentWidth and computeImagesMaxWidth. See RFC001 for an exhaustive description. This patch offers a rewrite of the HTMLImage component to get a close match with RFC001, “a deterministic approach to images scaling”. The only part of this RFC which is unsupported is the unitConverter behavior, which is planned for a later major release. In addition to the capabilities defined in the RFC, this patch provides the following features and behaviors: - new property enableExperimentalPercentWidth. It allows percent width for <img> tags, computed relatively to contentWidth. - take margins into account when scaling down images; - support for overriding image styles, including resizeMode; - support for minWidth, minHeight, maxWidth, maxHeight styles. This patch also fixes #141, #172 and provides the features offered in PR #242 and #315. OPTIMIZATIONS: The imageBoxDimensions are computed when required. In addition, requirements are also recomputed when necessary, preventing expensive operations from happening too often. Also, because we need to flatten the style prop to infer requirements, this flatten value is now cached and re-evaluated when appropriate. Finally, styles have been moved to a stylesheet when that is possible, to avoid commiting updates to the native side. Note that these performance optimizations are made possible by the high coverage rate of the HTMLImage component. fixes #141 fixes #172 closes #315 closes #242
BREAKING: imagesMaxWidth prop is discontinued in favor of contentWidth and computeImagesMaxWidth. See RFC001 for an exhaustive description. This patch offers a rewrite of the HTMLImage component to get a close match with RFC001, “a deterministic approach to images scaling”. The only part of this RFC which is unsupported is the unitConverter behavior, which is planned for a later major release. In addition to the capabilities defined in the RFC, this patch provides the following features and behaviors: - new property enableExperimentalPercentWidth. It allows percent width for <img> tags, computed relatively to contentWidth. - take margins into account when scaling down images; - support for overriding image styles, including resizeMode; - support for minWidth, minHeight, maxWidth, maxHeight styles. This patch also fixes #141, #172 and provides the features offered in PR #242 and #315. OPTIMIZATIONS: The imageBoxDimensions are computed when required. In addition, requirements are also recomputed when necessary, preventing expensive operations from happening too often. Also, because we need to flatten the style prop to infer requirements, this flatten value is now cached and re-evaluated when appropriate. Finally, styles have been moved to a stylesheet when that is possible, to avoid commiting updates to the native side. Note that these performance optimizations are made possible by the high coverage rate of the HTMLImage component. fixes #141 fixes #172 closes #315 closes #242
BREAKING: imagesMaxWidth prop is discontinued in favor of contentWidth and computeImagesMaxWidth. See RFC001 for an exhaustive description. This patch offers a rewrite of the HTMLImage component to get a close match with RFC001, “a deterministic approach to images scaling”. The only part of this RFC which is unsupported is the unitConverter behavior, which is planned for a later major release. In addition to the capabilities defined in the RFC, this patch provides the following features and behaviors: - new property enableExperimentalPercentWidth. It allows percent width for <img> tags, computed relatively to contentWidth. - take margins into account when scaling down images; - support for overriding image styles, including resizeMode; - support for minWidth, minHeight, maxWidth, maxHeight styles. This patch also fixes #141, #172 and provides the features offered in PR #242 and #315. OPTIMIZATIONS: The imageBoxDimensions are computed when required. In addition, requirements are also recomputed when necessary, preventing expensive operations from happening too often. Also, because we need to flatten the style prop to infer requirements, this flatten value is now cached and re-evaluated when appropriate. Finally, styles have been moved to a stylesheet when that is possible, to avoid commiting updates to the native side. Note that these performance optimizations are made possible by the high coverage rate of the HTMLImage component. fixes #141 fixes #172 updates #412 (could fix) closes #315 closes #242
BREAKING: imagesMaxWidth prop is discontinued in favor of contentWidth and computeImagesMaxWidth. See RFC001 for an exhaustive description. This patch offers a rewrite of the HTMLImage component to get a close match with RFC001, “a deterministic approach to images scaling”. The only part of this RFC which is unsupported is the unitConverter behavior, which is planned for a later major release. In addition to the capabilities defined in the RFC, this patch provides the following features and behaviors: - new property enableExperimentalPercentWidth. It allows percent width for <img> tags, computed relatively to contentWidth. - take margins into account when scaling down images; - support for overriding image styles, including resizeMode; - support for minWidth, minHeight, maxWidth, maxHeight styles. This patch also fixes #141, #172 and provides the features offered in PR #242 and #315. OPTIMIZATIONS: The imageBoxDimensions are computed when required. In addition, requirements are also recomputed when necessary, preventing expensive operations from happening too often. Also, because we need to flatten the style prop to infer requirements, this flatten value is now cached and re-evaluated when appropriate. Finally, styles have been moved to a stylesheet when that is possible, to avoid commiting updates to the native side. Note that these performance optimizations are made possible by the high coverage rate of the HTMLImage component. fixes #141 fixes #172 updates #412 (could fix) closes #315 closes #242
Is this a bug report or a feature request?
bug report
Have you read the guidelines regarding bug report?
yes
Have you read the documentation in its entirety?
yes
Have you made sure that your issue hasn't already been reported/solved?
yes
Is the bug specific to iOS or Android? Or can it be reproduced on both platforms?
Unknown - only able to test on IOS (11.3)
Is the bug reproductible in a production environment (not a debug one)?
Yes
Have you been able to reproduce the bug in the provided example?
I have not tried the demo
Environment
IOS (11.3)
Steps to Reproduce
(Write your steps here:)
Expected Behavior
Actual Behavior
Image getting blur when i have nested images
Reproducible Demo
i dont have a demo but i have a code
The text was updated successfully, but these errors were encountered: