feat(ios): support custom scale property in ImageParser#8329
Open
IsaacIsrael wants to merge 1 commit into
Open
feat(ios): support custom scale property in ImageParser#8329IsaacIsrael wants to merge 1 commit into
IsaacIsrael wants to merge 1 commit into
Conversation
When an image source dictionary includes a `scale` key, re-create the
UIImage at the requested scale. This lets callers pass `{ uri, scale }`
to control how tab-bar and toolbar icons are rendered on high-DPI
displays without relying on @2x/@3x filename suffixes, which are not
available for dynamically downloaded images.
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When an image source dictionary includes a
scalekey,ImageParsernow re-creates theUIImageat the requested scale factor. This enables callers to pass{ uri, scale }to precisely control how tab-bar and toolbar icons render on high-DPI displays — without relying on@2x/@3xfilename suffixes, which are unavailable for dynamically downloaded images (e.g. avatars fetched from a CDN at runtime).Problem
React Native Navigation uses
[RCTConvert UIImage:]to parse image sources, which defaults toscale = 1.0for URI-based images. On Retina displays, this causes dynamically downloaded images to render at their full pixel size instead of the intended logical size. The standard@2x/@3xsuffix convention doesn't apply to images downloaded to the cache directory at runtime.Solution
After the existing image parsing logic, check whether the source dictionary contains a
scalekey. If present (and > 0), re-create theUIImagewith the specified scale using[UIImage imageWithCGImage:scale:orientation:]. This is safe, backwards-compatible, and only activates when the caller explicitly opts in.Usage
Test plan
scale: 2andscale: 3scalekey) are unaffected{ system: 'star' }) bypass the scale logicMade with Cursor