@iternio/react-native-auto-play 0.2.3 → 0.3.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.
- package/README.md +1 -1
- package/ReactNativeAutoPlay.podspec +1 -0
- package/android/build.gradle +0 -1
- package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/VirtualRenderer.kt +32 -125
- package/ios/ReactHelpers/NitroSurface.m +6 -20
- package/ios/templates/MapTemplate.swift +2 -2
- package/ios/templates/Parser.swift +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -880,7 +880,7 @@ CarPlayDashboard.setButtons([
|
|
|
880
880
|
|
|
881
881
|
### iOS
|
|
882
882
|
|
|
883
|
-
- **Broken exceptions with `react-native-skia`**: When using `react-native-skia`
|
|
883
|
+
- **Broken exceptions with `react-native-skia`**: When using `react-native-skia` exceptions on iOS are not reported correctly. This is fixed since version `2.4.19` of `react-native-skia`. For more details, see this [pull request](https://github.com/Shopify/react-native-skia/pull/3595) and [issue](https://github.com/Shopify/react-native-skia/issues/3635).
|
|
884
884
|
- **AppState on iOS**: The `AppState` module from React Native does not work correctly on iOS because this library uses scenes, which are not supported by the stock `AppState` module. This library provides a custom state listener that works for both Android and iOS. Use `HybridAutoPlay.addListenerRenderState` instead of `AppState`.
|
|
885
885
|
- **Timers stop on screen lock**: iOS stops all timers when the device's main screen is turned off. To ensure timers continue to run (which is often necessary for background tasks related to autoplay), a patch for `react-native` is required. A patch is included in the root `patches/` directory and can be applied using `patch-package`.
|
|
886
886
|
- **expo-splash-screen stuck on iOS**: The `expo-splash-screen` module is broken on iOS because it does not support scenes, which are used by this library. This can cause the splash screen to be stuck on either the mobile device or on CarPlay. To fix this, a patch for `expo-splash-screen` is included in the root `patches/` directory and can be applied using `patch-package`. After applying the patch, you can hide the splash screen for a specific scene by passing the module name to the `hide` or `hideAsync` function. The module name can be one of the values from the `AutoPlayModules` enum or the UUID of a cluster screen.
|
package/android/build.gradle
CHANGED
|
@@ -44,7 +44,6 @@ android {
|
|
|
44
44
|
defaultConfig {
|
|
45
45
|
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
46
46
|
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
47
|
-
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
48
47
|
|
|
49
48
|
externalNativeBuild {
|
|
50
49
|
cmake {
|
package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/VirtualRenderer.kt
CHANGED
|
@@ -20,10 +20,8 @@ import androidx.car.app.CarContext
|
|
|
20
20
|
import androidx.car.app.SurfaceCallback
|
|
21
21
|
import androidx.car.app.SurfaceContainer
|
|
22
22
|
import com.facebook.react.ReactApplication
|
|
23
|
-
import com.facebook.react.ReactRootView
|
|
24
23
|
import com.facebook.react.bridge.Arguments
|
|
25
24
|
import com.facebook.react.bridge.ReactContext
|
|
26
|
-
import com.facebook.react.bridge.UIManager
|
|
27
25
|
import com.facebook.react.fabric.FabricUIManager
|
|
28
26
|
import com.facebook.react.runtime.ReactSurfaceImpl
|
|
29
27
|
import com.facebook.react.runtime.ReactSurfaceView
|
|
@@ -45,28 +43,18 @@ class VirtualRenderer(
|
|
|
45
43
|
private val isCluster: Boolean = false
|
|
46
44
|
) {
|
|
47
45
|
private lateinit var fabricUiManager: FabricUIManager
|
|
48
|
-
private lateinit var uiManager: UIManager
|
|
49
46
|
|
|
50
47
|
private fun isUiManagerInitialized(): Boolean {
|
|
51
|
-
|
|
52
|
-
return ::fabricUiManager.isInitialized
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return ::uiManager.isInitialized
|
|
48
|
+
return ::fabricUiManager.isInitialized
|
|
56
49
|
}
|
|
57
50
|
|
|
58
51
|
private lateinit var display: Display
|
|
59
52
|
private lateinit var reactContext: ReactContext
|
|
60
53
|
|
|
61
54
|
private lateinit var reactSurfaceImpl: ReactSurfaceImpl
|
|
62
|
-
private
|
|
55
|
+
private var reactSurfaceView: ReactSurfaceView? = null
|
|
63
56
|
private var reactSurfaceId: Int? = null
|
|
64
57
|
|
|
65
|
-
private lateinit var reactRootView: ReactRootView
|
|
66
|
-
private fun isReactRootViewInitialized(): Boolean {
|
|
67
|
-
return ::reactRootView.isInitialized
|
|
68
|
-
}
|
|
69
|
-
|
|
70
58
|
private var height: Int = 0
|
|
71
59
|
private var width: Int = 0
|
|
72
60
|
|
|
@@ -85,20 +73,9 @@ class VirtualRenderer(
|
|
|
85
73
|
reactContext =
|
|
86
74
|
ReactContextResolver.getReactContext(context.applicationContext as ReactApplication)
|
|
87
75
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
) as FabricUIManager
|
|
92
|
-
} else {
|
|
93
|
-
// UIManagerType.DEFAULT was deprecated and will eventually be removed, but LEGACY is not available in lower RN versions.
|
|
94
|
-
// So make sure both work to be backwards compatible
|
|
95
|
-
val legacyType = try {
|
|
96
|
-
UIManagerType::class.java.getField("LEGACY").getInt(null)
|
|
97
|
-
} catch (e: NoSuchFieldException) {
|
|
98
|
-
UIManagerType.DEFAULT
|
|
99
|
-
}
|
|
100
|
-
uiManager = UIManagerHelper.getUIManager(reactContext, legacyType) as UIManager
|
|
101
|
-
}
|
|
76
|
+
fabricUiManager = UIManagerHelper.getUIManager(
|
|
77
|
+
reactContext, UIManagerType.FABRIC
|
|
78
|
+
) as FabricUIManager
|
|
102
79
|
|
|
103
80
|
initRenderer()
|
|
104
81
|
}
|
|
@@ -216,7 +193,7 @@ class VirtualRenderer(
|
|
|
216
193
|
val additionalMarginRight =
|
|
217
194
|
if (stableArea.right == visibleArea.right && visibleArea.right != width) 0 else defaultMargin
|
|
218
195
|
val additionalMarginTop =
|
|
219
|
-
if (visibleArea.top != stableArea.top || (visibleArea.top > 0 &&
|
|
196
|
+
if (visibleArea.top != stableArea.top || (visibleArea.top > 0 && visibleArea.right < width)) 0 else defaultMargin
|
|
220
197
|
val additionalMarginBottom =
|
|
221
198
|
if (stableArea.bottom == visibleArea.bottom) defaultMargin else 0
|
|
222
199
|
|
|
@@ -293,89 +270,15 @@ class VirtualRenderer(
|
|
|
293
270
|
val mainScreenDensity = DisplayMetricsHolder.getScreenDisplayMetrics().density
|
|
294
271
|
val reactNativeScale = virtualScreenDensity / mainScreenDensity * BuildConfig.SCALE_FACTOR
|
|
295
272
|
|
|
296
|
-
if (
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
return
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
FabricMapPresentation(
|
|
304
|
-
context, display, height, width, initialProperties, reactNativeScale
|
|
305
|
-
).show()
|
|
306
|
-
} else {
|
|
307
|
-
if (!isUiManagerInitialized()) {
|
|
308
|
-
// this makes sure we have all required instances
|
|
309
|
-
// no matter if the app is launched on the phone or AA first
|
|
310
|
-
return
|
|
311
|
-
}
|
|
312
|
-
MapPresentation(
|
|
313
|
-
context, display, height, width, initialProperties, reactNativeScale
|
|
314
|
-
).show()
|
|
273
|
+
if (!isUiManagerInitialized()) {
|
|
274
|
+
// this makes sure we have all required instances
|
|
275
|
+
// no matter if the app is launched on the phone or AA first
|
|
276
|
+
return
|
|
315
277
|
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
inner class MapPresentation(
|
|
319
|
-
private val context: CarContext,
|
|
320
|
-
display: Display,
|
|
321
|
-
private val height: Int,
|
|
322
|
-
private val width: Int,
|
|
323
|
-
private val initialProperties: Bundle,
|
|
324
|
-
private val reactNativeScale: Float,
|
|
325
|
-
) : Presentation(context, display) {
|
|
326
|
-
override fun onCreate(savedInstanceState: Bundle?) {
|
|
327
|
-
super.onCreate(savedInstanceState)
|
|
328
|
-
|
|
329
|
-
var splashScreenView: View? = null
|
|
330
|
-
|
|
331
|
-
// Wrap applicationContext with app theme to support AppCompat widgets like ReactTextView
|
|
332
|
-
val appTheme = context.applicationContext.applicationInfo.theme
|
|
333
|
-
val themedContext = ContextThemeWrapper(context.applicationContext, appTheme)
|
|
334
|
-
|
|
335
|
-
if (!isReactRootViewInitialized()) {
|
|
336
|
-
splashScreenView =
|
|
337
|
-
if (isCluster) getClusterSplashScreen(themedContext, height, width) else null
|
|
338
|
-
|
|
339
|
-
val instanceManager =
|
|
340
|
-
(themedContext.applicationContext as ReactApplication).reactNativeHost.reactInstanceManager
|
|
341
|
-
|
|
342
|
-
reactRootView = ReactRootView(themedContext).apply {
|
|
343
|
-
layoutParams = FrameLayout.LayoutParams(
|
|
344
|
-
(this@MapPresentation.width / reactNativeScale).toInt(),
|
|
345
|
-
(this@MapPresentation.height / reactNativeScale).toInt()
|
|
346
|
-
)
|
|
347
|
-
scaleX = reactNativeScale
|
|
348
|
-
scaleY = reactNativeScale
|
|
349
|
-
pivotX = 0f
|
|
350
|
-
pivotY = 0f
|
|
351
|
-
setBackgroundColor(Color.DKGRAY)
|
|
352
|
-
|
|
353
|
-
splashScreenView?.let {
|
|
354
|
-
removeClusterSplashScreen({ viewTreeObserver }, it)
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
startReactApplication(instanceManager, moduleName, initialProperties)
|
|
358
|
-
runApplication()
|
|
359
|
-
}
|
|
360
|
-
} else {
|
|
361
|
-
(reactRootView.parent as? ViewGroup)?.removeView(reactRootView)
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
val rootContainer = FrameLayout(themedContext).apply {
|
|
365
|
-
layoutParams = FrameLayout.LayoutParams(
|
|
366
|
-
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT
|
|
367
|
-
)
|
|
368
|
-
clipChildren = false
|
|
369
|
-
|
|
370
|
-
addView(reactRootView)
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
splashScreenView?.let {
|
|
374
|
-
rootContainer.addView(it)
|
|
375
|
-
}
|
|
376
278
|
|
|
377
|
-
|
|
378
|
-
|
|
279
|
+
FabricMapPresentation(
|
|
280
|
+
context, display, height, width, initialProperties, reactNativeScale
|
|
281
|
+
).show()
|
|
379
282
|
}
|
|
380
283
|
|
|
381
284
|
inner class FabricMapPresentation(
|
|
@@ -398,11 +301,13 @@ class VirtualRenderer(
|
|
|
398
301
|
|
|
399
302
|
var splashScreenView: View? = null
|
|
400
303
|
|
|
401
|
-
|
|
304
|
+
reactSurfaceView?.let {
|
|
305
|
+
(it.parent as ViewGroup).removeView(it)
|
|
306
|
+
} ?: run {
|
|
402
307
|
splashScreenView =
|
|
403
308
|
if (isCluster) getClusterSplashScreen(themedContext, height, width) else null
|
|
404
309
|
|
|
405
|
-
|
|
310
|
+
val surfaceView = ReactSurfaceView(themedContext, reactSurfaceImpl).apply {
|
|
406
311
|
layoutParams = FrameLayout.LayoutParams(
|
|
407
312
|
(width / reactNativeScale).toInt(), (height / reactNativeScale).toInt()
|
|
408
313
|
)
|
|
@@ -418,7 +323,7 @@ class VirtualRenderer(
|
|
|
418
323
|
}
|
|
419
324
|
|
|
420
325
|
reactSurfaceId = fabricUiManager.startSurface(
|
|
421
|
-
|
|
326
|
+
surfaceView,
|
|
422
327
|
moduleName,
|
|
423
328
|
Arguments.fromBundle(initialProperties),
|
|
424
329
|
View.MeasureSpec.makeMeasureSpec(
|
|
@@ -433,10 +338,11 @@ class VirtualRenderer(
|
|
|
433
338
|
reactContext.removeLifecycleEventListener(fabricUiManager)
|
|
434
339
|
// trigger ui-managers onHostResume to make sure the surface is rendered properly even when AA only is starting without the phone app
|
|
435
340
|
fabricUiManager.onHostResume()
|
|
436
|
-
|
|
437
|
-
|
|
341
|
+
|
|
342
|
+
reactSurfaceView = surfaceView
|
|
438
343
|
}
|
|
439
344
|
|
|
345
|
+
|
|
440
346
|
val rootContainer = FrameLayout(themedContext).apply {
|
|
441
347
|
layoutParams = FrameLayout.LayoutParams(
|
|
442
348
|
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT
|
|
@@ -457,8 +363,15 @@ class VirtualRenderer(
|
|
|
457
363
|
private fun getClusterSplashScreen(
|
|
458
364
|
context: Context, containerHeight: Int, containerWidth: Int
|
|
459
365
|
): View {
|
|
366
|
+
val root = FrameLayout(context).apply {
|
|
367
|
+
layoutParams = ViewGroup.LayoutParams(
|
|
368
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
369
|
+
ViewGroup.LayoutParams.MATCH_PARENT
|
|
370
|
+
)
|
|
371
|
+
}
|
|
372
|
+
|
|
460
373
|
val layout =
|
|
461
|
-
LayoutInflater.from(context).inflate(R.layout.cluster_splashscreen,
|
|
374
|
+
LayoutInflater.from(context).inflate(R.layout.cluster_splashscreen, root, false)
|
|
462
375
|
val text = layout.findViewById<TextView>(R.id.splash_text)
|
|
463
376
|
|
|
464
377
|
AppInfo.getApplicationIcon(context)?.let {
|
|
@@ -506,15 +419,9 @@ class VirtualRenderer(
|
|
|
506
419
|
fun removeRenderer(moduleId: String) {
|
|
507
420
|
val renderer = virtualRenderer[moduleId]
|
|
508
421
|
|
|
509
|
-
if (
|
|
510
|
-
|
|
511
|
-
renderer.
|
|
512
|
-
renderer.fabricUiManager.stopSurface(it)
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
} else {
|
|
516
|
-
if (renderer?.isReactRootViewInitialized() == true) {
|
|
517
|
-
renderer.reactRootView.unmountReactApplication()
|
|
422
|
+
if (renderer?.isUiManagerInitialized() == true) {
|
|
423
|
+
renderer.reactSurfaceId?.let {
|
|
424
|
+
renderer.fabricUiManager.stopSurface(it)
|
|
518
425
|
}
|
|
519
426
|
}
|
|
520
427
|
|
|
@@ -19,32 +19,18 @@
|
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
if ([view isKindOfClass:[
|
|
22
|
+
if ([view isKindOfClass:[RCTSurfaceHostingView class]]) {
|
|
23
23
|
RCTSurfaceHostingProxyRootView *rootView =
|
|
24
24
|
(RCTSurfaceHostingProxyRootView *)view;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
NSLog(@"[AutoPlay] surface == nil, cannot stop");
|
|
25
|
+
|
|
26
|
+
if (rootView == nil) {
|
|
27
|
+
NSLog(@"[AutoPlay] rootView == nil, cannot stop");
|
|
29
28
|
return;
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
[surface stop];
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if ([view isKindOfClass:[RCTRootView class]]) {
|
|
37
|
-
RCTRootView *rootView = (RCTRootView *)view;
|
|
38
|
-
UIView<RCTInvalidating> *contentView = (UIView<RCTInvalidating> *)rootView.contentView;
|
|
39
30
|
|
|
40
|
-
|
|
41
|
-
[contentView invalidate];
|
|
42
|
-
} else {
|
|
43
|
-
NSLog(@"[AutoPlay] contentView does not conform to RCTInvalidating");
|
|
44
|
-
}
|
|
45
|
-
return;
|
|
31
|
+
[rootView.surface stop];
|
|
46
32
|
}
|
|
47
|
-
|
|
33
|
+
|
|
48
34
|
NSLog(@"[AutoPlay] View is not recognized type, ignoring");
|
|
49
35
|
}
|
|
50
36
|
|
|
@@ -597,7 +597,7 @@ class MapTemplate: AutoPlayHeaderProviding,
|
|
|
597
597
|
|
|
598
598
|
if var userInfo = route.userInfo as? [String: Any?] {
|
|
599
599
|
userInfo["travelEstimates"] = steps.map { step in
|
|
600
|
-
Parser.
|
|
600
|
+
Parser.parseTravelEstimates(
|
|
601
601
|
travelEstimates: step.travelEstimates
|
|
602
602
|
)
|
|
603
603
|
}
|
|
@@ -675,7 +675,7 @@ class MapTemplate: AutoPlayHeaderProviding,
|
|
|
675
675
|
.firstIndex(where: { $0.id == nitroManeuver.id })
|
|
676
676
|
{
|
|
677
677
|
navigationSession.updateEstimates(
|
|
678
|
-
Parser.
|
|
678
|
+
Parser.parseTravelEstimates(
|
|
679
679
|
travelEstimates: nitroManeuver.travelEstimates
|
|
680
680
|
),
|
|
681
681
|
for: navigationSession.upcomingManeuvers[maneuverIndex]
|
|
@@ -452,7 +452,7 @@ class Parser {
|
|
|
452
452
|
id: routeChoice.id,
|
|
453
453
|
// we don't want to keep the origin travel estimate
|
|
454
454
|
travelEstimates: routeChoice.steps[1...].map { step in
|
|
455
|
-
|
|
455
|
+
parseTravelEstimates(travelEstimates: step.travelEstimates)
|
|
456
456
|
}
|
|
457
457
|
)
|
|
458
458
|
|
|
@@ -492,7 +492,7 @@ class Parser {
|
|
|
492
492
|
}
|
|
493
493
|
}
|
|
494
494
|
|
|
495
|
-
static func
|
|
495
|
+
static func parseTravelEstimates(travelEstimates: TravelEstimates)
|
|
496
496
|
-> CPTravelEstimates
|
|
497
497
|
{
|
|
498
498
|
return CPTravelEstimates(
|
|
@@ -515,7 +515,7 @@ class Parser {
|
|
|
515
515
|
traitCollection: traitCollection
|
|
516
516
|
)
|
|
517
517
|
|
|
518
|
-
maneuver.initialTravelEstimates = Parser.
|
|
518
|
+
maneuver.initialTravelEstimates = Parser.parseTravelEstimates(
|
|
519
519
|
travelEstimates: nitroManeuver.travelEstimates
|
|
520
520
|
)
|
|
521
521
|
maneuver.symbolImage = Parser.parseNitroImage(
|