Skip to content

Commit f41f2dc

Browse files
OdNairygithub-actions[bot]
authored andcommitted
Fix FrameViewAnnotationsExample: account for shadow in bounding box (#9555)
## Summary - Wrap annotation view in a container with padding to account for shadow extent - This ensures the annotation's bounding box includes the shadow area, preventing premature hiding during map panning ## Problem View annotations with shadows were disappearing before the shadow visually left the screen. This happened because `ViewAnnotation` uses `systemLayoutSizeFitting()` to determine the bounding box, which doesn't account for `CALayer` shadow properties. ## Solution Wrap the card view in a transparent container with padding calculated from shadow parameters: ```swift let shadowPadding = shadowRadius * 2 + max(abs(shadowOffset.width), abs(shadowOffset.height)) ``` This makes the bounding box large enough to include the full shadow extent. Related: - mapbox/mapbox-sdk#9460 | Before | After | |--------|--------| | <video src="https://github.com/user-attachments/assets/304b4b61-74b5-460f-a5b0-8638b30d6413" /> | <video src="https://github.com/user-attachments/assets/f50e812b-6b6a-4d87-b4c8-58e4cee27d90" /> | cc @mapbox/sdk-platform cc @mapbox/maps-ios GitOrigin-RevId: 0ef27e5c14073b9f433cded608831c14ecccb1fb
1 parent 50f70e2 commit f41f2dc

2 files changed

Lines changed: 34 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Mapbox welcomes participation and contributions from everyone.
66

77
### Features ✨ and improvements 🏁
88
* Introduce experimental `queryRenderedRasterValues` API for querying the rendered raster array value at a point on the map.
9+
10+
### Bug fixes 🐞
11+
* Fix `FrameViewAnnotationsExample` annotations disappearing before shadow leaves the screen.
912
## 11.18.0 - 15 January, 2026
1013

1114
### Bug fixes 🐞

Sources/Examples/All Examples/Annotations/FrameViewAnnotationsExample.swift

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,24 +134,43 @@ final class FrameViewAnnotationsExample: UIViewController, ExampleProtocol {
134134

135135
private func addAnnotations() {
136136
func makeView(text: String) -> UIView {
137-
let view = UIView()
138-
view.backgroundColor = .white
139-
view.layer.shadowOpacity = 0.25
140-
view.layer.shadowRadius = 8
141-
view.layer.shadowOffset = CGSize(width: 0, height: 2)
142-
view.layer.cornerRadius = 8
137+
let shadowRadius: CGFloat = 8
138+
let shadowOffset = CGSize(width: 0, height: 2)
139+
// Shadow blur extends beyond shadowRadius. Use ~2x multiplier for smooth fade.
140+
let shadowPadding = shadowRadius * 2 + max(abs(shadowOffset.width), abs(shadowOffset.height))
141+
let labelPadding: CGFloat = 4
142+
143+
let container = UIView()
144+
145+
let card = UIView()
146+
card.backgroundColor = .white
147+
card.layer.shadowOpacity = 0.25
148+
card.layer.shadowRadius = shadowRadius
149+
card.layer.shadowOffset = shadowOffset
150+
card.layer.cornerRadius = 8
151+
card.translatesAutoresizingMaskIntoConstraints = false
152+
143153
let label = UILabel()
144154
label.text = text
145155
label.textColor = .black
146156
label.translatesAutoresizingMaskIntoConstraints = false
147-
view.addSubview(label)
157+
158+
card.addSubview(label)
159+
container.addSubview(card)
160+
148161
NSLayoutConstraint.activate([
149-
label.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 4),
150-
label.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -4),
151-
label.topAnchor.constraint(equalTo: view.topAnchor, constant: 4),
152-
label.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -4),
162+
label.leadingAnchor.constraint(equalTo: card.leadingAnchor, constant: labelPadding),
163+
label.trailingAnchor.constraint(equalTo: card.trailingAnchor, constant: -labelPadding),
164+
label.topAnchor.constraint(equalTo: card.topAnchor, constant: labelPadding),
165+
label.bottomAnchor.constraint(equalTo: card.bottomAnchor, constant: -labelPadding),
166+
167+
card.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: shadowPadding),
168+
card.trailingAnchor.constraint(equalTo: container.trailingAnchor, constant: -shadowPadding),
169+
card.topAnchor.constraint(equalTo: container.topAnchor, constant: shadowPadding),
170+
card.bottomAnchor.constraint(equalTo: container.bottomAnchor, constant: -shadowPadding),
153171
])
154-
return view
172+
173+
return container
155174
}
156175

157176
self.annotations = annotationData.map {

0 commit comments

Comments
 (0)