Repository navigation
[iOS] Map: Update pin icon when Pin.ImageSource changes at runtime #36293
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
Changes from 2 commits
2153617
197086e
b2cb88b
981e5df
6ce52cf
429ffab
09934f1
fa0c761
8a9d158
a0b4df3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -248,21 +248,36 @@ void ZoomToShowClusterPins(IMKAnnotation[] annotations) | |
| SetVisibleMapRect(paddedRect, true); | ||
| } | ||
|
|
||
| // Refreshes a pin already on the map after its ImageSource changed at runtime, updating the | ||
| // live annotation view in place. Pins with no individual view (off-screen or collapsed into a | ||
| // cluster) are skipped; GetViewForAnnotation applies the current ImageSource when they appear. | ||
| internal void UpdatePinImage(IMapPin pin) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
[moderate] Regression Prevention —
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in 09934f1: a device test in |
||
| { | ||
| if (pin.MarkerId is not IMKAnnotation annotation || ViewForAnnotation(annotation) is not MKAnnotationView view) | ||
| return; | ||
|
|
||
| view.Image = null; | ||
| if (pin.ImageSource is not null) | ||
|
kevin68 marked this conversation as resolved.
Resolved
|
||
| ApplyCustomImageAsync(view, pin).FireAndForget(); | ||
| } | ||
|
|
||
| async System.Threading.Tasks.Task ApplyCustomImageAsync(MKAnnotationView annotationView, IMapPin pin) | ||
| { | ||
| _handlerRef.TryGetTarget(out IMapHandler? handler); | ||
| if (handler?.MauiContext == null || pin.ImageSource == null) | ||
| return; | ||
|
|
||
| // Capture the annotation before the async operation to detect reuse | ||
| // Capture the annotation and requested source before the async operation, to detect both | ||
| // view reuse and a newer ImageSource change that started while this load was in flight. | ||
| var targetAnnotation = annotationView.Annotation; | ||
| var requestedSource = pin.ImageSource; | ||
|
|
||
| try | ||
| { | ||
| var result = await pin.ImageSource.GetPlatformImageAsync(handler.MauiContext); | ||
| var result = await requestedSource.GetPlatformImageAsync(handler.MauiContext); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
[major] Memory Leak Prevention — The
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 981e5df. |
||
|
|
||
| // Verify the annotation view hasn't been reused for a different pin | ||
| if (annotationView.Annotation != targetAnnotation) | ||
| // Drop this load if the view was reused or the pin's ImageSource changed since. | ||
| if (annotationView.Annotation != targetAnnotation || !ReferenceEquals(pin.ImageSource, requestedSource)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
[moderate] iOS/MacCatalyst Platform Specifics — guard the annotation view handle before reading it after the async load
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 429ffab. The post-await staleness check now tests |
||
| return; | ||
|
|
||
| if (result?.Value is UIImage image) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 [minor] Sample Accuracy — The comment still says Location/Label update live "unlike ImageSource", but this gallery now exists to verify ImageSource also refreshes live at runtime. Updating the wording avoids sending future testers toward the old expected behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 6ce52cf. Reworded to note Location/Label update live via their mappers and to use this button alongside Toggle Icon to confirm ImageSource now refreshes live too.