Skip to content
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

Fix image flickering caused by resetting BackgroundSize #2729

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/react-native-web/src/exports/Image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ const Image: React.AbstractComponent<
const displayImageUri = resolveAssetUri(selectedSource);
const imageSizeStyle = resolveAssetDimensions(selectedSource);
const backgroundImage = displayImageUri ? `url("${displayImageUri}")` : null;
const backgroundSize = getBackgroundSize();
const cachedBackgroundSize = React.useRef(null);
const backgroundSize = getBackgroundSize() || cachedBackgroundSize.current;

// Accessibility image allows users to trigger the browser's image context menu
const hiddenImage = displayImageUri
Expand Down Expand Up @@ -260,7 +261,8 @@ const Image: React.AbstractComponent<
);
const x = Math.ceil(scaleFactor * naturalWidth);
const y = Math.ceil(scaleFactor * naturalHeight);
return `${x}px ${y}px`;
cachedBackgroundSize.current = `${x}px ${y}px`;
return cachedBackgroundSize.current;
}
}
}
Expand Down