capacitor-google-navigation 0.0.2 → 0.0.4

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.
package/README.md CHANGED
@@ -134,8 +134,8 @@ startNavigation({ lat, lng, travelMode })
134
134
  ↓ fires onRouteChanged on recalculation
135
135
  stopNavigation()
136
136
  ↓ ends guidance, clears destination
137
- showNavigationView({ show: false })
138
- ↓ dismisses native map, restores app UI
137
+ showNavigationView({ show: false }) — or user taps the ✕ close button
138
+ ↓ dismisses native map, fires onNavigationClosed, restores app UI
139
139
  ```
140
140
 
141
141
  ---
@@ -154,9 +154,10 @@ interface UseNavigationOptions {
154
154
  apiKey: string;
155
155
  onArrival?: (event: any) => void;
156
156
  onRouteChanged?: () => void;
157
+ onNavigationClosed?: () => void;
157
158
  }
158
159
 
159
- export function useGoogleNavigation({ apiKey, onArrival, onRouteChanged }: UseNavigationOptions) {
160
+ export function useGoogleNavigation({ apiKey, onArrival, onRouteChanged, onNavigationClosed }: UseNavigationOptions) {
160
161
  const listeners = useRef<PluginListenerHandle[]>([]);
161
162
 
162
163
  useEffect(() => {
@@ -176,6 +177,11 @@ export function useGoogleNavigation({ apiKey, onArrival, onRouteChanged }: UseNa
176
177
  listeners.current.push(h);
177
178
  }
178
179
 
180
+ if (onNavigationClosed) {
181
+ const h = await GoogleNavigation.addListener('onNavigationClosed', onNavigationClosed);
182
+ listeners.current.push(h);
183
+ }
184
+
179
185
  await GoogleNavigation.initialize({ apiKey });
180
186
  };
181
187
 
@@ -232,6 +238,7 @@ const NavigationPage: React.FC = () => {
232
238
  apiKey: import.meta.env.VITE_GOOGLE_NAV_API_KEY as string,
233
239
  onArrival: () => setShowArrival(true),
234
240
  onRouteChanged: () => console.log('Route recalculated'),
241
+ onNavigationClosed: () => console.log('User closed navigation'),
235
242
  });
236
243
 
237
244
  return (
@@ -301,6 +308,11 @@ const routeHandle = await GoogleNavigation.addListener('onRouteChanged', () => {
301
308
  console.log('Route recalculated');
302
309
  });
303
310
 
311
+ const closedHandle = await GoogleNavigation.addListener('onNavigationClosed', () => {
312
+ // Fired when the user taps the ✕ close button on the native navigation view
313
+ console.log('Navigation closed by user');
314
+ });
315
+
304
316
  // 2. Initialize the SDK (fires onNavigationReady when done)
305
317
  await GoogleNavigation.initialize({ apiKey: 'YOUR_API_KEY' });
306
318
 
@@ -400,14 +412,14 @@ Show/hide navigation view
400
412
  ### addListener(...)
401
413
 
402
414
  ```typescript
