@iternio/react-native-auto-play 0.3.0 → 0.3.2

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.
@@ -37,7 +37,6 @@ Pod::Spec.new do |s|
37
37
  load 'nitrogen/generated/ios/ReactNativeAutoPlay+autolinking.rb'
38
38
  add_nitrogen_files(s)
39
39
 
40
- s.dependency 'React-Core'
41
40
  s.dependency 'React-jsi'
42
41
  s.dependency 'React-callinvoker'
43
42
  install_modules_dependencies(s)
@@ -0,0 +1,19 @@
1
+ //
2
+ // NitroConvert.h
3
+ // Pods
4
+ //
5
+ // Created by Manuel Auer on 04.11.25.
6
+ //
7
+
8
+ // this is required for old architecture support since the React pod can not be imported
9
+
10
+ #import <UIKit/UIKit.h>
11
+
12
+ NS_ASSUME_NONNULL_BEGIN
13
+
14
+ @interface NitroConvert : NSObject
15
+ + (UIColor *)uiColor:(id)json;
16
+ + (UIImage *)uiImage:(id)json;
17
+ @end
18
+
19
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,21 @@
1
+ //
2
+ // NitroConvert.m
3
+ // Pods
4
+ //
5
+ // Created by Manuel Auer on 04.11.25.
6
+ //
7
+
8
+ // this is required for old architecture support since the React pod can not be imported
9
+
10
+ #import "NitroConvert.h"
11
+ #import <React/RCTConvert.h>
12
+
13
+ @implementation NitroConvert
14
+ + (UIColor *)uiColor:(id)json {
15
+ return [RCTConvert UIColor:json];
16
+ }
17
+
18
+ + (nonnull UIImage *)uiImage:(nonnull id)json {
19
+ return [RCTConvert UIImage:json];
20
+ }
21
+ @end
@@ -0,0 +1,10 @@
1
+ //
2
+ // NitroSurface.h
3
+ // Pods
4
+ //
5
+ // Created by Manuel Auer on 28.11.25.
6
+ //
7
+
8
+ @interface NitroSurface : NSObject
9
+ + (void)stop:(nullable UIView *)view;
10
+ @end
@@ -0,0 +1,37 @@
1
+ //
2
+ // NitroSurface.m
3
+ // Pods
4
+ //
5
+ // Created by Manuel Auer on 28.11.25.
6
+ //
7
+
8
+ #import "NitroSurface.h"
9
+ #import <React/RCTInvalidating.h>
10
+ #import <React/RCTRootView.h>
11
+ #import <React/RCTSurface.h>
12
+ #import <React/RCTSurfaceHostingView.h>
13
+
14
+ @implementation NitroSurface
15
+
16
+ + (void)stop:(nullable UIView *)view {
17
+ if (view == nil) {
18
+ NSLog(@"[AutoPlay] View is nil, ignoring");
19
+ return;
20
+ }
21
+
22
+ if ([view isKindOfClass:[RCTSurfaceHostingView class]]) {
23
+ RCTSurfaceHostingView *rootView =
24
+ (RCTSurfaceHostingView *)view;
25
+
26
+ if (rootView == nil) {
27
+ NSLog(@"[AutoPlay] rootView == nil, cannot stop");
28
+ return;
29
+ }
30
+
31
+ [rootView.surface stop];
32
+ }
33
+
34
+ NSLog(@"[AutoPlay] View is not recognized type, ignoring");
35
+ }
36
+
37
+ @end
package/ios/Types.swift CHANGED
@@ -12,7 +12,6 @@ struct TemplateEventPayload {
12
12
 
13
13
  enum AutoPlayError: Error {
14
14
  case templateNotFound(String)
15
- case sceneNotFound(String)
16
15
  case interfaceControllerNotFound(String)
17
16
  case invalidTemplateError(String)
18
17
  case propertyNotFoundError(String)
@@ -147,7 +147,7 @@ class HybridAutoPlay: HybridAutoPlaySpec {
147
147
  -> NitroModules.Promise<Void>
148
148
  {
149
149
  return Promise.async {
150
- return try await RootModule.withSceneAndInterfaceController {
150
+ try await RootModule.withSceneAndInterfaceController {
151
151
  scene,
152
152
  interfaceController in
153
153
 
@@ -196,7 +196,7 @@ class HybridAutoPlay: HybridAutoPlaySpec {
196
196
 
197
197
  func popTemplate(animate: Bool?) throws -> NitroModules.Promise<Void> {
198
198
  return Promise.async {
199
- return try await RootModule.withInterfaceController {
199
+ try await RootModule.withInterfaceController {
200
200
  interfaceController in
201
201
 
202
202
  if try await interfaceController.dismissTemplate(
@@ -240,7 +240,7 @@ class HybridAutoPlay: HybridAutoPlaySpec {
240
240
  Void
241
241
  > {
242
242
  return Promise.async {
243
- return try await RootModule.withInterfaceController {
243
+ try await RootModule.withInterfaceController {
244
244
  interfaceController in
245
245
 
246
246
  let _ = try await interfaceController.dismissTemplate(
@@ -32,7 +32,7 @@ class HybridCarPlayDashboard: HybridCarPlayDashboardSpec {
32
32
 
33
33
  func initRootView() throws -> Promise<Void> {
34
34
  return Promise.async {
35
- guard let scene = try SceneStore.getDashboardScene() else { return }
35
+ guard let scene = SceneStore.getDashboardScene() else { return }
36
36
  try await MainActor.run {
37
37
  try scene.initRootView()
38
38
  }
@@ -43,9 +43,9 @@ class HybridCarPlayDashboard: HybridCarPlayDashboardSpec {
43
43
  Void
44
44
  > {
45
45
  return Promise.async {
46
- try await MainActor.run {
47
- let scene = try SceneStore.getDashboardScene()
48
- scene?.setButtons(buttons: buttons)
46
+ await MainActor.run {
47
+ guard let scene = SceneStore.getDashboardScene() else { return }
48
+ scene.setButtons(buttons: buttons)
49
49
  }
50
50
  }
51
51
  }
@@ -57,10 +57,13 @@ class HybridCluster: HybridClusterSpec {
57
57
  return Promise.async {
58
58
  if #available(iOS 15.4, *) {
59
59
  try await MainActor.run {
60
- let scene = try SceneStore.getClusterScene(
60
+ guard let scene = SceneStore.getClusterScene(
61
61
  clusterId: clusterId
62
- )
63
- try scene?.initRootView()
62
+ ) else {
63
+ return
64
+ }
65
+
66
+ try scene.initRootView()
64
67
  }
65
68
  }
66
69
  else {
@@ -77,10 +80,13 @@ class HybridCluster: HybridClusterSpec {
77
80
  [NitroAttributedString]
78
81
  ) throws {
79
82
  if #available(iOS 15.4, *) {
80
- let scene = try SceneStore.getClusterScene(
83
+ guard let scene = SceneStore.getClusterScene(
81
84
  clusterId: clusterId
82
- )
83
- scene?.setAttributedInactiveDescriptionVariants(
85
+ ) else {
86
+ return
87
+ }
88
+
89
+ scene.setAttributedInactiveDescriptionVariants(
84
90
  attributedInactiveDescriptionVariants:
85
91
  attributedInactiveDescriptionVariants
86
92
  )
@@ -6,7 +6,6 @@
6
6
  //
7
7
 
8
8
  import CarPlay
9
- import React
10
9
 
11
10
  class AutoPlayScene: UIResponder {
12
11
  var initialProperties: [String: Any] = [:]
@@ -54,10 +53,7 @@ class AutoPlayScene: UIResponder {
54
53
  }
55
54
 
56
55
  func disconnect() {
57
- if let view = self.window?.rootViewController?.view, let rootView = view as? RCTSurfaceHostingProxyRootView {
58
- rootView.surface.stop()
59
- }
60
-
56
+ NitroSurface.stop(self.window?.rootViewController?.view)
61
57
  self.window = nil
62
58
  isConnected = false
63
59
 
@@ -49,22 +49,20 @@ class SceneStore {
49
49
  )
50
50
  }
51
51
 
52
- static func getDashboardScene() throws -> DashboardSceneDelegate? {
52
+ static func getDashboardScene() -> DashboardSceneDelegate? {
53
53
  guard
54
54
  let scene = SceneStore.getScene(
55
55
  moduleName: SceneStore.dashboardModuleName
56
56
  )
57
57
  else {
58
- throw AutoPlayError.sceneNotFound(
59
- "operation failed, \(SceneStore.dashboardModuleName) scene not found"
60
- )
58
+ return nil
61
59
  }
62
60
 
63
61
  return scene as? DashboardSceneDelegate
64
62
  }
65
63
 
66
64
  @available(iOS 15.4, *)
67
- static func getClusterScene(clusterId: String) throws
65
+ static func getClusterScene(clusterId: String)
68
66
  -> ClusterSceneDelegate?
69
67
  {
70
68
  guard
@@ -72,9 +70,7 @@ class SceneStore {
72
70
  moduleName: clusterId
73
71
  )
74
72
  else {
75
- throw AutoPlayError.sceneNotFound(
76
- "operation failed, \(clusterId) scene not found"
77
- )
73
+ return nil
78
74
  }
79
75
 
80
76
  return scene as? ClusterSceneDelegate
@@ -580,10 +580,10 @@ class MapTemplate: AutoPlayHeaderProviding,
580
580
 
581
581
  guard let trip = navigationSession?.trip else { return }
582
582
 
583
- let travelEstaimtes = trip.routeChoices.first?
583
+ let travelEstimates = trip.routeChoices.first?
584
584
  .travelEstimates
585
585
  if let estimates = self.visibleTravelEstimate == .first
586
- ? travelEstaimtes?.first : travelEstaimtes?.last
586
+ ? travelEstimates?.first : travelEstimates?.last
587
587
  {
588
588
  template.updateEstimates(estimates, for: trip)
589
589
  }
@@ -7,7 +7,6 @@
7
7
 
8
8
  import CarPlay
9
9
  import UIKit
10
- import React
11
10
 
12
11
  struct HeaderActions {
13
12
  let leadingNavigationBarButtons: [CPBarButton]
@@ -740,7 +739,7 @@ class Parser {
740
739
  }
741
740
 
742
741
  static func doubleToColor(value: Double) -> UIColor {
743
- return RCTConvert.uiColor(value)
742
+ return NitroConvert.uiColor(value)
744
743
  }
745
744
 
746
745
  static func parseNitroImage(
@@ -768,7 +767,7 @@ class Parser {
768
767
  assetImage: AssetImage,
769
768
  traitCollection: UITraitCollection
770
769
  ) -> UIImage? {
771
- let uiImage = RCTConvert.uiImage([
770
+ let uiImage = NitroConvert.uiImage([
772
771
  "height": assetImage.height, "width": assetImage.width,
773
772
  "uri": assetImage.uri, "scale": assetImage.scale,
774
773
  "__packager_asset": assetImage.packager_asset,
@@ -777,10 +776,6 @@ class Parser {
777
776
  guard let color = assetImage.color else {
778
777
  return uiImage
779
778
  }
780
-
781
- guard let uiImage = uiImage else {
782
- return nil
783
- }
784
779
 
785
780
  return getTintedImageAsset(
786
781
  color: color,
@@ -16,9 +16,7 @@ class RootModule {
16
16
  moduleName: SceneStore.rootModuleName
17
17
  )
18
18
  else {
19
- throw AutoPlayError.sceneNotFound(
20
- "operation failed, \(SceneStore.rootModuleName) scene not found"
21
- )
19
+ return
22
20
  }
23
21
 
24
22
  try action(scene)
@@ -51,35 +49,16 @@ class RootModule {
51
49
  }
52
50
  }
53
51
 
54
- static func withTemplate<T: CPTemplate>(
55
- templateId: String,
56
- perform action: @escaping (T) throws -> Void
57
- ) throws {
58
- try withAutoPlayTemplate(templateId: templateId) {
59
- (autoPlayTemplate: AutoPlayTemplate) in
60
- if let template = autoPlayTemplate.getTemplate() as? T {
61
- try! action(template)
62
- }
63
- else {
64
- throw AutoPlayError.invalidTemplateType(
65
- "\(autoPlayTemplate) is not a \(T.self) template"
66
- )
67
- }
68
- }
69
- }
70
-
71
52
  static func withScene<T>(
72
53
  perform action:
73
54
  @escaping (AutoPlayScene) async throws -> T
74
- ) async throws -> T {
55
+ ) async throws -> T? {
75
56
  guard
76
57
  let scene = SceneStore.getScene(
77
58
  moduleName: SceneStore.rootModuleName
78
59
  )
79
60
  else {
80
- throw AutoPlayError.sceneNotFound(
81
- "operation failed, \(SceneStore.rootModuleName) scene not found"
82
- )
61
+ return nil
83
62
  }
84
63
 
85
64
  return try await action(scene)
@@ -90,7 +69,7 @@ class RootModule {
90
69
  perform action:
91
70
  @escaping (AutoPlayScene, AutoPlayInterfaceController) async throws
92
71
  -> T
93
- ) async throws -> T {
72
+ ) async throws -> T? {
94
73
  return try await withScene { scene in
95
74
  guard let interfaceController = scene.interfaceController else {
96
75
  throw AutoPlayError.interfaceControllerNotFound(
@@ -106,7 +85,7 @@ class RootModule {
106
85
  static func withInterfaceController<T>(
107
86
  perform action:
108
87
  @escaping (AutoPlayInterfaceController) async throws -> T
109
- ) async throws -> T {
88
+ ) async throws -> T? {
110
89
  try await withSceneAndInterfaceController { _, interfaceController in
111
90
  try await action(interfaceController)
112
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iternio/react-native-auto-play",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",