Skip to content

Commit

Permalink
Merge branch 'main' into refactor-rx
Browse files Browse the repository at this point in the history
  • Loading branch information
nighthawk authored Nov 1, 2023
2 parents 8ec375f + 75c48f0 commit 16c180c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Sources/TripKitUI/cards/TKUIMapManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ open class TKUIMapManager: TGMapManager {
/// Cache of renderers, used to update styling when selection changes
private var renderers: [WeakRenderers] = []

/// Whether user interaction for selecting annotation is enabled, defaults to `true`.
open var annotationSelectionEnabled: Bool = true {
didSet {
if !annotationSelectionEnabled {
selectionIdentifier = nil
}
}
}

/// The identifier for what should be drawn as selected on the map
public var selectionIdentifier: String? {
didSet {
Expand Down Expand Up @@ -372,6 +381,7 @@ extension TKUIMapManager {

private func updateSelectionForTapping(_ view: MKAnnotationView) {
guard
annotationSelectionEnabled,
let selectable = view.annotation as? TKUISelectableOnMap,
let identifier = selectable.selectionIdentifier
else { return }
Expand Down
2 changes: 2 additions & 0 deletions Sources/TripKitUI/cards/TKUITripModeByModeCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ public class TKUITripModeByModeCard: TGPageCard {

public override func didAppear(animated: Bool) {
super.didAppear(animated: animated)

tripMapManager.annotationSelectionEnabled = true

TKUIEventCallback.handler(.cardAppeared(self))
if let controller = self.controller {
Expand Down
5 changes: 5 additions & 0 deletions Sources/TripKitUI/cards/TKUITripOverviewCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ public class TKUITripOverviewCard: TKUITableCard {
tripMapManager?.deselectSegment(animated: animated)
}

// Annotation selection on the trip map manager is used by the mode-by-mode
// card, but not the overview card; as it doesn't do anything useful, and
// you can't undo it.
tripMapManager?.annotationSelectionEnabled = false

TKUIEventCallback.handler(.cardAppeared(self))
}

Expand Down
5 changes: 4 additions & 1 deletion Sources/TripKitUI/helper/TKUIMapManagerHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class TKUIMapManagerHelper: NSObject {
points.append(TKUICircleAnnotation(
coordinate: visit.coordinate,
title: visit.title,
subtitle: visit.subtitle,
circleColor: service.color ?? .tkAppTintColor,
isTravelled: segment.uses(visit),
asLarge: true,
Expand Down Expand Up @@ -187,9 +188,10 @@ class TKUIMapManagerHelper: NSObject {
}

fileprivate class TKUICircleAnnotation: NSObject, TKUICircleDisplayable, TKUISelectableOnMap {
internal init(coordinate: CLLocationCoordinate2D, title: String? = nil, circleColor: UIColor, isTravelled: Bool, asLarge: Bool, selectionIdentifier: String?, selectionCondition: TKUISelectionCondition) {
internal init(coordinate: CLLocationCoordinate2D, title: String? = nil, subtitle: String? = nil, circleColor: UIColor, isTravelled: Bool, asLarge: Bool, selectionIdentifier: String?, selectionCondition: TKUISelectionCondition) {
self.coordinate = coordinate
self.title = title
self.subtitle = subtitle
self.circleColor = circleColor
self.isTravelled = isTravelled
self.asLarge = asLarge
Expand All @@ -204,6 +206,7 @@ fileprivate class TKUICircleAnnotation: NSObject, TKUICircleDisplayable, TKUISel

var coordinate: CLLocationCoordinate2D
var title: String?
var subtitle: String?

// MARK: TKUICircleDisplayable

Expand Down

0 comments on commit 16c180c

Please sign in to comment.