Repository navigation
fix(ios): remove <Images> images from the style on unmount and drop stale map entries - #4424
Merged
Merged
Conversation
…tale map entries Removing an <Image> child or unmounting <Images> now removes its images from the style, as Android does for <Images>. Another <Images> that still provides a removed name re-adds it via addMissingImageToStyle, which now also covers <Image> children. removeFromMap also drops the component from RNMBXMapView.images; addToMap appended it on every style load, so stale entries piled up and kept unmounted views alive.
This branch was previously deployed
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
Found while reviewing #4423. Two iOS
<Images>bugs:<Image>child, or unmounting<Images>, never removed its images from the style, so symbol layers kept drawing them. Removal now deletes the names from the style, matching what Android does when<Images>unmounts (Android doesn't remove images for a single<Image>child either; iOS now does). Images are only removed on view removal, not on style changes.addToMapappended the component toRNMBXMapView.imageson every style load, andremoveFromMapnever took it out. The list grew by one per<Images>per style switch and on every remount, and it kept unmounted components alive.removeFromMapnow removes it.Shared names: if two
<Images>provide the same name and one is removed, the image is removed from the style. The resultingstyleImageMissingevent then makes the remaining provider re-add it. For that to work with<Image>children,addMissingImageToStylenow also looks atimageViews. I went with this instead of ref-counting because it reuses the existing missing-image path and needs no shared bookkeeping.Known limitation: the Mapbox renderer keeps drawing an icon that symbols had already laid out with a removed image, even though
style.imageExistsreturns false and the tile re-lays out (the moved points in the reproducer still showed it). It goes away once a referenced image changes or the style reloads; I didn't find an API to force it. This is why the single-child case below still shows the icon visually even though the style state is correct.Verified on an iPhone 17 simulator (iOS 26.5) using the reproducer below plus temporary logging (not part of this PR), on main (44d37d2) vs. this branch:
map.imagescount over mount → unmount/remount A → 4 style switches: main 2 → 3 → 11 and noRNMBXImagesdeinit; fixed 2 → 1 → 2 → stays 2, and deinit runs on unmount.imageExists1s after removing<Image child-red>: maintrue, fixedfalse.<Images>A + reload shape: main still draws red andprop-pin; fixed shows neither, andsharedstays (re-added by B).<Images>B + reload shape: main still drawsonly-b; fixed removes it, andsharedstays (re-added by A).yarn lintandyarn testpass, and the iOS example builds.Checklist
CONTRIBUTING.mdyarn generatein the root folder/exampleapp./example)Component to reproduce the issue you're fixing
Repro.tsx