@iternio/react-native-auto-play 0.5.12 → 0.5.13
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/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/VirtualRenderer.kt
CHANGED
|
@@ -41,6 +41,7 @@ class VirtualRenderer(
|
|
|
41
41
|
private val isCluster: Boolean = false
|
|
42
42
|
) {
|
|
43
43
|
private var virtualDisplay: VirtualDisplay? = null
|
|
44
|
+
private val pendingDisplays = mutableListOf<VirtualDisplay>()
|
|
44
45
|
|
|
45
46
|
private var reactSurfaceImpl: ReactSurfaceImpl? = null
|
|
46
47
|
private var reactSurfaceView: ReactSurfaceView? = null
|
|
@@ -92,8 +93,8 @@ class VirtualRenderer(
|
|
|
92
93
|
stableArea = Rect(0, 0, 0, 0)
|
|
93
94
|
visibleArea = Rect(0, 0, 0, 0)
|
|
94
95
|
|
|
95
|
-
virtualDisplay
|
|
96
|
-
|
|
96
|
+
// Not releasing virtualDisplay here, and not relying on this firing at all (unreliable on
|
|
97
|
+
// some Automotive devices) -- see applySurface/onDraw sweep for where the old display actually gets freed.
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
override fun onScroll(distanceX: Float, distanceY: Float) {
|
|
@@ -236,10 +237,15 @@ class VirtualRenderer(
|
|
|
236
237
|
// surface itself is kept alive so JS state survives the resize; the JS side is informed
|
|
237
238
|
// via the windowInformation listener since the window initial prop stays stale.
|
|
238
239
|
val isResize = reactSurfaceView != null && (width != surfaceWidth
|
|
239
|
-
|
|
240
|
+
|| height != surfaceHeight || dpi != surfaceContainer.dpi)
|
|
240
241
|
|
|
241
242
|
val manager = context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
|
|
242
|
-
|
|
243
|
+
|
|
244
|
+
virtualDisplay?.let {
|
|
245
|
+
// released once its replacement (created below) has drawn
|
|
246
|
+
pendingDisplays.add(it)
|
|
247
|
+
}
|
|
248
|
+
|
|
243
249
|
virtualDisplay = manager.createVirtualDisplay(
|
|
244
250
|
moduleName,
|
|
245
251
|
surfaceWidth,
|
|
@@ -415,6 +421,23 @@ class VirtualRenderer(
|
|
|
415
421
|
rootContainer.addView(it)
|
|
416
422
|
}
|
|
417
423
|
|
|
424
|
+
rootContainer.viewTreeObserver.addOnDrawListener(object :
|
|
425
|
+
ViewTreeObserver.OnDrawListener {
|
|
426
|
+
override fun onDraw() {
|
|
427
|
+
rootContainer.post {
|
|
428
|
+
rootContainer.viewTreeObserver.removeOnDrawListener(this)
|
|
429
|
+
// Releasing here, only once a new display has drawn, avoids the window-absent gap that
|
|
430
|
+
// stops Choreographer. Releasing old displays any earlier reintroduces that suspension. It
|
|
431
|
+
// freezes the map (Mapbox ValueAnimator) and RN (setInterval/setTimeout) until the phone
|
|
432
|
+
// screen is woken.
|
|
433
|
+
pendingDisplays.forEach {
|
|
434
|
+
it.release()
|
|
435
|
+
}
|
|
436
|
+
pendingDisplays.clear()
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
})
|
|
440
|
+
|
|
418
441
|
setContentView(rootContainer)
|
|
419
442
|
}
|
|
420
443
|
}
|
|
@@ -491,6 +514,13 @@ class VirtualRenderer(
|
|
|
491
514
|
virtualDisplay?.release()
|
|
492
515
|
virtualDisplay = null
|
|
493
516
|
|
|
517
|
+
pendingDisplays.forEach {
|
|
518
|
+
// make sure to release any pending displays in case
|
|
519
|
+
// the new one did not draw yet but stop is called
|
|
520
|
+
it.release()
|
|
521
|
+
}
|
|
522
|
+
pendingDisplays.clear()
|
|
523
|
+
|
|
494
524
|
try {
|
|
495
525
|
stopReactSurface()
|
|
496
526
|
} finally {
|