@granite-js/screen 2.5.0 → 2.5.2
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/CHANGELOG.md +8 -0
- package/android/src/main/kotlin/run/granite/GraniteReactDelegate.kt +9 -0
- package/android/src/main/kotlin/run/granite/GraniteReactDelegateImpl.kt +12 -1
- package/android/src/main/kotlin/run/granite/GraniteReactHost.kt +13 -0
- package/android/src/main/kotlin/run/granite/ReactHostFactory.kt +8 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -30,6 +30,15 @@ interface GraniteReactDelegate {
|
|
|
30
30
|
|
|
31
31
|
fun setBundleLoaderProvider(provider: () -> BundleLoader)
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Set a handler that will be called when React Native internals throw an exception.
|
|
35
|
+
* Optional - the exception is always logged to logcat first, and this handler runs after that.
|
|
36
|
+
* Must be set before onCreate(), because the handler is bound when the ReactHost is created.
|
|
37
|
+
* GraniteReactHost users should override handleInstanceException() instead, because
|
|
38
|
+
* setupHost() sets this handler.
|
|
39
|
+
*/
|
|
40
|
+
fun setExceptionHandler(handler: (Exception) -> Unit)
|
|
41
|
+
|
|
33
42
|
// View creation methods - optional customization
|
|
34
43
|
fun setLoadingViewProvider(provider: (AppCompatActivity) -> View)
|
|
35
44
|
|
|
@@ -54,6 +54,7 @@ class GraniteReactDelegateImpl : GraniteReactDelegate {
|
|
|
54
54
|
private var loadingViewProvider: ((AppCompatActivity) -> View)? = null
|
|
55
55
|
private var errorViewProvider: ((AppCompatActivity, Throwable) -> View)? = null
|
|
56
56
|
private var reactContainerProvider: ((AppCompatActivity) -> android.view.ViewGroup?)? = null
|
|
57
|
+
private var exceptionHandler: ((Exception) -> Unit)? = null
|
|
57
58
|
|
|
58
59
|
// Consumer functions - for advanced view control
|
|
59
60
|
private var loadingViewConsumer: (() -> Unit)? = null
|
|
@@ -172,6 +173,7 @@ class GraniteReactDelegateImpl : GraniteReactDelegate {
|
|
|
172
173
|
loadingViewProvider = null
|
|
173
174
|
errorViewProvider = null
|
|
174
175
|
reactContainerProvider = null
|
|
176
|
+
exceptionHandler = null
|
|
175
177
|
loadingViewConsumer = null
|
|
176
178
|
surfaceViewConsumer = null
|
|
177
179
|
errorViewConsumer = null
|
|
@@ -185,6 +187,10 @@ class GraniteReactDelegateImpl : GraniteReactDelegate {
|
|
|
185
187
|
this.bundleLoaderProvider = provider
|
|
186
188
|
}
|
|
187
189
|
|
|
190
|
+
override fun setExceptionHandler(handler: (Exception) -> Unit) {
|
|
191
|
+
this.exceptionHandler = handler
|
|
192
|
+
}
|
|
193
|
+
|
|
188
194
|
override fun setLoadingViewProvider(provider: (AppCompatActivity) -> View) {
|
|
189
195
|
this.loadingViewProvider = provider
|
|
190
196
|
}
|
|
@@ -438,7 +444,12 @@ class GraniteReactDelegateImpl : GraniteReactDelegate {
|
|
|
438
444
|
bundleSource: BundleSource,
|
|
439
445
|
): ReactHostFactory.Result {
|
|
440
446
|
val packages = reactPackagesProvider?.invoke() ?: emptyList()
|
|
441
|
-
return ReactHostFactory.create(
|
|
447
|
+
return ReactHostFactory.create(
|
|
448
|
+
activity.applicationContext,
|
|
449
|
+
bundleSource,
|
|
450
|
+
packages,
|
|
451
|
+
exceptionHandler,
|
|
452
|
+
)
|
|
442
453
|
}
|
|
443
454
|
|
|
444
455
|
companion object {
|
|
@@ -43,6 +43,7 @@ interface GraniteReactHost {
|
|
|
43
43
|
graniteDelegate.setBundleLoaderProvider { createBundleLoader() }
|
|
44
44
|
graniteDelegate.setLoadingViewProvider { activity -> createLoadingView() }
|
|
45
45
|
graniteDelegate.setErrorViewProvider { activity, error -> createErrorView(error) }
|
|
46
|
+
graniteDelegate.setExceptionHandler { error -> handleInstanceException(error) }
|
|
46
47
|
|
|
47
48
|
// Initialize
|
|
48
49
|
graniteDelegate.onCreate(this, savedInstanceState, initialProps)
|
|
@@ -100,6 +101,18 @@ interface GraniteReactHost {
|
|
|
100
101
|
// Override in your activity to register modules or perform other initialization
|
|
101
102
|
}
|
|
102
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Called when React Native internals throw an exception. Override this method to add custom
|
|
106
|
+
* handling such as reporting the exception to your own crash reporting tool. Granite always
|
|
107
|
+
* logs the exception to logcat before calling this method.
|
|
108
|
+
*
|
|
109
|
+
* @param error The exception thrown by React Native internals
|
|
110
|
+
*/
|
|
111
|
+
fun handleInstanceException(error: Exception) {
|
|
112
|
+
// Default implementation does nothing
|
|
113
|
+
// Override in your activity to report the exception or perform other custom handling
|
|
114
|
+
}
|
|
115
|
+
|
|
103
116
|
// Convenience accessors
|
|
104
117
|
|
|
105
118
|
/** Get the current bundle loader if any. */
|
|
@@ -33,6 +33,7 @@ internal object ReactHostFactory {
|
|
|
33
33
|
applicationContext: Context,
|
|
34
34
|
bundleSource: BundleSource,
|
|
35
35
|
packages: List<ReactPackage>,
|
|
36
|
+
exceptionHandler: ((Exception) -> Unit)? = null,
|
|
36
37
|
): Result {
|
|
37
38
|
Log.d(TAG, "Creating ReactHost with bundle source: $bundleSource")
|
|
38
39
|
|
|
@@ -42,6 +43,12 @@ internal object ReactHostFactory {
|
|
|
42
43
|
|
|
43
44
|
val tmmDelegateBuilder = DefaultTurboModuleManagerDelegate.Builder()
|
|
44
45
|
|
|
46
|
+
// Always log the exception, then hand it to the app for custom handling (crash reporting, etc.)
|
|
47
|
+
val instanceExceptionHandler: (Exception) -> Unit = { ex ->
|
|
48
|
+
Log.e(TAG, "ReactHost exception", ex)
|
|
49
|
+
exceptionHandler?.invoke(ex)
|
|
50
|
+
}
|
|
51
|
+
|
|
45
52
|
val reactHostDelegate =
|
|
46
53
|
DefaultReactHostDelegate(
|
|
47
54
|
jsMainModulePath = DEFAULT_JS_MAIN_MODULE,
|
|
@@ -50,9 +57,7 @@ internal object ReactHostFactory {
|
|
|
50
57
|
jsRuntimeFactory = HermesInstance(),
|
|
51
58
|
bindingsInstaller = null,
|
|
52
59
|
turboModuleManagerDelegateBuilder = tmmDelegateBuilder,
|
|
53
|
-
exceptionHandler =
|
|
54
|
-
Log.e(TAG, "ReactHost exception", ex)
|
|
55
|
-
},
|
|
60
|
+
exceptionHandler = instanceExceptionHandler,
|
|
56
61
|
)
|
|
57
62
|
|
|
58
63
|
val newComponentFactory = ComponentFactory()
|