@iternio/react-native-auto-play 0.3.1 → 0.3.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.
@@ -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)
@@ -5,7 +5,7 @@ buildscript {
5
5
  }
6
6
 
7
7
  dependencies {
8
- classpath "com.android.tools.build:gradle:8.13.0"
8
+ classpath "com.android.tools.build:gradle:8.13.2"
9
9
  }
10
10
  }
11
11
 
@@ -14,18 +14,11 @@ def reactNativeArchitectures() {
14
14
  return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
15
15
  }
16
16
 
17
- def isNewArchitectureEnabled() {
18
- return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
19
- }
20
-
21
17
  apply plugin: "com.android.library"
22
18
  apply plugin: 'org.jetbrains.kotlin.android'
23
19
  apply from: '../nitrogen/generated/android/ReactNativeAutoPlay+autolinking.gradle'
24
20
  apply from: "./fix-prefab.gradle"
25
-
26
- if (isNewArchitectureEnabled()) {
27
- apply plugin: "com.facebook.react"
28
- }
21
+ apply plugin: "com.facebook.react"
29
22
 
30
23
  def getExtOrDefault(name) {
31
24
  return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["ReactNativeAutoPlay_" + name]
@@ -117,12 +110,10 @@ android {
117
110
 
118
111
  sourceSets {
119
112
  main {
120
- if (isNewArchitectureEnabled()) {
121
- java.srcDirs += [
122
- // React Codegen files
123
- "${project.buildDir}/generated/source/codegen/java"
124
- ]
125
- }
113
+ java.srcDirs += [
114
+ // React Codegen files
115
+ "${project.buildDir}/generated/source/codegen/java"
116
+ ]
126
117
 
127
118
  if (getExtOrDefault("isAutomotiveApp") == "true") {
128
119
  java.srcDirs += 'src/automotive/java'
@@ -163,6 +154,6 @@ dependencies {
163
154
  }
164
155
 
165
156
  implementation 'com.google.android.gms:play-services-base:18.10.0'
166
- implementation 'com.google.android.gms:play-services-auth:21.5.0'
157
+ implementation 'com.google.android.gms:play-services-auth:21.5.1'
167
158
  }
168
159
 
@@ -11,6 +11,7 @@ import android.content.ServiceConnection
11
11
  import android.content.pm.ApplicationInfo
12
12
  import android.content.pm.PackageManager
13
13
  import android.graphics.Bitmap
14
+ import android.os.Build
14
15
  import android.os.IBinder
15
16
  import android.util.Log
16
17
  import androidx.car.app.CarAppService
@@ -61,11 +62,13 @@ class AndroidAutoService : CarAppService() {
61
62
  notificationManager = getSystemService(NotificationManager::class.java)
62
63
  val appLabel = AppInfo.getApplicationLabel(this)
63
64
 
64
- getSystemService(NotificationManager::class.java).createNotificationChannel(
65
- NotificationChannel(
66
- CHANNEL_ID, appLabel, NotificationManager.IMPORTANCE_DEFAULT
65
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
66
+ getSystemService(NotificationManager::class.java).createNotificationChannel(
67
+ NotificationChannel(
68
+ CHANNEL_ID, appLabel, NotificationManager.IMPORTANCE_DEFAULT
69
+ )
67
70
  )
68
- )
71
+ }
69
72
  }
70
73
 
71
74
  override fun onCreateSession(sessionInfo: SessionInfo): Session {
@@ -2,59 +2,35 @@ package com.margelo.nitro.swe.iternio.reactnativeautoplay.utils
2
2
 
3
3
  import com.facebook.react.ReactApplication
4
4
  import com.facebook.react.ReactInstanceEventListener
5
- import com.facebook.react.ReactInstanceManager
6
5
  import com.facebook.react.bridge.ReactContext
7
- import com.margelo.nitro.BuildConfig
8
6
  import kotlinx.coroutines.suspendCancellableCoroutine
9
7
  import kotlin.coroutines.resume
10
8
 
11
9
  object ReactContextResolver {
12
10
  suspend fun getReactContext(application: ReactApplication): ReactContext {
13
- if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
14
- val host =
15
- application.reactHost ?: throw IllegalArgumentException("application host null")
16
- return suspendCancellableCoroutine { continuation ->
17
- host.currentReactContext?.let {
18
- continuation.resume(it)
19
- return@suspendCancellableCoroutine
20
- }
21
-
22
- val listener = object : ReactInstanceEventListener {
23
- override fun onReactContextInitialized(context: ReactContext) {
24
- host.removeReactInstanceEventListener(this)
25
- continuation.resume(context)
26
- }
27
- }
28
- host.addReactInstanceEventListener(listener)
11
+ val host =
12
+ application.reactHost ?: throw IllegalArgumentException("application host null")
29
13
 
30
- continuation.invokeOnCancellation {
31
- host.removeReactInstanceEventListener(listener)
32
- }
33
-
34
- host.start()
14
+ return suspendCancellableCoroutine { continuation ->
15
+ host.currentReactContext?.let {
16
+ continuation.resume(it)
17
+ return@suspendCancellableCoroutine
35
18
  }
36
- } else {
37
- val reactInstanceManager = application.reactNativeHost.reactInstanceManager
38
- return suspendCancellableCoroutine { continuation ->
39
- reactInstanceManager.currentReactContext?.let {
40
- continuation.resume(it)
41
- return@suspendCancellableCoroutine
42
- }
43
19
 
44
- val listener = object : ReactInstanceManager.ReactInstanceEventListener {
45
- override fun onReactContextInitialized(context: ReactContext) {
46
- reactInstanceManager.removeReactInstanceEventListener(this)
47
- continuation.resume(context)
48
- }
49
- }
50
- reactInstanceManager.addReactInstanceEventListener(listener)
51
-
52
- continuation.invokeOnCancellation {
53
- reactInstanceManager.removeReactInstanceEventListener(listener)
20
+ val listener = object : ReactInstanceEventListener {
21
+ override fun onReactContextInitialized(context: ReactContext) {
22
+ host.removeReactInstanceEventListener(this)
23
+ continuation.resume(context)
54
24
  }
25
+ }
26
+ host.addReactInstanceEventListener(listener)
55
27
 
56
- reactInstanceManager.createReactContextInBackground()
28
+ continuation.invokeOnCancellation {
29
+ host.removeReactInstanceEventListener(listener)
57
30
  }
31
+
32
+ host.start()
58
33
  }
34
+
59
35
  }
60
36
  }
@@ -9,7 +9,7 @@
9
9
  #import <React/RCTInvalidating.h>
10
10
  #import <React/RCTRootView.h>
11
11
  #import <React/RCTSurface.h>
12
- #import <React/RCTSurfaceHostingProxyRootView.h>
12
+ #import <React/RCTSurfaceHostingView.h>
13
13
 
14
14
  @implementation NitroSurface
15
15
 
@@ -20,8 +20,8 @@
20
20
  }
21
21
 
22
22
  if ([view isKindOfClass:[RCTSurfaceHostingView class]]) {
23
- RCTSurfaceHostingProxyRootView *rootView =
24
- (RCTSurfaceHostingProxyRootView *)view;
23
+ RCTSurfaceHostingView *rootView =
24
+ (RCTSurfaceHostingView *)view;
25
25
 
26
26
  if (rootView == nil) {
27
27
  NSLog(@"[AutoPlay] rootView == nil, cannot stop");
@@ -30,7 +30,7 @@
30
30
 
31
31
  [rootView.surface stop];
32
32
  }
33
-
33
+
34
34
  NSLog(@"[AutoPlay] View is not recognized type, ignoring");
35
35
  }
36
36
 
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
  )
@@ -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
  }
@@ -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.1",
3
+ "version": "0.3.3",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",