@iternio/react-native-auto-play 0.1.13 → 0.1.15
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
|
|
package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/VirtualRenderer.kt
CHANGED
|
@@ -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
|
|
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,18 @@ class VirtualRenderer(
|
|
|
78
86
|
ReactContextResolver.getReactContext(context.applicationContext as ReactApplication)
|
|
79
87
|
|
|
80
88
|
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
|
|
81
|
-
|
|
89
|
+
fabricUiManager = UIManagerHelper.getUIManager(
|
|
82
90
|
reactContext, UIManagerType.FABRIC
|
|
83
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
|
|
84
101
|
}
|
|
85
102
|
|
|
86
103
|
initRenderer()
|
|
@@ -287,6 +304,11 @@ class VirtualRenderer(
|
|
|
287
304
|
context, display, height, width, initialProperties, reactNativeScale
|
|
288
305
|
).show()
|
|
289
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
|
+
}
|
|
290
312
|
MapPresentation(
|
|
291
313
|
context, display, height, width, initialProperties, reactNativeScale
|
|
292
314
|
).show()
|
|
@@ -312,7 +334,10 @@ class VirtualRenderer(
|
|
|
312
334
|
|
|
313
335
|
val instanceManager =
|
|
314
336
|
(context.applicationContext as ReactApplication).reactNativeHost.reactInstanceManager
|
|
315
|
-
|
|
337
|
+
// Wrap applicationContext with app theme to support AppCompat widgets like ReactTextView
|
|
338
|
+
val appTheme = context.applicationContext.applicationInfo.theme
|
|
339
|
+
val themedContext = ContextThemeWrapper(context.applicationContext, appTheme)
|
|
340
|
+
reactRootView = ReactRootView(themedContext).apply {
|
|
316
341
|
layoutParams = FrameLayout.LayoutParams(
|
|
317
342
|
(this@MapPresentation.width / reactNativeScale).toInt(),
|
|
318
343
|
(this@MapPresentation.height / reactNativeScale).toInt()
|
|
@@ -387,7 +412,7 @@ class VirtualRenderer(
|
|
|
387
412
|
}
|
|
388
413
|
}
|
|
389
414
|
|
|
390
|
-
reactSurfaceId =
|
|
415
|
+
reactSurfaceId = fabricUiManager.startSurface(
|
|
391
416
|
reactSurfaceView,
|
|
392
417
|
moduleName,
|
|
393
418
|
Arguments.fromBundle(initialProperties),
|
|
@@ -400,9 +425,9 @@ class VirtualRenderer(
|
|
|
400
425
|
)
|
|
401
426
|
|
|
402
427
|
// remove ui-managers lifecycle listener to not stop rendering when app is not in foreground/phone screen is off
|
|
403
|
-
reactContext.removeLifecycleEventListener(
|
|
428
|
+
reactContext.removeLifecycleEventListener(fabricUiManager)
|
|
404
429
|
// trigger ui-managers onHostResume to make sure the surface is rendered properly even when AA only is starting without the phone app
|
|
405
|
-
|
|
430
|
+
fabricUiManager.onHostResume()
|
|
406
431
|
} else {
|
|
407
432
|
(reactSurfaceView.parent as ViewGroup).removeView(reactSurfaceView)
|
|
408
433
|
}
|
|
@@ -479,7 +504,7 @@ class VirtualRenderer(
|
|
|
479
504
|
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
|
|
480
505
|
if (renderer?.isUiManagerInitialized() == true) {
|
|
481
506
|
renderer.reactSurfaceId?.let {
|
|
482
|
-
renderer.
|
|
507
|
+
renderer.fabricUiManager.stopSurface(it)
|
|
483
508
|
}
|
|
484
509
|
}
|
|
485
510
|
} else {
|
|
@@ -491,4 +516,4 @@ class VirtualRenderer(
|
|
|
491
516
|
virtualRenderer.remove(moduleId)
|
|
492
517
|
}
|
|
493
518
|
}
|
|
494
|
-
}
|
|
519
|
+
}
|