Skip to content

feat(ios): support custom scale property in ImageParser#8329

Open
IsaacIsrael wants to merge 1 commit into
wix:masterfrom
IsaacIsrael:feat/image-parser-scale-support
Open

feat(ios): support custom scale property in ImageParser#8329
IsaacIsrael wants to merge 1 commit into
wix:masterfrom
IsaacIsrael:feat/image-parser-scale-support

Conversation

@IsaacIsrael

Copy link
Copy Markdown
Contributor

Summary

When an image source dictionary includes a scale key, ImageParser now re-creates the UIImage at 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/@3x filename 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 to scale = 1.0 for 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/@3x suffix 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 scale key. If present (and > 0), re-create the UIImage with the specified scale using [UIImage imageWithCGImage:scale:orientation:]. This is safe, backwards-compatible, and only activates when the caller explicitly opts in.

Usage

Navigation.mergeOptions(componentId, {
  bottomTabs: {
    children: [{
      options: {
        bottomTab: {
          icon: { uri: 'file:///path/to/avatar.png', scale: 3 }
        }
      }
    }]
  }
});

Test plan

  • Verified with dynamically downloaded tab-bar avatar icons at scale: 2 and scale: 3
  • Confirmed existing image sources (without scale key) are unaffected
  • Confirmed system images ({ system: 'star' }) bypass the scale logic

Made with Cursor

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant