@sbaiahmed1/react-native-blur 4.5.5-beta.2 → 4.5.5-beta.3

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.
@@ -1,6 +1,8 @@
1
1
  package com.sbaiahmed1.reactnativeblur
2
2
 
3
+ import android.app.Activity
3
4
  import android.content.Context
5
+ import android.content.ContextWrapper
4
6
  import android.graphics.Canvas
5
7
  import android.graphics.Color
6
8
  import android.graphics.LinearGradient
@@ -14,6 +16,7 @@ import android.view.View
14
16
  import android.view.ViewGroup
15
17
  import android.widget.FrameLayout
16
18
  import android.view.View.MeasureSpec
19
+ import com.facebook.react.bridge.ReactContext
17
20
  import com.qmdeve.blurview.widget.BlurView
18
21
  import kotlin.math.max
19
22
 
@@ -215,10 +218,11 @@ class ReactNativeProgressiveBlurView : FrameLayout {
215
218
 
216
219
  /**
217
220
  * Falls back to android.R.id.content or the activity root view.
221
+ * Tries ReactContext.currentActivity first, then unwraps ContextWrapper chain.
218
222
  */
219
223
  private fun getContentViewFallback(): ViewGroup? {
220
224
  try {
221
- val activity = context as? android.app.Activity
225
+ val activity = getActivityFromContext()
222
226
  activity?.findViewById<ViewGroup>(android.R.id.content)?.let { return it }
223
227
  } catch (e: Exception) {
224
228
  logDebug("Could not access activity content view: ${e.message}")
@@ -226,6 +230,23 @@ class ReactNativeProgressiveBlurView : FrameLayout {
226
230
  return this.parent as? ViewGroup
227
231
  }
228
232
 
233
+ /**
234
+ * Resolves an Activity from the view's context.
235
+ * Priority: ReactContext.currentActivity > ContextWrapper unwrap chain.
236
+ */
237
+ private fun getActivityFromContext(): Activity? {
238
+ // Try ReactContext first (most common in React Native)
239
+ (context as? ReactContext)?.currentActivity?.let { return it }
240
+
241
+ // Unwrap ContextWrapper chain to find an Activity
242
+ var ctx: Context? = context
243
+ while (ctx != null) {
244
+ if (ctx is Activity) return ctx
245
+ ctx = (ctx as? ContextWrapper)?.baseContext
246
+ }
247
+ return null
248
+ }
249
+
229
250
  override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
230
251
  val width = MeasureSpec.getSize(widthMeasureSpec)
231
252
  val height = MeasureSpec.getSize(heightMeasureSpec)
@@ -379,6 +400,23 @@ class ReactNativeProgressiveBlurView : FrameLayout {
379
400
  blurView?.removeCallbacks(runnable)
380
401
  }
381
402
  swapRootRunnable = null
403
+
404
+ // Unregister the OnPreDrawListener from whatever root it was moved to,
405
+ // preventing callbacks into a detached BlurView and avoiding leaks.
406
+ blurView?.let { bv ->
407
+ val listener = bv.preDrawListener
408
+ val decor = bv.mDecorView
409
+ if (listener != null && decor != null) {
410
+ try {
411
+ decor.viewTreeObserver.removeOnPreDrawListener(listener)
412
+ } catch (e: Exception) {
413
+ logDebug("Could not remove pre-draw listener during cleanup: ${e.message}")
414
+ }
415
+ }
416
+ bv.mDecorView = null
417
+ bv.mDifferentRoot = false
418
+ }
419
+
382
420
  logDebug("View cleaned up")
383
421
  }
384
422
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sbaiahmed1/react-native-blur",
3
- "version": "4.5.5-beta.2",
3
+ "version": "4.5.5-beta.3",
4
4
  "description": "React native modern blur view",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",