403
- addListener(eventName: 'onArrival' | 'onRouteChanged' | 'onNavigationReady', listenerFunc: (event: any) => void) => Promise<PluginListenerHandle>
415
+ addListener(eventName: 'onArrival' | 'onRouteChanged' | 'onNavigationReady' | 'onNavigationClosed', listenerFunc: (event: any) => void) => Promise<PluginListenerHandle>
404
416
  ```
405
417
 
406
418
  Add listener for navigation events
407
419
 
408
420
  | Param | Type |
409
421
  | ------------------ | ----------------------------------------------------------------- |
410
- | **`eventName`** | <code>'onArrival' \| 'onRouteChanged' \| 'onNavigationReady'</code> |
422
+ | **`eventName`** | <code>'onArrival' \| 'onRouteChanged' \| 'onNavigationReady' \| 'onNavigationClosed'</code> |
411
423
  | **`listenerFunc`** | <code>(event: any) =&gt; void</code> |
412
424
 
413
425
  **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
@@ -446,6 +458,7 @@ Remove all listeners
446
458
  | `onNavigationReady` | `{}` | SDK has initialized and the navigator is available |
447
459
  | `onArrival` | `{ latitude, longitude, title }` | User arrives at the destination waypoint |
448
460
  | `onRouteChanged` | `{}` | The route is recalculated (traffic, missed turn, etc.) |
461
+ | `onNavigationClosed` | `{}` | User tapped the ✕ close button on the native navigation view (iOS) |
449
462
 
450
463
  ---
451
464
 
@@ -43,12 +43,20 @@ import GoogleNavigation
43
43
  return
44
44
  }
45
45
 
46
- session.started = true
46
+ session.isStarted = true
47
47
  self.navigationSession = session
48
- session.navigator?.addListener(self)
48
+ session.navigator?.add(self)
49
49
 
50
50
  let mapVC = NavigationMapViewController(session: session)
51
51
  mapVC.modalPresentationStyle = .fullScreen
52
+ mapVC.onDismiss = { [weak self] in
53
+ guard let self = self else { return }
54
+ self.navigationSession?.navigator?.remove(self)
55
+ self.navigationSession?.isStarted = false
56
+ self.navigationSession = nil
57
+ self.mapViewController = nil
58
+ self.plugin?.notifyListeners("onNavigationClosed", data: [:])
59
+ }
52
60
  self.mapViewController = mapVC
53
61
 
54
62
  presentingVC.present(mapVC, animated: true) {
@@ -62,8 +70,8 @@ import GoogleNavigation
62
70
  func dismissNavigationViewController(completion: @escaping () -> Void) {
63
71
  DispatchQueue.main.async {
64
72
  self.mapViewController?.dismiss(animated: true) {
65
- self.navigationSession?.navigator?.removeListener(self)
66
- self.navigationSession?.started = false
73
+ self.navigationSession?.navigator?.remove(self)
74
+ self.navigationSession?.isStarted = false
67
75
  self.navigationSession = nil
68
76
  self.mapViewController = nil
69
77
  completion()
@@ -113,7 +121,7 @@ import GoogleNavigation
113
121
  }
114
122
 
115
123
  extension GoogleNavigation: GMSNavigatorListener {
116
- public func navigator(_ navigator: GMSNavigator, didArriveAtWaypoint waypoint: GMSNavigationWaypoint) {
124
+ public func navigator(_ navigator: GMSNavigator, didArriveAt waypoint: GMSNavigationWaypoint) {
117
125
  plugin?.notifyListeners("onArrival", data: [
118
126
  "latitude": waypoint.coordinate.latitude,
119
127
  "longitude": waypoint.coordinate.longitude,
@@ -5,6 +5,7 @@ import GoogleNavigation
5
5
  class NavigationMapViewController: UIViewController {
6
6
  private let session: GMSNavigationSession
7
7
  private var mapView: GMSMapView?
8
+ var onDismiss: (() -> Void)?
8
9
 
9
10
  init(session: GMSNavigationSession) {
10
11
  self.session = session
@@ -27,6 +28,32 @@ class NavigationMapViewController: UIViewController {
27
28
 
28
29
  _ = mapView.enableNavigation(with: session)
29
30
  mapView.cameraMode = .following
31
+
32
+ addCloseButton()
33
+ }
34
+
35
+ private func addCloseButton() {
36
+ let button = UIButton(type: .system)
37
+ button.setImage(UIImage(systemName: "xmark"), for: .normal)
38
+ button.tintColor = .white
39
+ button.backgroundColor = UIColor.black.withAlphaComponent(0.6)
40
+ button.layer.cornerRadius = 20
41
+ button.translatesAutoresizingMaskIntoConstraints = false
42
+ button.addTarget(self, action: #selector(closeTapped), for: .touchUpInside)
43
+ view.addSubview(button)
44
+
45
+ NSLayoutConstraint.activate([
46
+ button.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 16),
47
+ button.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16),
48
+ button.widthAnchor.constraint(equalToConstant: 40),
49
+ button.heightAnchor.constraint(equalToConstant: 40)
50
+ ])
51
+ }
52
+
53
+ @objc private func closeTapped() {
54
+ dismiss(animated: true) { [weak self] in
55
+ self?.onDismiss?()
56
+ }
30
57
  }
31
58
 
32
59
  func setCameraFollowing() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-google-navigation",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Google maps turn by turn navigation for capcitor",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",