@sbaiahmed1/react-native-blur 4.2.0 → 4.2.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.
@@ -74,7 +74,7 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
74
74
  dependencies {
75
75
  implementation "com.facebook.react:react-android"
76
76
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
77
- implementation 'com.qmdeve:QmBlurView:1.0.5-Beta01'
77
+ implementation 'com.qmdeve.blurview:core:1.0.5'
78
78
  }
79
79
 
80
80
  react {
@@ -5,9 +5,12 @@ import android.graphics.Color
5
5
  import android.util.AttributeSet
6
6
  import android.util.Log
7
7
  import android.util.TypedValue
8
+ import android.view.ViewGroup
8
9
  import com.qmdeve.blurview.widget.BlurViewGroup
9
10
  import androidx.core.graphics.toColorInt
10
11
 
12
+ import android.view.View.MeasureSpec
13
+
11
14
  /**
12
15
  * Android implementation of React Native BlurView component.
13
16
  * Provides cross-platform blur effects using the QmBlurView library.
@@ -28,7 +31,7 @@ class ReactNativeBlurView : BlurViewGroup {
28
31
 
29
32
  companion object {
30
33
  private const val TAG = "ReactNativeBlurView"
31
- private const val MAX_BLUR_RADIUS = 25f
34
+ private const val MAX_BLUR_RADIUS = 100f
32
35
  private const val DEFAULT_BLUR_RADIUS = 10f
33
36
  private const val DEBUG = false // Set to true for debug builds
34
37
 
@@ -80,6 +83,7 @@ class ReactNativeBlurView : BlurViewGroup {
80
83
  // setBlurRadius takes Float, setOverlayColor takes Int, setCornerRadius takes Float (in dp)
81
84
  super.setBlurRadius(currentBlurRadius)
82
85
  super.setOverlayColor(currentOverlayColor)
86
+ super.setDownsampleFactor(6.0F)
83
87
  updateCornerRadius()
84
88
 
85
89
  // Set transparent background to prevent visual artifacts
@@ -322,31 +326,37 @@ class ReactNativeBlurView : BlurViewGroup {
322
326
  }
323
327
  }
324
328
 
329
+ override fun generateDefaultLayoutParams(): BlurViewGroup.LayoutParams {
330
+ return BlurViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
331
+ }
332
+
333
+ override fun generateLayoutParams(attrs: AttributeSet?): BlurViewGroup.LayoutParams {
334
+ return BlurViewGroup.LayoutParams(context, attrs)
335
+ }
336
+
337
+ override fun generateLayoutParams(p: ViewGroup.LayoutParams?): ViewGroup.LayoutParams {
338
+ return ViewGroup.MarginLayoutParams(p)
339
+ }
340
+
341
+ override fun checkLayoutParams(p: ViewGroup.LayoutParams?): Boolean {
342
+ return p is ViewGroup.MarginLayoutParams
343
+ }
344
+
345
+ override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
346
+ // Trust React Native to provide correct dimensions
347
+ setMeasuredDimension(
348
+ MeasureSpec.getSize(widthMeasureSpec),
349
+ MeasureSpec.getSize(heightMeasureSpec)
350
+ )
351
+ }
352
+
325
353
  /**
326
354
  * Override onLayout to properly position children according to React Native's Yoga layout.
327
- * This prevents children from stacking on top of each other and ensures they follow
328
- * the flexbox layout calculated by React Native.
329
- *
330
- * React Native's Yoga layout system calculates positions for all children, but we need
331
- * to explicitly apply those positions in onLayout. Without this, BlurViewGroup's default
332
- * FrameLayout-like behavior would stack all children at (0,0).
333
355
  */
334
356
  override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
335
- // Position each child according to its layout calculated by React Native's Yoga
336
- for (i in 0 until childCount) {
337
- val child = getChildAt(i)
338
- if (child.visibility != GONE) {
339
- // React Native stores the calculated layout in the view's properties
340
- // We just need to apply them by calling layout() with the correct coordinates
341
- val childLeft = child.left
342
- val childTop = child.top
343
- val childRight = child.right
344
- val childBottom = child.bottom
345
-
346
- child.layout(childLeft, childTop, childRight, childBottom)
347
-
348
- logDebug("Laid out child $i at ($childLeft, $childTop, $childRight, $childBottom)")
349
- }
350
- }
357
+ // No-op: Layout is handled by React Native's UIManager.
358
+ // We override this to prevent the superclass (BlurViewGroup/FrameLayout) from
359
+ // re-positioning children based on its own logic (e.g. gravity), which would
360
+ // conflict with React Native's layout.
351
361
  }
