@iternio/react-native-auto-play 0.5.14-beta → 0.5.14-beta.1

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.
@@ -53,11 +53,18 @@ class TemplateStore {
53
53
  }
54
54
 
55
55
  func purge() {
56
- withLock {
57
- store = store.filter {
58
- !($0.value.getTemplate() is CPSearchTemplate)
56
+ // These templates were popped by a native CarPlay button we cannot
57
+ // intercept, so they need an `onPopped()` just like an explicit pop.
58
+ let removed = withLock {
59
+ let searchTemplates = store.filter {
60
+ $0.value.getTemplate() is CPSearchTemplate
59
61
  }
62
+ searchTemplates.keys.forEach { store.removeValue(forKey: $0) }
63
+
64
+ return Array(searchTemplates.values)
60
65
  }
66
+
67
+ removed.forEach { template in template.onPopped() }
61
68
  }
62
69
 
63
70
  @MainActor
@@ -68,6 +75,19 @@ class TemplateStore {
68
75
  }
69
76
 
70
77
  func disconnect() {
71
- withLock { store = [:] }
78
+ // The session is gone, so these templates will never be popped
79
+ // individually. Without an `onPopped()` here anything the app tied to a
80
+ // template's lifetime (event listeners, timers, cached render state)
81
+ // leaks for the rest of the app lifetime, and the host app keeps
82
+ // running after a disconnect. Android does the same on
83
+ // `Lifecycle.Event.ON_DESTROY` (AndroidAutoScreen.kt).
84
+ let removed = withLock {
85
+ let templates = Array(store.values)
86
+ store = [:]
87
+
88
+ return templates
89
+ }
90
+
91
+ removed.forEach { template in template.onPopped() }
72
92
  }
73
93
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iternio/react-native-auto-play",
3
- "version": "0.5.14-beta",
3
+ "version": "0.5.14-beta.1",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",