@iternio/react-native-auto-play 0.0.1 → 0.0.3

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.
Files changed (73) hide show
  1. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/AndroidAutoSession.kt +2 -0
  2. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/{hybrid/HybridAutoPlay.kt → HybridAutoPlay.kt} +20 -20
  3. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/{hybrid/HybridSearchTemplate.kt → HybridSearchTemplate.kt} +3 -3
  4. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/VirtualRenderer.kt +1 -1
  5. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/template/GridTemplate.kt +1 -16
  6. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/template/InformationTemplate.kt +1 -14
  7. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/template/ListTemplate.kt +1 -16
  8. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/template/MapTemplate.kt +5 -1
  9. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/template/MessageTemplate.kt +1 -16
  10. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/template/Parser.kt +58 -17
  11. package/ios/Assets/MaterialSymbolsOutlined-Regular.ttf +0 -0
  12. package/ios/Types.swift +1 -0
  13. package/ios/hybrid/HybridAutoPlay.swift +5 -4
  14. package/ios/hybrid/HybridGridTemplate.swift +3 -6
  15. package/ios/hybrid/HybridInformationTemplate.swift +9 -9
  16. package/ios/hybrid/HybridListTemplate.swift +3 -6
  17. package/ios/hybrid/HybridMapTemplate.swift +21 -16
  18. package/ios/hybrid/HybridSearchTemplate.swift +7 -11
  19. package/ios/templates/AutoPlayTemplate.swift +31 -48
  20. package/ios/templates/GridTemplate.swift +31 -22
  21. package/ios/templates/InformationTemplate.swift +29 -21
  22. package/ios/templates/ListTemplate.swift +29 -20
  23. package/ios/templates/MapTemplate.swift +162 -61
  24. package/ios/templates/MessageTemplate.swift +19 -12
  25. package/ios/templates/SearchTemplate.swift +17 -25
  26. package/ios/templates/TemplateStore.swift +3 -3
  27. package/ios/utils/RootModule.swift +36 -38
  28. package/lib/templates/MapTemplate.d.ts +14 -3
  29. package/lib/templates/Template.d.ts +1 -0
  30. package/lib/types/Button.d.ts +5 -4
  31. package/lib/types/Maneuver.d.ts +3 -1
  32. package/lib/utils/NitroMapButton.d.ts +2 -2
  33. package/lib/utils/NitroMapButton.js +4 -9
  34. package/nitrogen/generated/android/ReactNativeAutoPlayOnLoad.cpp +2 -0
  35. package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +74 -0
  36. package/nitrogen/generated/android/c++/JGridTemplateConfig.hpp +1 -0
  37. package/nitrogen/generated/android/c++/JHybridGridTemplateSpec.cpp +1 -0
  38. package/nitrogen/generated/android/c++/JHybridInformationTemplateSpec.cpp +2 -0
  39. package/nitrogen/generated/android/c++/JHybridListTemplateSpec.cpp +2 -0
  40. package/nitrogen/generated/android/c++/JHybridMapTemplateSpec.cpp +3 -2
  41. package/nitrogen/generated/android/c++/JHybridMessageTemplateSpec.cpp +2 -0
  42. package/nitrogen/generated/android/c++/JInformationTemplateConfig.hpp +2 -0
  43. package/nitrogen/generated/android/c++/JListTemplateConfig.hpp +2 -0
  44. package/nitrogen/generated/android/c++/JMapTemplateConfig.hpp +31 -11
  45. package/nitrogen/generated/android/c++/JMessageTemplateConfig.hpp +2 -0
  46. package/nitrogen/generated/android/c++/JNitroBaseMapTemplateConfig.hpp +17 -1
  47. package/nitrogen/generated/android/c++/JNitroMapButton.hpp +9 -9
  48. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/Func_void_bool.kt +80 -0
  49. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/MapTemplateConfig.kt +12 -6
  50. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/NitroBaseMapTemplateConfig.kt +7 -4
  51. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/NitroMapButton.kt +5 -5
  52. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.cpp +8 -0
  53. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.hpp +37 -0
  54. package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
  55. package/nitrogen/generated/ios/swift/MapTemplateConfig.swift +70 -6
  56. package/nitrogen/generated/ios/swift/NitroBaseMapTemplateConfig.swift +42 -1
  57. package/nitrogen/generated/ios/swift/NitroMapButton.swift +54 -54
  58. package/nitrogen/generated/shared/c++/MapTemplateConfig.hpp +14 -6
  59. package/nitrogen/generated/shared/c++/NitroBaseMapTemplateConfig.hpp +5 -1
  60. package/nitrogen/generated/shared/c++/NitroMapButton.hpp +10 -10
  61. package/package.json +2 -1
  62. package/src/templates/MapTemplate.ts +32 -12
  63. package/src/templates/Template.ts +1 -0
  64. package/src/types/Button.ts +5 -4
  65. package/src/types/Maneuver.ts +1 -1
  66. package/src/utils/NitroMapButton.ts +6 -14
  67. /package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/{hybrid/HybridAndroidAutoTelemetry.kt → HybridAndroidAutoTelemetry.kt} +0 -0
  68. /package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/{hybrid/HybridCluster.kt → HybridCluster.kt} +0 -0
  69. /package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/{hybrid/HybridGridTemplate.kt → HybridGridTemplate.kt} +0 -0
  70. /package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/{hybrid/HybridInformationTemplate.kt → HybridInformationTemplate.kt} +0 -0
  71. /package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/{hybrid/HybridListTemplate.kt → HybridListTemplate.kt} +0 -0
  72. /package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/{hybrid/HybridMapTemplate.kt → HybridMapTemplate.kt} +0 -0
  73. /package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/{hybrid/HybridMessageTemplate.kt → HybridMessageTemplate.kt} +0 -0
