@granite-js/screen 2.5.6 → 2.5.8

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @granite-js/screen
2
2
 
3
+ ## 2.5.8
4
+
5
+ ## 2.5.7
6
+
7
+ ### Patch Changes
8
+
9
+ - b4c56eb: fix(android): stop the ReactHost instance exception handler from retaining destroyed screens. Override `createInstanceExceptionHandler()` to keep handling exceptions after the screen is collected.
10
+
3
11
  ## 2.5.6
4
12
 
5
13
  ## 2.5.5
@@ -34,8 +34,10 @@ interface GraniteReactDelegate {
34
34
  * Set a handler that will be called when React Native internals throw an exception.
35
35
  * Optional - the exception is always logged to logcat first, and this handler runs after that.
36
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.
37
+ * The ReactHost keeps the handler for as long as it lives, which can outlast onDestroy(), so
38
+ * the handler must not strongly reference an Activity or Fragment.
39
+ * GraniteReactHost users should override handleInstanceException() or
40
+ * createInstanceExceptionHandler() instead, because setupHost() sets this handler.
39
41
  */
40
42
  fun setExceptionHandler(handler: (Exception) -> Unit)
41
43
 
@@ -6,6 +6,7 @@ import androidx.appcompat.app.AppCompatActivity
6
6
  import com.facebook.react.ReactHost
7
7
  import com.facebook.react.ReactPackage
8
8
  import com.facebook.react.bridge.ReactContext
9
+ import java.lang.ref.WeakReference
9
10
 
10
11
  /**
11
12
  * Host interface for integrating React Native into activities. This interface allows you to "host"
@@ -43,7 +44,7 @@ interface GraniteReactHost {
43
44
  graniteDelegate.setBundleLoaderProvider { createBundleLoader() }
44
45
  graniteDelegate.setLoadingViewProvider { activity -> createLoadingView() }
45
46
  graniteDelegate.setErrorViewProvider { activity, error -> createErrorView(error) }
46
- graniteDelegate.setExceptionHandler { error -> handleInstanceException(error) }
47
+ graniteDelegate.setExceptionHandler(createInstanceExceptionHandler())
47
48
 
48
49
  // Initialize
49
50
  graniteDelegate.onCreate(this, savedInstanceState, initialProps)
@@ -104,7 +105,8 @@ interface GraniteReactHost {
104
105
  /**
105
106
  * Called when React Native internals throw an exception. Override this method to add custom
106
107
  * 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
+ * logs the exception to logcat before calling this method. This method is no longer called
109
+ * once the host has been garbage collected; see createInstanceExceptionHandler().
108
110
  *
109
111
  * @param error The exception thrown by React Native internals
110
112
  */
@@ -113,6 +115,21 @@ interface GraniteReactHost {
113
115
  // Override in your activity to report the exception or perform other custom handling
114
116
  }
115
117
 
118
+ /**
119
+ * Create the handler that receives React Native instance exceptions. setupHost() registers it,
120
+ * and the ReactHost keeps it for as long as the ReactHost lives, which can be longer than this
121
+ * host. The default implementation references this host weakly and forwards to
122
+ * handleInstanceException() while the host is still reachable.
123
+ *
124
+ * Override this method to keep handling exceptions after the host is collected. The returned
125
+ * handler must not strongly reference this host (e.g. an Activity or Fragment), or the host
126
+ * cannot be collected while the ReactHost is alive.
127
+ */
128
+ fun createInstanceExceptionHandler(): (Exception) -> Unit {
129
+ val hostRef = WeakReference(this)
130
+ return { error -> hostRef.get()?.handleInstanceException(error) }
131
+ }
132
+
116
133
  // Convenience accessors
117
134
 
118
135
  /** Get the current bundle loader if any. */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@granite-js/screen",
3
3
  "type": "module",
4
- "version": "2.5.6",
4
+ "version": "2.5.8",
5
5
  "description": "Brownfield Screen for React Native",
6
6
  "files": [
7
7
  "dist",