Skip to content

Commit efe9639

Browse files
OdNairyclaude
authored andcommitted
[maps-ios] Document view annotation shadow padding workaround (#9767)
## Summary - Add documentation to `ViewAnnotation` (UIKit) and `MapViewAnnotation` (SwiftUI) explaining that shadows and other visual effects extending beyond view bounds may cause premature annotation hiding ## Context View annotations calculate visibility using the view's frame, which doesn't account for layer effects like shadows. When a view with a shadow moves off-screen, the annotation hides while the shadow is still visible, causing a jarring visual "pop". The SDK team decided not to address this on the SDK side, so this documentation helps customers implement the workaround themselves. cc @mapbox/maps-ios Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> GitOrigin-RevId: 07bcd5bb3784c7c8ffaa77c55d79a9631886f05b
1 parent 961bb41 commit efe9639

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

Sources/MapboxMaps/Annotations/ViewAnnotation.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ import MapboxCommon
3131
///
3232
/// - Important: Don't set `UIView.isHidden` property to hide the annotation. Instead, use ``visible`` property.
3333
///
34+
/// - Important: When using shadows, blur, or other visual effects that extend beyond the view's bounds
35+
/// (such as `CALayer.shadow*` properties), the annotation may disappear while the effect is still visible.
36+
/// This occurs because visibility is calculated using the view's frame, which doesn't include the shadow extent.
37+
/// To prevent this, wrap your content in a container view with padding that accounts for the effect.
38+
/// For shadows, use padding of approximately `shadowRadius * 2 + max(abs(shadowOffset.width), abs(shadowOffset.height))`.
39+
/// See `FrameViewAnnotationsExample` in the Examples app for a reference implementation.
40+
///
3441
/// When view content or layout is updated, use ``setNeedsUpdateSize()`` to update the the annotation size. It's safe to use it multiple times, only one update will be performed.
3542
///
3643
/// ```swift

Sources/MapboxMaps/SwiftUI/Annotations/MapViewAnnotation.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import SwiftUI
1919
/// The view annotations are great for displaying unique interactive features. However, they may be suboptimal for large amounts of data and don't support clustering. For those cases use ``PointAnnotation`` or Runtime Styling API, for example, ``SymbolLayer`` with ``GeoJSONSource``.
2020
///
2121
/// - Note: View Annotations appear above all content of MapView (e.g. layers, annotations, puck). If you need to display annotation between layers or below puck, use ``PointAnnotation``.
22+
///
23+
/// - Important: When using shadows, blur, or other visual effects that extend beyond the view's bounds,
24+
/// the annotation may disappear while the effect is still visible. This occurs because visibility is calculated
25+
/// using the view's frame, which doesn't include the shadow extent. To prevent this, wrap your content in a
26+
/// container view with padding that accounts for the effect. See ``ViewAnnotation`` documentation for details.
2227

2328
public struct MapViewAnnotation {
2429
struct Actions {

0 commit comments

Comments
 (0)