@sbaiahmed1/react-native-blur 4.5.5-beta.0 → 4.5.5-beta.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.
@@ -36,6 +36,7 @@ class ReactNativeBlurView : BlurViewGroup {
36
36
  private var viewType: String = "blur"
37
37
  private var glassType: String = "clear"
38
38
  private var isBlurInitialized: Boolean = false
39
+ private var initRunnable: Runnable? = null
39
40
 
40
41
  companion object {
41
42
  private const val TAG = "ReactNativeBlurView"
@@ -103,11 +104,17 @@ class ReactNativeBlurView : BlurViewGroup {
103
104
  override fun onAttachedToWindow() {
104
105
  super.onAttachedToWindow()
105
106
 
107
+ if (isBlurInitialized) return
108
+
106
109
  // Defer the blur root swap to next frame so the view tree is fully mounted
107
- post {
110
+ val runnable = Runnable {
111
+ initRunnable = null
112
+ if (isBlurInitialized) return@Runnable
108
113
  swapBlurRootToScreenAncestor()
109
114
  initializeBlur()
110
115
  }
116
+ initRunnable = runnable
117
+ post(runnable)
111
118
  }
112
119
 
113
120
  /**
@@ -118,6 +125,7 @@ class ReactNativeBlurView : BlurViewGroup {
118
125
  * Also moves the OnPreDrawListener from the old root to the new one.
119
126
  */
120
127
  private fun swapBlurRootToScreenAncestor() {
128
+ // Pinned to QmBlurView 1.1.4 – depends on: mBaseBlurViewGroup, mDecorView, preDrawListener, mDifferentRoot, mForceRedraw
121
129
  val newRoot = findOptimalBlurRoot() ?: return
122
130
 
123
131
  try {
@@ -138,6 +146,13 @@ class ReactNativeBlurView : BlurViewGroup {
138
146
  preDrawListenerField.isAccessible = true
139
147
  val preDrawListener = preDrawListenerField.get(baseBlurViewGroup) as? ViewTreeObserver.OnPreDrawListener
140
148
 
149
+ if (oldDecorView == null) {
150
+ logWarning("swapBlurRootToScreenAncestor: oldDecorView is null, skipping swap – falling back to decor view")
151
+ }
152
+ if (preDrawListener == null) {
153
+ logWarning("swapBlurRootToScreenAncestor: preDrawListener is null, skipping swap – falling back to decor view")
154
+ }
155
+
141
156
  if (preDrawListener != null && oldDecorView != null) {
142
157
  // Step 3: Remove listener from old root's ViewTreeObserver
143
158
  try {
@@ -210,8 +225,11 @@ class ReactNativeBlurView : BlurViewGroup {
210
225
  /**
211
226
  * Initialize the blur view with current settings.
212
227
  * Called after the view is attached and the blur root has been swapped.
228
+ * Guarded by isBlurInitialized to prevent duplicate setup.
213
229
  */
214
230
  private fun initializeBlur() {
231
+ if (isBlurInitialized) return
232
+
215
233
  try {
216
234
  super.setBlurRadius(currentBlurRadius)
217
235
  super.setOverlayColor(currentOverlayColor)
@@ -240,7 +258,8 @@ class ReactNativeBlurView : BlurViewGroup {
240
258
  */
241
259
  fun cleanup() {
242
260
  isBlurInitialized = false
243
- removeCallbacks(null)
261
+ initRunnable?.let { removeCallbacks(it) }
262
+ initRunnable = null
244
263
  logDebug("View cleaned up")
245
264
  }
246
265
 
@@ -35,6 +35,8 @@ class ReactNativeProgressiveBlurView : FrameLayout {
35
35
  private var currentStartOffset = 0.0f
36
36
  private var hasExplicitBackground: Boolean = false
37
37
  private var isBlurInitialized: Boolean = false
38
+ private var initRunnable: Runnable? = null
39
+ private var swapRootRunnable: Runnable? = null
38
40
 
39
41
  companion object {
40
42
  private const val TAG = "ReactNativeProgressiveBlur"
@@ -102,9 +104,12 @@ class ReactNativeProgressiveBlurView : FrameLayout {
102
104
  super.onAttachedToWindow()
103
105
 
104
106
  if (!isBlurInitialized) {
105
- post {
107
+ val runnable = Runnable {
108
+ initRunnable = null
106
109
  initializeBlurChild()
107
110
  }
111
+ initRunnable = runnable
112
+ post(runnable)
108
113
  }
109
114
  }
110
115
 
@@ -132,9 +137,12 @@ class ReactNativeProgressiveBlurView : FrameLayout {
132
137
  }
133
138
 
134
139
  // Swap blur root after BlurView is attached (deferred to let it attach first)
135
- blurView?.post {
140
+ val swapRunnable = Runnable {
141
+ swapRootRunnable = null
136
142
  swapBlurRootToScreenAncestor()
137
143
  }
144
+ swapRootRunnable = swapRunnable
145
+ blurView?.post(swapRunnable)
138
146
 
139
147
  isBlurInitialized = true
140
148
  logDebug("Initialized progressive blur with blur + gradient approach")
@@ -365,7 +373,12 @@ class ReactNativeProgressiveBlurView : FrameLayout {
365
373
  fun cleanup() {
366
374
  hasExplicitBackground = false
367
375
  isBlurInitialized = false
368
- removeCallbacks(null)
376
+ initRunnable?.let { removeCallbacks(it) }
377
+ initRunnable = null
378
+ swapRootRunnable?.let { runnable ->
379
+ blurView?.removeCallbacks(runnable)
380
+ }
381
+ swapRootRunnable = null
369
382
  logDebug("View cleaned up")
370
383
  }
371
384
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sbaiahmed1/react-native-blur",
3
- "version": "4.5.5-beta.0",
3
+ "version": "4.5.5-beta.2",
4
4
  "description": "React native modern blur view",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",