352
362
  }
@@ -11,6 +11,7 @@ import android.graphics.Shader
11
11
  import android.util.AttributeSet
12
12
  import android.util.Log
13
13
  import android.widget.FrameLayout
14
+ import android.view.View.MeasureSpec
14
15
  import com.qmdeve.blurview.widget.BlurView
15
16
  import androidx.core.graphics.toColorInt
16
17
 
@@ -18,14 +19,14 @@ import androidx.core.graphics.toColorInt
18
19
  * Android implementation of React Native ProgressiveBlurView component.
19
20
  * Uses a combination of normal blur (BlurView) + linear gradient mask to create
20
21
  * a progressive blur effect that transitions from blurred to clear.
21
- *
22
+ *
22
23
  * This approach is more reliable than using the library's ProgressiveBlurView,
23
24
  * which has limited control over gradient direction and appearance.
24
25
  */
25
26
  class ReactNativeProgressiveBlurView : FrameLayout {
26
27
  private var blurView: BlurView? = null
27
28
  private val gradientPaint = Paint(Paint.ANTI_ALIAS_FLAG)
28
-
29
+
29
30
  private var currentBlurRadius = DEFAULT_BLUR_RADIUS
30
31
  private var currentOverlayColor = Color.TRANSPARENT
31
32
  private var currentDirection = "topToBottom"
@@ -34,7 +35,7 @@ class ReactNativeProgressiveBlurView : FrameLayout {
34
35
 
35
36
  companion object {
36
37
  private const val TAG = "ReactNativeProgressiveBlur"
37
- private const val MAX_BLUR_RADIUS = 25f
38
+ private const val MAX_BLUR_RADIUS = 100f
38
39
  private const val DEFAULT_BLUR_RADIUS = 10f
39
40
  private const val DEBUG = true
40
41
 
@@ -86,7 +87,9 @@ class ReactNativeProgressiveBlurView : FrameLayout {
86
87
  blurView = BlurView(context, null).apply {
87
88
  layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
88
89
  setBlurRadius(currentBlurRadius)
89
- setOverlayColor(currentOverlayColor)
90
+ setDownsampleFactor(6.0F)
91
+ blurRounds = 3
92
+ overlayColor = currentOverlayColor
90
93
  setBackgroundColor(Color.TRANSPARENT)
91
94
  }
92
95
  addView(blurView)
@@ -94,7 +97,7 @@ class ReactNativeProgressiveBlurView : FrameLayout {
94
97
  // Set up the gradient paint
95
98
  gradientPaint.style = Paint.Style.FILL
96
99
  setWillNotDraw(false) // Enable onDraw for gradient overlay
97
-
100
+
98
101
  // Set transparent background for the container
99
102
  super.setBackgroundColor(Color.TRANSPARENT)
100
103
 
@@ -106,6 +109,27 @@ class ReactNativeProgressiveBlurView : FrameLayout {
106
109
  }
107
110
  }
108
111
 
112
+ override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
113
+ val width = MeasureSpec.getSize(widthMeasureSpec)
114
+ val height = MeasureSpec.getSize(heightMeasureSpec)
115
+ setMeasuredDimension(width, height)
116
+
117
+ // Measure the internal blurView to match the parent size
118
+ blurView?.measure(
119
+ MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
120
+ MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
121
+ )
122
+ }
123
+
124
+ override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
125
+ // Layout the internal blurView to fill the parent
126
+ val width = right - left
127
+ val height = bottom - top
128
+ blurView?.layout(0, 0, width, height)
129
+
130
+ // Do NOT call super.onLayout to avoid interfering with React Native children
131
+ }
132
+
109
133
  override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
110
134
  super.onSizeChanged(w, h, oldw, oldh)
111
135
  if (w > 0 && h > 0) {
@@ -154,12 +178,12 @@ class ReactNativeProgressiveBlurView : FrameLayout {
154
178
  floatArrayOf(0f, 1f),
155
179
  Shader.TileMode.CLAMP
156
180
  )
157
-
181
+
158
182
  gradientPaint.shader = gradient
159
-
183
+
160
184
  logDebug("Updated gradient: direction=$currentDirection, start=($x0,$y0), end=($x1,$y1), offset=$currentStartOffset")
161
185
  invalidate()
162
-
186
+
163
187
  } catch (e: Exception) {
164
188
  logError("Failed to update gradient: ${e.message}", e)
165
189
  }
@@ -173,15 +197,15 @@ class ReactNativeProgressiveBlurView : FrameLayout {
173
197
 
174
198
  // Use a layer to apply the gradient mask
175
199
  val saveCount = canvas.saveLayer(0f, 0f, width.toFloat(), height.toFloat(), null)
176
-
200
+
177
201
  // Draw the blur view
178
202
  super.dispatchDraw(canvas)
179
-
203
+
180
204
  // Apply gradient mask using DST_IN to make the blur gradually transparent
181
205
  gradientPaint.xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_IN)
182
206
  canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), gradientPaint)
