Skip to content
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

[ornaments] Refactor visibility options for the logo and attribution button #326

Merged
merged 8 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Mapbox welcomes participation and contributions from everyone.

## main

### Breaking changes ⚠️

- `OrnamentOptions.logo._isVisible` and `OrnamentOptions.attributionButton._isVisible` have been replaced with `OrnamentOptions.logo.visibility` and `OrnamentOptions.attributionButton.visibility`. ([#326](https://github.com/mapbox/mapbox-maps-ios/pull/326))
## 10.0.0-beta.19 - May 6, 2021

### Breaking changes ⚠️
Expand Down
8 changes: 8 additions & 0 deletions Sources/MapboxMaps/Foundation/LogoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ internal class LogoView: UIView {
}
}

public override var isHidden: Bool {
didSet {
if isHidden {
Log.warning(forMessage: "The Mapbox logo wordmark must remain enabled in accordance with our Terms of Service. See https://www.mapbox.com/legal/tos for more details.", category: "Ornaments")
}
}
}

internal override var intrinsicContentSize: CGSize {
return logoSize.rawValue
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/MapboxMaps/MapView/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ open class MapView: BaseMapView {
public internal(set) var gestures: GestureManager!

/// The `ornaments`object will be responsible for all ornaments on the map.
public var ornaments: OrnamentsManager!
public internal(set) var ornaments: OrnamentsManager!

/// The `camera` object manages a camera's view lifecycle..
public internal(set) var camera: CameraAnimationsManager!
Expand Down
8 changes: 8 additions & 0 deletions Sources/MapboxMaps/Ornaments/MapboxInfoButtonOrnament.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ internal class MapboxInfoButtonOrnament: UIView {
}
}

public override var isHidden: Bool {
didSet {
if isHidden {
Log.warning(forMessage: "Attribution must be enabled if you use data from sources that require it. See https://docs.mapbox.com/help/getting-started/attribution/ for more details.", category: "Ornaments")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this language was checked by @sbma44

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
}

internal init() {
super.init(frame: CGRect(origin: .zero, size: CGSize(width: 44, height: 44)))
NSLayoutConstraint.activate([
Expand Down
35 changes: 21 additions & 14 deletions Sources/MapboxMaps/Ornaments/OrnamentOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ private let defaultOrnamentsMargin = CGPoint(x: 8.0, y: 8.0)
public struct OrnamentOptions: Equatable {

// MARK: - Scale Bar
/// The ornament options for the scale bar.
/// The ornament options for the map's scale bar..
public var scaleBar = ScaleBarViewOptions()

// MARK: - Compass

/// The ornament options for the compass view.
/// The ornament options for the map's compass view.
public var compass = CompassViewOptions()

// MARK: - Logo View
Expand All @@ -25,21 +25,24 @@ public struct OrnamentOptions: Equatable {
information. See https://docs.mapbox.com/help/how-mapbox-works/attribution/
for details.
*/
/// The ornament options for the logo view.

/// The ornament options for the map's logo view.
public var logo = LogoViewOptions()

// MARK: - Attribution Button
/// The ornament options for the attribution button.

/// The ornament options for the map's attribution button.
public var attributionButton = AttributionButtonOptions()
}

public protocol BaseOrnamentOptions: Equatable {
public protocol OrnamentOptionsProtocol {
var position: OrnamentPosition { get set }
/// The default value for this property is `CGPoint(x: 8.0, y: 8.0)`.
var margins: CGPoint { get set }
}

/// Used to configure position, margin, and visibility for the map's scale bar.
public struct ScaleBarViewOptions: BaseOrnamentOptions {
/// Used to configure position, margin, and visibility for the map's scale bar view.
public struct ScaleBarViewOptions: OrnamentOptionsProtocol, Equatable {
/// The default value for this property is `.topLeft`.
public var position: OrnamentPosition = .topLeft
/// The default value for this property is `CGPoint(x: 8.0, y: 8.0)`.
Expand All @@ -49,7 +52,7 @@ public struct ScaleBarViewOptions: BaseOrnamentOptions {
}

/// Used to configure position, margin, and visibility for the map's compass view.
public struct CompassViewOptions: BaseOrnamentOptions {
public struct CompassViewOptions: OrnamentOptionsProtocol, Equatable {
/// The default value for this property is `.topRight`.
public var position: OrnamentPosition = .topRight
/// The default value for this property is `CGPoint(x: 8.0, y: 8.0)`.
Expand All @@ -59,21 +62,25 @@ public struct CompassViewOptions: BaseOrnamentOptions {
}

/// Used to configure position, margin, and visibility for the map's attribution button.
public struct AttributionButtonOptions: Equatable {
public struct AttributionButtonOptions: OrnamentOptionsProtocol, Equatable {
/// The default value for this property is `.bottomRight`.
public var position: OrnamentPosition = .bottomRight
/// The default value for this property is `CGPoint(x: 8.0, y: 8.0)`.
public var margins: CGPoint = defaultOrnamentsMargin
/// The default value for this property is `true`.
public var _isVisible: Bool = true
/// The default value for this property is `visible`. Setting this property to `.adaptive`
/// will lead to the same behavior as `.visible`. The attribution button will be visible
/// as long as the map view is visible.
public var _visibility: OrnamentVisibility = .visible
}

/// Used to configure position, margin, and visibility for the map's logo view.
public struct LogoViewOptions: Equatable {
public struct LogoViewOptions: OrnamentOptionsProtocol, Equatable {
/// The default value for this property is `.bottomLeft`.
public var position: OrnamentPosition = .bottomLeft
/// The default value for this property is `CGPoint(x: 8.0, y: 8.0)`.
public var margins: CGPoint = defaultOrnamentsMargin
/// The default value for this property is `true`.
public var _isVisible: Bool = true
/// The default value for this property is `visible`. Setting this property to `.adaptive`
jmkiley marked this conversation as resolved.
Show resolved Hide resolved
/// willl lead to the same behavior as `.visible`. The logo view will be visible as long
/// as the map view is visible.
public var _visibility: OrnamentVisibility = .visible
}
4 changes: 2 additions & 2 deletions Sources/MapboxMaps/Ornaments/OrnamentsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ public class OrnamentsManager: NSObject {
// Activate new constraints
NSLayoutConstraint.activate(constraints)

logoView.isHidden = !options.logo._isVisible
logoView.isHidden = options.logo._visibility == .hidden
scalebarView.isHidden = options.scaleBar.visibility == .hidden
compassView.isHidden = options.compass.visibility == .hidden
attributionButton.isHidden = !options.attributionButton._isVisible
attributionButton.isHidden = options.attributionButton._visibility == .hidden
}

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