capacitor-google-navigation 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,19 +2,9 @@ import UIKit
|
|
|
2
2
|
import GoogleMaps
|
|
3
3
|
import GoogleNavigation
|
|
4
4
|
|
|
5
|
-
/// A transparent view that passes touches through to underlying windows,
|
|
6
|
-
/// only intercepting touches that land on one of its subviews (e.g. the close button).
|
|
7
|
-
private class PassthroughView: UIView {
|
|
8
|
-
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
|
9
|
-
let hit = super.hitTest(point, with: event)
|
|
10
|
-
return hit == self ? nil : hit
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
5
|
class NavigationMapViewController: UIViewController {
|
|
15
6
|
private let session: GMSNavigationSession
|
|
16
7
|
private var mapView: GMSMapView?
|
|
17
|
-
private var overlayWindow: UIWindow?
|
|
18
8
|
var onDismiss: (() -> Void)?
|
|
19
9
|
|
|
20
10
|
init(session: GMSNavigationSession) {
|
|
@@ -46,34 +36,12 @@ class NavigationMapViewController: UIViewController {
|
|
|
46
36
|
if enabled {
|
|
47
37
|
mapView.cameraMode = .following
|
|
48
38
|
}
|
|
39
|
+
addCloseButton()
|
|
49
40
|
}
|
|
50
41
|
|
|
51
|
-
|
|
52
|
-
super.viewDidAppear(animated)
|
|
53
|
-
addCloseButtonWindow()
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
override func viewDidDisappear(_ animated: Bool) {
|
|
57
|
-
super.viewDidDisappear(animated)
|
|
58
|
-
tearDownCloseButtonWindow()
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// MARK: - Close button in a top-level UIWindow above all SDK UI
|
|
62
|
-
|
|
63
|
-
private func addCloseButtonWindow() {
|
|
64
|
-
guard let scene = view.window?.windowScene else { return }
|
|
65
|
-
|
|
66
|
-
let window = UIWindow(windowScene: scene)
|
|
67
|
-
window.windowLevel = .alert + 1
|
|
68
|
-
window.backgroundColor = .clear
|
|
69
|
-
window.isHidden = false
|
|
70
|
-
|
|
71
|
-
let overlayVC = UIViewController()
|
|
72
|
-
let passthroughView = PassthroughView()
|
|
73
|
-
passthroughView.backgroundColor = .clear
|
|
74
|
-
overlayVC.view = passthroughView
|
|
75
|
-
window.rootViewController = overlayVC
|
|
42
|
+
// MARK: - Close button overlaid directly on the map view
|
|
76
43
|
|
|
44
|
+
private func addCloseButton() {
|
|
77
45
|
let button = UIButton(type: .system)
|
|
78
46
|
button.setImage(UIImage(systemName: "xmark"), for: .normal)
|
|
79
47
|
button.tintColor = .white
|
|
@@ -81,25 +49,17 @@ class NavigationMapViewController: UIViewController {
|
|
|
81
49
|
button.layer.cornerRadius = 20
|
|
82
50
|
button.translatesAutoresizingMaskIntoConstraints = false
|
|
83
51
|
button.addTarget(self, action: #selector(closeTapped), for: .touchUpInside)
|
|
84
|
-
|
|
52
|
+
view.addSubview(button)
|
|
85
53
|
|
|
86
54
|
NSLayoutConstraint.activate([
|
|
87
|
-
button.topAnchor.constraint(equalTo:
|
|
88
|
-
button.leadingAnchor.constraint(equalTo:
|
|
55
|
+
button.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 16),
|
|
56
|
+
button.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16),
|
|
89
57
|
button.widthAnchor.constraint(equalToConstant: 40),
|
|
90
58
|
button.heightAnchor.constraint(equalToConstant: 40),
|
|
91
59
|
])
|
|
92
|
-
|
|
93
|
-
self.overlayWindow = window
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private func tearDownCloseButtonWindow() {
|
|
97
|
-
overlayWindow?.isHidden = true
|
|
98
|
-
overlayWindow = nil
|
|
99
60
|
}
|
|
100
61
|
|
|
101
62
|
@objc private func closeTapped() {
|
|
102
|
-
tearDownCloseButtonWindow()
|
|
103
63
|
dismiss(animated: true) { [weak self] in
|
|
104
64
|
self?.onDismiss?()
|
|
105
65
|
}
|