183
207
  gradientPaint.xfermode = null
184
-
208
+
185
209
  canvas.restoreToCount(saveCount)
186
210
  }
187
211
 
@@ -190,7 +214,7 @@ class ReactNativeProgressiveBlurView : FrameLayout {
190
214
  */
191
215
  override fun setBackgroundColor(color: Int) {
192
216
  logDebug("setBackgroundColor called: $color")
193
-
217
+
194
218
  if (color != Color.TRANSPARENT) {
195
219
  hasExplicitBackground = true
196
220
  logDebug("Stored explicit background color: $color")
@@ -266,13 +290,13 @@ class ReactNativeProgressiveBlurView : FrameLayout {
266
290
  /**
267
291
  * Set the start offset for the progressive blur.
268
292
  * Controls where the gradient transition begins.
269
- *
293
+ *
270
294
  * @param offset The offset value (0.0 to 1.0) - where 0 starts immediately, 1 delays to the end
271
295
  */
272
296
  fun setStartOffset(offset: Float) {
273
297
  currentStartOffset = offset.coerceIn(0.0f, 1.0f)
274
298
  logDebug("setStartOffset: $offset -> clamped to $currentStartOffset")
275
-
299
+
276
300
  try {
277
301
  updateGradient()
278
302
  } catch (e: Exception) {
@@ -306,7 +330,7 @@ class ReactNativeProgressiveBlurView : FrameLayout {
306
330
  logDebug("Cleared reduced transparency fallback color")
307
331
  return
308
332
  }
309
-
333
+
310
334
  try {
311
335
  val fallbackColor = color.toColorInt()
312
336
  logDebug("setReducedTransparencyFallbackColor: $color -> ${Integer.toHexString(fallbackColor)}")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sbaiahmed1/react-native-blur",
3
- "version": "4.2.0",
3
+ "version": "4.2.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",
@@ -116,7 +116,7 @@
116
116
  "tagName": "v${version}"
117
117
  },
118
118
  "npm": {
119
- "publish": true
119
+ "publish": false
120
120
  },
121
121
  "github": {
122
122
  "release": true