Skip to content

Commit 2e75657

Browse files
evil159github-actions[bot]
authored andcommitted
Add config option for attribution tint button color (#5643)
GitOrigin-RevId: 0963fb5433fc1795b26b082e30c1064de06e8b3c
1 parent cfa9cd8 commit 2e75657

File tree

6 files changed

+63
-1
lines changed

6 files changed

+63
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Map {
1515
}
1616
```
1717
## 11.14.1 - 07 August, 2025
18+
* Add configuration option to configure attribution button tint color.
1819

1920
## 11.14.0 - 30 July, 2025
2021

Sources/MapboxMaps/Ornaments/InfoButtonOrnament.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ internal class InfoButtonOrnament: UIView {
1515
}
1616
}
1717

18+
var onTintColorDidChange: ((_ tintColor: UIColor) -> Void)?
19+
20+
override func tintColorDidChange() {
21+
super.tintColorDidChange()
22+
23+
onTintColorDidChange?(tintColor)
24+
}
25+
1826
internal weak var delegate: InfoButtonOrnamentDelegate?
1927

2028
internal init() {

Sources/MapboxMaps/Ornaments/OrnamentOptions.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,21 @@ public struct AttributionButtonOptions: Equatable, Sendable {
156156
/// Restricted API. Please contact Mapbox to discuss your use case if you intend to use this property.
157157
@_spi(Restricted) public var visibility: OrnamentVisibility = .visible
158158

159+
/// Tint color of the attribution button control.
160+
public var tintColor: UIColor?
161+
159162
/// Initializes an `AttributionButtonOptions`.
160163
/// - Parameters:
161164
/// - position: The position of the attribution button.
162165
/// - margins: The margins of the attribution button.
163166
public init(
164167
position: OrnamentPosition = .bottomTrailing,
165-
margins: CGPoint = .init(x: 8.0, y: 8.0)
168+
margins: CGPoint = .init(x: 8.0, y: 8.0),
169+
tintColor: UIColor? = nil
166170
) {
167171
self.position = position
168172
self.margins = margins
173+
self.tintColor = tintColor
169174
}
170175
}
171176

Sources/MapboxMaps/Ornaments/OrnamentsManager.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ public final class OrnamentsManager {
159159
self._attributionButton = attributionButton
160160

161161
_attributionButton.delegate = infoButtonOrnamentDelegate
162+
_attributionButton.onTintColorDidChange = { [weak self] tintColor in
163+
self?.options.attributionButton.tintColor = tintColor
164+
}
162165

163166
updateOrnaments()
164167

@@ -227,6 +230,7 @@ public final class OrnamentsManager {
227230
_compassView.isHidden = options.compass.visibility == .hidden
228231
_attributionButton.isHidden = options.attributionButton.visibility == .hidden
229232
_scaleBarView.useMetricUnits = options.scaleBar.useMetricUnits
233+
_attributionButton.tintColor = options.attributionButton.tintColor
230234
}
231235

232236
private func constraints(with view: UIView, position: OrnamentPosition, margins: CGPoint) -> [NSLayoutConstraint] {

Tests/MapboxMapsTests/Ornaments/OrnamentManagerTests.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,45 @@ final class OrnamentManagerTests: XCTestCase {
148148
func testAttributionButton() {
149149
XCTAssertIdentical(ornamentsManager.attributionButton, attributionButton)
150150
}
151+
152+
func testTintColor() {
153+
options.attributionButton.tintColor = .red
154+
ornamentsManager.options = options
155+
XCTAssertEqual(ornamentsManager.attributionButton.tintColor, .red)
156+
XCTAssertEqual(ornamentsManager.options.attributionButton.tintColor, .red)
157+
}
158+
159+
func testTintColorOverride() {
160+
ornamentsManager.attributionButton.tintColor = .gray
161+
162+
options.attributionButton.tintColor = .red
163+
ornamentsManager.options = options
164+
XCTAssertEqual(ornamentsManager.attributionButton.tintColor, .red)
165+
XCTAssertEqual(ornamentsManager.options.attributionButton.tintColor, .red)
166+
}
167+
168+
func testTintColorSync() {
169+
ornamentsManager.attributionButton.tintColor = .gray
170+
XCTAssertEqual(ornamentsManager.attributionButton.tintColor, .gray)
171+
XCTAssertEqual(ornamentsManager.options.attributionButton.tintColor, .gray)
172+
173+
options.attributionButton.tintColor = .red
174+
ornamentsManager.options = options
175+
XCTAssertEqual(ornamentsManager.attributionButton.tintColor, .red)
176+
XCTAssertEqual(ornamentsManager.options.attributionButton.tintColor, .red)
177+
}
178+
179+
func testTintColorClear() {
180+
let originalTintColor = ornamentsManager.attributionButton.tintColor
181+
182+
options.attributionButton.tintColor = .red
183+
ornamentsManager.options = options
184+
XCTAssertEqual(ornamentsManager.attributionButton.tintColor, .red)
185+
XCTAssertEqual(ornamentsManager.options.attributionButton.tintColor, .red)
186+
187+
options.attributionButton.tintColor = nil
188+
ornamentsManager.options = options
189+
XCTAssertEqual(ornamentsManager.attributionButton.tintColor, originalTintColor)
190+
XCTAssertEqual(ornamentsManager.options.attributionButton.tintColor, originalTintColor)
191+
}
151192
}

scripts/api-compatibility-check/breakage_allowlist.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,3 +2170,6 @@ Accessor PolylineAnnotationManager.lineZOffset.Modify() is now with @_spi
21702170
Accessor PolylineAnnotationManager.longPressRadius.Modify() is now with @_spi
21712171
Accessor PolylineAnnotationManager.tapRadius.Modify() is now with @_spi
21722172
Accessor ViewAnnotationManager.viewAnnotationAvoidLayers.Modify() is now with @_spi
2173+
2174+
# Add configuration option to configure attribution button tint color.
2175+
Constructor AttributionButtonOptions.init(position:margins:) has been removed

0 commit comments

Comments
 (0)