@iternio/react-native-auto-play 0.1.12 → 0.1.14

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
@@ -484,5 +484,5 @@ Contributions are welcome! Please submit a pull request.
484
484
 
485
485
  ## License
486
486
 
487
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
487
+ This project is licensed under the MIT License - see the [LICENSE](../../LICENSE.md) file for details.
488
488
 
@@ -2,6 +2,7 @@ package com.margelo.nitro.swe.iternio.reactnativeautoplay
2
2
 
3
3
  import android.app.Presentation
4
4
  import android.content.Context
5
+ import android.view.ContextThemeWrapper
5
6
  import android.graphics.Color
6
7
  import android.graphics.Rect
7
8
  import android.hardware.display.DisplayManager
@@ -22,6 +23,7 @@ import com.facebook.react.ReactApplication
22
23
  import com.facebook.react.ReactRootView
23
24
  import com.facebook.react.bridge.Arguments
24
25
  import com.facebook.react.bridge.ReactContext
26
+ import com.facebook.react.bridge.UIManager
25
27
  import com.facebook.react.fabric.FabricUIManager
26
28
  import com.facebook.react.runtime.ReactSurfaceImpl
27
29
  import com.facebook.react.runtime.ReactSurfaceView
@@ -42,8 +44,14 @@ class VirtualRenderer(
42
44
  private val moduleName: String,
43
45
  private val isCluster: Boolean = false
44
46
  ) {
45
- private lateinit var uiManager: FabricUIManager
47
+ private lateinit var fabricUiManager: FabricUIManager
48
+ private lateinit var uiManager: UIManager
49
+
46
50
  private fun isUiManagerInitialized(): Boolean {
51
+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
52
+ return ::fabricUiManager.isInitialized
53
+ }
54
+
47
55
  return ::uiManager.isInitialized
48
56
  }
49
57
 
@@ -78,9 +86,13 @@ class VirtualRenderer(
78
86
  ReactContextResolver.getReactContext(context.applicationContext as ReactApplication)
79
87
 
80
88
  if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
81
- uiManager = UIManagerHelper.getUIManager(
89
+ fabricUiManager = UIManagerHelper.getUIManager(
82
90
  reactContext, UIManagerType.FABRIC
83
91
  ) as FabricUIManager
92
+ } else {
93
+ uiManager = UIManagerHelper.getUIManager(
94
+ reactContext, UIManagerType.LEGACY
95
+ ) as UIManager
84
96
  }
85
97
 
86
98
  initRenderer()
@@ -287,6 +299,11 @@ class VirtualRenderer(
287
299
  context, display, height, width, initialProperties, reactNativeScale
288
300
  ).show()
289
301
  } else {
302
+ if (!isUiManagerInitialized()) {
303
+ // this makes sure we have all required instances
304
+ // no matter if the app is launched on the phone or AA first
305
+ return
306
+ }
290
307
  MapPresentation(
291
308
  context, display, height, width, initialProperties, reactNativeScale
292
309
  ).show()
@@ -312,7 +329,10 @@ class VirtualRenderer(
312
329
 
313
330
  val instanceManager =
314
331
  (context.applicationContext as ReactApplication).reactNativeHost.reactInstanceManager
315
- reactRootView = ReactRootView(context.applicationContext).apply {
332
+ // Wrap applicationContext with app theme to support AppCompat widgets like ReactTextView
333
+ val appTheme = context.applicationContext.applicationInfo.theme
334
+ val themedContext = ContextThemeWrapper(context.applicationContext, appTheme)
335
+ reactRootView = ReactRootView(themedContext).apply {
316
336
  layoutParams = FrameLayout.LayoutParams(
317
337
  (this@MapPresentation.width / reactNativeScale).toInt(),
318
338
  (this@MapPresentation.height / reactNativeScale).toInt()
@@ -387,7 +407,7 @@ class VirtualRenderer(
387
407
  }
388
408
  }
389
409
 
390
- reactSurfaceId = uiManager.startSurface(
410
+ reactSurfaceId = fabricUiManager.startSurface(
391
411
  reactSurfaceView,
392
412
  moduleName,
393
413
  Arguments.fromBundle(initialProperties),
@@ -400,9 +420,9 @@ class VirtualRenderer(
400
420
  )
401
421
 
402
422
  // remove ui-managers lifecycle listener to not stop rendering when app is not in foreground/phone screen is off
403
- reactContext.removeLifecycleEventListener(uiManager)
423
+ reactContext.removeLifecycleEventListener(fabricUiManager)
404
424
  // trigger ui-managers onHostResume to make sure the surface is rendered properly even when AA only is starting without the phone app
405
- uiManager.onHostResume()
425
+ fabricUiManager.onHostResume()
406
426
  } else {
407
427
  (reactSurfaceView.parent as ViewGroup).removeView(reactSurfaceView)
408
428
  }
@@ -479,7 +499,7 @@ class VirtualRenderer(
479
499
  if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
480
500
  if (renderer?.isUiManagerInitialized() == true) {
481
501
  renderer.reactSurfaceId?.let {
482
- renderer.uiManager.stopSurface(it)
502
+ renderer.fabricUiManager.stopSurface(it)
483
503
  }
484
504
  }
485
505
  } else {
@@ -5,6 +5,7 @@ import android.graphics.Color
5
5
  import androidx.car.app.AppManager
6
6
  import androidx.car.app.CarContext
7
7
  import androidx.car.app.model.Action
8
+ import androidx.car.app.model.ActionStrip
8
9
  import androidx.car.app.model.Alert
9
10
  import androidx.car.app.model.AlertCallback
10
11
  import androidx.car.app.model.CarColor
@@ -75,6 +76,12 @@ class MapTemplate(
75
76
  }
76
77
  config.headerActions?.let { headerActions ->
77
78
  setActionStrip(Parser.parseMapHeaderActions(context, headerActions))
79
+ } ?: run {
80
+ setActionStrip(
81
+ ActionStrip.Builder()
82
+ .addAction(Action.APP_ICON)
83
+ .build()
84
+ )
78
85
  }
79
86
  val travelEstimates =
80
87
  if (config.visibleTravelEstimate == VisibleTravelEstimate.FIRST) destinationTravelEstimates.firstOrNull() else destinationTravelEstimates.lastOrNull()
@@ -409,4 +416,4 @@ class MapTemplate(
409
416
  }
410
417
  }
411
418
  }
412
- }
419
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iternio/react-native-auto-play",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",