Repository navigation
fix(ios): render snapshots at the screen's scale - #4459
Closed
mickeypause wants to merge 2 commits into
Closed
mickeypause wants to merge 2 commits into
mickeypause wants to merge 2 commits into
Conversation
mickeypause
force-pushed
the
feat/snapshot-pixel-ratio-attribution
branch
from
November 27, 2026 08:40
5c478e4 to
233cce5
Compare
8 tasks done
mickeypause
marked this pull request as draft
November 27, 2026 08:43
RNMBXSnapshotModule hard-coded pixelRatio: 1.0, so every iOS snapshot was 1x and looked blurry when shown at its point size on a 2x or 3x screen. Use UIScreen.main.scale, as the offline module already does. Android already renders at the screen density.
mickeypause
force-pushed
the
feat/snapshot-pixel-ratio-attribution
branch
from
November 27, 2026 09:32
233cce5 to
5251ee8
Compare
mickeypause
added a commit
to mickeypause/maps
that referenced
this pull request
Nov 27, 2026
mickeypause
added a commit
to mickeypause/maps
that referenced
this pull request
Nov 27, 2026
mickeypause
force-pushed
the
feat/snapshot-pixel-ratio-attribution
branch
2 times, most recently
from
November 27, 2026 10:10
fe80bd8 to
28b3115
Compare
MapSnapshotOptions has a precondition that each side is at most 8192 px, so rendering at the screen's scale would crash a 3x device for snapshots wider or taller than about 2730 pt. Lower the scale for those, but never below 1x: snapshots with a side over 8192 pt still crash, as on main.
mickeypause
force-pushed
the
feat/snapshot-pixel-ratio-attribution
branch
from
November 27, 2026 10:16
28b3115 to
67f1741
Compare
Author
|
Superseded by #4462: same change and description, from a branch whose name matches the title. |
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.
Description
Fixes blurry
snapshotManager.takeSnapimages on iOS.RNMBXSnapshotModule.swifthard-codespixelRatio: 1.0, so every iOS snapshot is 1×. A 300 × 150 pt snapshot is only 300 × 150 px, and it looks blurry on a 2× or 3× screen. This usesUIScreen.main.scale, asRNMBXOfflineModuleLegacyalready does. Android already renders at the screen density, so the two platforms now match. Android rounds the density down; iPhone scales are whole numbers anyway.Crash: Mapbox's 8192 px limit
MapSnapshotOptions.init(Mapbox Maps SDK,MapSnapshotOptions.swift) hasprecondition(size.width * pixelRatio <= 8192)and the same for height. A failedpreconditionstops the app, in release builds too, so it can't be caught and turned into a rejected promise. Rendering at 3× would make snapshots that work today crash, so the scale is capped at8192 / max(width, height), but never below 1× (the current behaviour):mainSo the screen scale is used whenever it fits, and anything that works on
mainstill works. Known limitation, not changed by this PR: a snapshot with a side over 8192 pt still crashes, as it does onmaintoday, because even 1× is over the limit. Fixing that means either rendering below 1× or rejecting the call, which is a separate behaviour decision.Crash seen without the cap (
TakeSnapshotscene temporarily set to 3000 pt wide, iPhone 16 Pro simulator):With the cap the same scene renders and no crash report is written.
On a 3× device the snapshot's pixel size grows from 300 × 150 to 900 × 450, so files and base64 strings get bigger. The size in points doesn't change.
Screenshots
The first snapshot in the
TakeSnapshotexample scene, unchanged. Before:main. After: this branch (at this size the scale is 3×; the 8192 px cap doesn't apply). iPhone 16 Pro simulator (3×), iOS 27, New Architecture.main: 1×)Checklist
CONTRIBUTING.mdyarn generatein the root folder (no changes)/exampleapp./example) (n/a: bug fix, no new feature)Testing
/exampleapp: I ran theTakeSnapshotscene on an iPhone 16 Pro simulator (iOS 27, New Architecture), with and without this change. The screenshots above come from those runs.TakeSnapshotscene temporarily set to 3000 pt wide, the build without the cap crashed (EXC_BREAKPOINTinMapSnapshotOptions.init, called from_getSnapshotterOptions). With the cap, the snapshots render. That scene edit isn't part of this PR.Component to reproduce the issue you're fixing
On
main, on a 2× or 3× iPhone, the snapshot is blurry. With this branch it's sharp.Reproducer