Skip to content

Commit

Permalink
activate closest issue when tapping near it
Browse files Browse the repository at this point in the history
fat finger helper
  • Loading branch information
juliand665 committed Feb 2, 2024
1 parent 9d7537a commit b4bbc14
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Issue Manager/Issue Manager/Map/MapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,27 @@ final class MapViewController: UIViewController, InstantiableViewController {
$0.overlayView.backgroundColor = .darkOverlay
$0.additionalSafeAreaInsets.bottom += self.pullableView.minHeight
+ 8 // for symmetry
$0.overlayView.addGestureRecognizer(UITapGestureRecognizer(
target: self, action: #selector(mapTapped(_:))
))
}
self.updateMarkers()
}
}

@objc func mapTapped(_ recognizer: UITapGestureRecognizer) {
guard recognizer.state == .ended else { return }

let markersView = pdfController!.overlayView!
let tap = recognizer.location(in: markersView)
let distances = markers.lazy.map { ($0.center - tap).length }
let closest = zip(markers, distances).min { $0.1 < $1.1 }?.0
guard let closest else { return }
let screenSpaceDistance = (markersView.convert(closest.center, to: view) - recognizer.location(in: view)).length
guard screenSpaceDistance < 40 else { return } // too far to be intentional
showDetails(for: closest.issue)
}

private func updateMarkers() {
guard let pdfController = pdfController else { return }

Expand Down

0 comments on commit b4bbc14

Please sign in to comment.