@@ -11,14 +11,35 @@ struct NavigationAlertWrapper {
11
11
  let config: NitroNavigationAlert
12
12
  }
13
13
 
14
- class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
14
+ class MapTemplate: NSObject, AutoPlayTemplate, AutoPlayHeaderProviding,
15
+ CPMapTemplateDelegate
16
+ {
17
+ let template: CPMapTemplate
15
18
  var config: MapTemplateConfig
16
19
 
20
+ let screenDimensions: CGSize
21
+
22
+ var barButtons: [NitroAction]? {
23
+ get {
24
+ return config.headerActions
25
+ }
26
+ set {
27
+ config.headerActions = newValue
28
+ setBarButtons(template: template, barButtons: newValue)
29
+ }
30
+ }
31
+
32
+ var autoDismissMs: Double? {
33
+ return config.autoDismissMs
34
+ }
35
+
36
+ func getTemplate() -> CPTemplate {
37
+ return template
38
+ }
39
+
17
40
  var onTripSelected: ((_ tripId: String, _ routeId: String) -> Void)?
18
41
  var onTripStarted: ((_ tripId: String, _ routeId: String) -> Void)?
19
-
20
42
  var navigationSession: CPNavigationSession?
21
-
22
43
  var navigationAlert: NavigationAlertWrapper?
23
44
 
24
45
  var tripSelectorVisible = false {
@@ -32,23 +53,38 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
32
53
 
33
54
  init(config: MapTemplateConfig) {
34
55
  self.config = config
56
+ template = CPMapTemplate(id: config.id)
35
57
 
36
- super.init(
37
- template: CPMapTemplate(id: config.id),
38
- header: config.headerActions,
39
- autoDismissMs: config.autoDismissMs
40
- )
41
-
42
- if let template = self.template as? CPMapTemplate {
43
- template.mapDelegate = self
58
+ if let initialProperties = SceneStore.getRootScene()?.initialProperties,
59
+ let windowDict = initialProperties["window"] as? [String: Any],
60
+ let height = windowDict["height"] as? CGFloat,
61
+ let width = windowDict["width"] as? CGFloat
62
+ {
63
+ screenDimensions = CGSize(
64
+ width: width,
65
+ height: height
66
+ )
67
+ } else {
68
+ screenDimensions = CGSize(width: 0, height: 0)
44
69
  }
45
70
 
71
+ super.init()
72
+
73
+ template.mapDelegate = self
46
74
  invalidate()
47
75
  }
48
76
 
77
+ func onPanButtonPress() {
78
+ if template.isPanningInterfaceVisible {
79
+ template.dismissPanningInterface(animated: true)
80
+ } else {
81
+ template.showPanningInterface(animated: true)
82
+ }
83
+ }
84
+
49
85
  func parseMapButtons(mapButtons: [NitroMapButton]) -> [CPMapButton] {
50
86
  return mapButtons.map { button in
51
- if let glyphImage = button.image?.glyphImage,
87
+ if let glyphImage = button.image.glyphImage,
52
88
  let icon = SymbolFont.imageFromNitroImage(
53
89
  image: glyphImage,
54
90
  size: CPButtonMaximumImageSize.height,
@@ -56,72 +92,101 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
56
92
  )
57
93
  {
58
94
  return CPMapButton(image: icon) { _ in
59
- button.onPress()
95
+ if button.type == .pan {
96
+ self.onPanButtonPress()
97
+ return
98
+ }
99
+ button.onPress?()
60
100
  }
61
101
  }
62
- if let assetImage = button.image?.assetImage,
102
+ if let assetImage = button.image.assetImage,
63
103
  let icon = Parser.parseAssetImage(
64
104
  assetImage: assetImage,
65
105
  traitCollection: SceneStore.getRootTraitCollection()
66
106
  )
67
107
  {
68
108
  return CPMapButton(image: icon) { _ in
69
- button.onPress()
109
+ if button.type == .pan {
110
+ self.onPanButtonPress()
111
+ return
112
+ }
113
+ button.onPress?()
70
114
  }
71
115
  }
72
116
 
73
117
  return CPMapButton { _ in
74
- button.onPress()
118
+ if button.type == .pan {
119
+ self.onPanButtonPress()
120
+ return
121
+ }
122
+ button.onPress?()
75
123
  }
76
124
  }
77
125
 
78
126
  }
79
127
 
80
- override func invalidate() {
128
+ func invalidate() {
81
129
  if tripSelectorVisible {
82
130
  // ignore invalidate calls to not break the trip selectors back button
83
131
  return
84
132
  }
133
+
134
+ if template.isPanningInterfaceVisible {
135
+ // while panning interface is shown we only provide a back button on the header
136
+ // and all map buttons except the pan button
137
+ // reason is that you can have a max of 2 map buttons while panning interface is shown
138
+ // best practice is to provide zoom buttons then but then there is no more room for the pan button to exit pan mode
139
+ template.trailingNavigationBarButtons = []
140
+ template.leadingNavigationBarButtons = []
141
+ template.backButton = CPBarButton(title: "") { _ in
142
+ self.template.dismissPanningInterface(animated: true)
143
+ }
144
+
145
+ let mapButtons = config.mapButtons?.filter { button in
146
+ button.type != .pan
147
+ } ?? []
148
+
149
+ template.mapButtons = parseMapButtons(mapButtons: mapButtons)
150
+
151
+ return
152
+ }
85
153
 
86
- guard let template = self.template as? CPMapTemplate else { return }
87
-
88
- setBarButtons()
154
+ setBarButtons(template: template, barButtons: config.headerActions)
89
155
 
90
156
  if let mapButtons = config.mapButtons {
91
157
  template.mapButtons = parseMapButtons(mapButtons: mapButtons)
92
158
  }
93
159
  }
94
160
 
95
- override func onWillAppear(animated: Bool) {
161
+ func onWillAppear(animated: Bool) {
96
162
  config.onWillAppear?(animated)
97
163
  }
98
164
 
99
- override func onDidAppear(animated: Bool) {
165
+ func onDidAppear(animated: Bool) {
100
166
  config.onDidAppear?(animated)
101
167
  }
102
168
 
103
- override func onWillDisappear(animated: Bool) {
169
+ func onWillDisappear(animated: Bool) {
104
170
  config.onWillDisappear?(animated)
105
171
  }
106
172
 
107
- override func onDidDisappear(animated: Bool) {
173
+ func onDidDisappear(animated: Bool) {
108
174
  config.onDidDisappear?(animated)
109
175
  }
110
176
 
111
- override func onPopped() {
177
+ func onPopped() {
112
178
  config.onPopped?()
113
179
  }
114
180
 
115
- override func traitCollectionDidChange() {
181
+ func traitCollectionDidChange() {
116
182
  let traitCollection = SceneStore.getRootTraitCollection()
117
183
  let isDark = traitCollection.userInterfaceStyle == .dark
118
184
 
119
- self.config.onAppearanceDidChange?(
185
+ config.onAppearanceDidChange?(
120
186
  isDark ? .dark : .light
121
187
  )
122
- self.invalidate()
123
188
 
124
- guard let template = self.template as? CPMapTemplate else { return }
189
+ invalidate()
125
190
 
126
191
  template.tripEstimateStyle = isDark ? .dark : .light
127
192
  }
@@ -132,7 +197,7 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
132
197
  didUpdatePanGestureWithTranslation: CGPoint,
133
198
  velocity: CGPoint
134
199
  ) {
135
- config.onDidUpdatePanGestureWithTranslation?(
200
+ config.onDidPan?(
136
201
  Point(
137
202
  x: didUpdatePanGestureWithTranslation.x,
138
203
  y: didUpdatePanGestureWithTranslation.y
@@ -147,6 +212,10 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
147
212
  scale: CGFloat,
148
213
  velocity: CGFloat
149
214
  ) {
215
+ if template.isPanningInterfaceVisible {
216
+ return
217
+ }
218
+
150
219
  if scale == 1 && velocity == 1 {
151
220
  config.onDoubleClick?(Point(x: center.x, y: center.y))
152
221
  return
@@ -158,6 +227,47 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
158
227
  )
159
228
  }
160
229
 
230
+ func mapTemplateDidShowPanningInterface(_ mapTemplate: CPMapTemplate) {
231
+ config.onDidChangePanningInterface?(true)
232
+ invalidate()
233
+ }
234
+
235
+ func mapTemplateDidDismissPanningInterface(_ mapTemplate: CPMapTemplate) {
236
+ config.onDidChangePanningInterface?(false)
237
+ invalidate()
238
+ }
239
+
240
+ func mapTemplate(
241
+ _ mapTemplate: CPMapTemplate,
242
+ panWith direction: CPMapTemplate.PanDirection
243
+ ) {
244
+ let panButtonScrollPercentage = config.panButtonScrollPercentage ?? 0.15
245
+ let scrollDistanceX = screenDimensions.width * panButtonScrollPercentage
246
+ let scrollDistanceY = screenDimensions.height * panButtonScrollPercentage
247
+
248
+ var translation = CGPoint.zero
249
+
250
+ switch direction {
251
+ case .left:
252
+ translation.x = scrollDistanceX
253
+ case .right:
254
+ translation.x = -scrollDistanceX
255
+ case .up:
256
+ translation.y = scrollDistanceY
257
+ case .down:
258
+ translation.y = -scrollDistanceY
259
+ default:
260
+ return
261
+ }
262
+
263
+ let velocity = CGPoint(x: translation.x * 2, y: translation.y * 2)
264
+
265
+ config.onDidPan?(
266
+ Point(x: translation.x, y: translation.y),
267
+ Point(x: velocity.x, y: velocity.y)
268
+ )
269
+ }
270
+
161
271
  // MARK: maneuver style
162
272
  func mapTemplate(
163
273
  _ mapTemplate: CPMapTemplate,
@@ -225,6 +335,8 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
225
335
  case .userDismissed: return .user
226
336
  case .timeout: return .timeout
227
337
  case .systemDismissed: return .system
338
+ @unknown default:
339
+ return .system
228
340
  }
229
341
  }()
230
342
 
@@ -233,8 +345,6 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
233
345
  }
234
346
 
235
347
  func showAlert(alertConfig: NitroNavigationAlert) {
236
- guard let template = self.template as? CPMapTemplate else { return }
237
-
238
348
  if let priority = self.navigationAlert?.config.priority,
239
349
  priority > alertConfig.priority
240
350
  {
@@ -254,6 +364,7 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
254
364
  let style = Parser.parseActionAlertStyle(
255
365
  style: alertConfig.primaryAction.style
256
366
  )
367
+
257
368
  let primaryAction = CPAlertAction(
258
369
  title: alertConfig.primaryAction.title,
259
370
  style: style
@@ -274,7 +385,7 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
274
385
  image: image,
275
386
  primaryAction: primaryAction,
276
387
  secondaryAction: secondaryAction,
277
- duration: alertConfig.durationMs / 1000,
388
+ duration: alertConfig.durationMs / 1000
278
389
  )
279
390
 
280
391
  func setNavigationAlert() {
@@ -290,21 +401,26 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
290
401
  setNavigationAlert()
291
402
  }
292
403
  }
293
-
294
- func updateNavigationAlert(alertId: Double, title: AutoText, subtitle: AutoText?) {
404
+
405
+ func updateNavigationAlert(
406
+ alertId: Double,
407
+ title: AutoText,
408
+ subtitle: AutoText?
409
+ ) {
295
410
  guard let alert = self.navigationAlert?.alert else {
296
411
  return
297
412
  }
298
-
413
+
299
414
  if self.navigationAlert?.config.id != alertId {
300
415
  return
301
416
  }
302
-
417
+
303
418
  let title = Parser.parseText(text: title)!
304
- let subtitle = subtitle.map { subtitle in
305
- [Parser.parseText(text: subtitle)!]
306
- } ?? []
307
-
419
+ let subtitle =
420
+ subtitle.map { subtitle in
421
+ [Parser.parseText(text: subtitle)!]
422
+ } ?? []
423
+
308
424
  alert.updateTitleVariants([title], subtitleVariants: subtitle)
309
425
  }
310
426
 
@@ -313,7 +429,6 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
313
429
  return
314
430
  }
315
431
 
316
- guard let template = self.template as? CPMapTemplate else { return }
317
432
  template.dismissNavigationAlert(animated: true) { _ in }
318
433
  }
319
434
 
@@ -326,13 +441,7 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
326
441
  onTripStarted: @escaping (_ tripId: String, _ routeId: String) -> Void,
327
442
  onBackPressed: @escaping () -> Void,
328
443
  mapButtons: [NitroMapButton]
329
- ) throws -> TripSelectorCallback {
330
- guard let template = self.template as? CPMapTemplate else {
331
- throw AutoPlayError.invalidTemplateError(
332
- template.id + " template not of type map template"
333
- )
334
- }
335
-
444
+ ) -> TripSelectorCallback {
336
445
  self.onTripSelected = onTripSelected
337
446
  self.onTripStarted = onTripStarted
338
447
 
@@ -375,7 +484,7 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
375
484
  let selectedTrip = tripPreviews.first { trip in
376
485
  trip.id == tripId
377
486
  }
378
- template.showTripPreviews(
487
+ self.template.showTripPreviews(
379
488
  tripPreviews,
380
489
  selectedTrip: selectedTrip,
381
490
  textConfiguration: textConfiguration
@@ -386,13 +495,11 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
386
495
  }
387
496
 
388
497
  func hideTripSelector() {
389
- guard let template = self.template as? CPMapTemplate else { return }
390
-
391
498
  template.hideTripPreviews()
392
499
 
393
- self.tripSelectorVisible = false
394
- self.onTripSelected = nil
395
- self.onTripStarted = nil
500
+ tripSelectorVisible = false
501
+ onTripSelected = nil
502
+ onTripStarted = nil
396
503
  }
397
504
 
398
505
  func mapTemplate(
@@ -438,8 +545,6 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
438
545
  func updateVisibleTravelEstimate(
439
546
  visibleTravelEstimate: VisibleTravelEstimate?
440
547
  ) {
441
- guard let template = self.template as? CPMapTemplate else { return }
442
-
443
548
  if let visibleTravelEstimate = visibleTravelEstimate {
444
549
  config.visibleTravelEstimate = visibleTravelEstimate
445
550
  }
@@ -474,7 +579,6 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
474
579
  }
475
580
 
476
581
  func updateManeuvers(messageManeuver: NitroMessageManeuver) {
477
- guard let template = template as? CPMapTemplate else { return }
478
582
  guard let navigationSession = navigationSession else { return }
479
583
 
480
584
  let color = messageManeuver.cardBackgroundColor
@@ -505,7 +609,6 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
505
609
  }
506
610
 
507
611
  func updateManeuvers(maneuvers: [NitroRoutingManeuver]) {
508
- guard let template = template as? CPMapTemplate else { return }
509
612
  guard let navigationSession = navigationSession else { return }
510
613
 
511
614
  if #unavailable(iOS 15.4),
@@ -605,8 +708,6 @@ class MapTemplate: AutoPlayTemplate, CPMapTemplateDelegate {
605
708
  }
606
709
 
607
710
  func startNavigation(trip: CPTrip) {
608
- guard let template = self.template as? CPMapTemplate else { return }
609
-
610
711
  let routeChoice = trip.routeChoices.first
611
712
 
612
713
  if let travelEstimates = config.visibleTravelEstimate == .first
@@ -8,41 +8,48 @@
8
8
  import CarPlay
9
9
 
10
10
  class MessageTemplate: AutoPlayTemplate {
11
+ let template: CPAlertTemplate
11
12
  var config: MessageTemplateConfig
13
+
14
+ var autoDismissMs: Double? {
15
+ return config.autoDismissMs
16
+ }
17
+
18
+ func getTemplate() -> CPTemplate {
19
+ return template
20
+ }
12
21
 
13
22
  init(config: MessageTemplateConfig) {
14
23
  self.config = config
15
24
 
16
- let template = CPAlertTemplate(
25
+ template = CPAlertTemplate(
17
26
  titleVariants: [Parser.parseText(text: config.message)!],
18
27
  actions: Parser.parseAlertActions(alertActions: config.actions),
19
28
  id: config.id
20
29
  )
21
-
22
- super.init(
23
- template: template,
24
- header: config.headerActions,
25
- autoDismissMs: config.autoDismissMs
26
- )
30
+ }
31
+
32
+ func invalidate() {
33
+ // this template can not be updated
27
34
  }
28
35
 
29
- override func onWillAppear(animated: Bool) {
36
+ func onWillAppear(animated: Bool) {
30
37
  config.onWillAppear?(animated)
31
38
  }
32
39
 
33
- override func onDidAppear(animated: Bool) {
40
+ func onDidAppear(animated: Bool) {
34
41
  config.onDidAppear?(animated)
35
42
  }
36
43
 
37
- override func onWillDisappear(animated: Bool) {
44
+ func onWillDisappear(animated: Bool) {
38
45
  config.onWillDisappear?(animated)
39
46
  }
40
47
 
41
- override func onDidDisappear(animated: Bool) {
48
+ func onDidDisappear(animated: Bool) {
42
49
  config.onDidDisappear?(animated)
43
50
  }
44
51
 
45
- override func onPopped() {
52
+ func onPopped() {
46
53
  config.onPopped?()
47
54
  }
48
55
  }
@@ -7,26 +7,26 @@
7
7
 
8
8
  import CarPlay
9
9
 
10
- class SearchTemplate: AutoPlayTemplate, CPSearchTemplateDelegate {
10
+ class SearchTemplate: NSObject, AutoPlayTemplate, CPSearchTemplateDelegate {
11
+ var template: CPSearchTemplate
11
12
  var config: SearchTemplateConfig
13
+
14
+ var autoDismissMs: Double? {
15
+ return config.autoDismissMs
16
+ }
12
17
 
13
- var completionHandler: (([CPListItem]) -> Void)?
18
+ func getTemplate() -> CPTemplate {
19
+ return template
20
+ }
14
21
 
22
+ var completionHandler: (([CPListItem]) -> Void)?
15
23
  var pushedListTemplate: ListTemplate?
16
-
17
24
  var searchText = ""
18
-
19
25
  var isInitialized = false
20
26
 
21
27
  init(config: SearchTemplateConfig) {
22
28
  self.config = config
23
- let template = CPSearchTemplate(id: config.id)
24
-
25
- super.init(
26
- template: template,
27
- header: config.headerActions,
28
- autoDismissMs: config.autoDismissMs
29
- )
29
+ template = CPSearchTemplate(id: config.id)
30
30
  }
31
31
 
32
32
  func updateSearchResults(results: NitroSection) {
@@ -34,7 +34,7 @@ class SearchTemplate: AutoPlayTemplate, CPSearchTemplateDelegate {
34
34
  invalidate()
35
35
  }
36
36
 
37
- override func invalidate() {
37
+ func invalidate() {
38
38
  // if we have pushed a list template update it
39
39
  if let listTemplate = pushedListTemplate {
40
40
  listTemplate.updateSections(sections: [config.results])
@@ -54,34 +54,26 @@ class SearchTemplate: AutoPlayTemplate, CPSearchTemplateDelegate {
54
54
  self.completionHandler = nil
55
55
  }
56
56
 
57
- override func onWillAppear(animated: Bool) {
57
+ func onWillAppear(animated: Bool) {
58
58
  self.pushedListTemplate = nil
59
59
  config.onWillAppear?(animated)
60
60
  }
61
61
 
62
- override func onDidAppear(animated: Bool) {
62
+ func onDidAppear(animated: Bool) {
63
63
  config.onDidAppear?(animated)
64
-
65
- guard let template = self.template as? CPSearchTemplate else {
66
- return
67
- }
68
64
  template.delegate = self
69
65
  }
70
66
 
71
- override func onWillDisappear(animated: Bool) {
67
+ func onWillDisappear(animated: Bool) {
72
68
  config.onWillDisappear?(animated)
73
-
74
- guard let template = self.template as? CPSearchTemplate else {
75
- return
76
- }
77
69
  template.delegate = nil
78
70
  }
79
71
 
80
- override func onDidDisappear(animated: Bool) {
72
+ func onDidDisappear(animated: Bool) {
81
73
  config.onDidDisappear?(animated)
82
74
  }
83
75
 
84
- override func onPopped() {
76
+ func onPopped() {
85
77
  config.onPopped?()
86
78
  }
87
79
 
@@ -10,7 +10,7 @@ class TemplateStore {
10
10
  private var store: [String: AutoPlayTemplate] = [:]
11
11
 
12
12
  func getCPTemplate(templateId key: String) -> CPTemplate? {
13
- return store[key]?.template
13
+ return store[key]?.getTemplate()
14
14
  }
15
15
 
16
16
  func getTemplate(templateId: String) -> AutoPlayTemplate? {
@@ -34,9 +34,9 @@ class TemplateStore {
34
34
 
35
35
  store = store.filter { !templateIds.contains($0.key) }
36
36
  }
37
-
37
+
38
38
  func purge() {
39
- store = store.filter { !($0.value.template is CPSearchTemplate) }
39
+ store = store.filter { !($0.value.getTemplate() is CPSearchTemplate) }
40
40
  }
41
41
 
42
42
  func traitCollectionDidChange() {