Skip to content

Commit 91af23e

Browse files
DanielAraldisbaiahmed1
authored andcommitted
feat(android): re-apply blur rounds in the onAttachedToWindow call
1 parent 867f75c commit 91af23e

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

android/src/main/java/com/sbaiahmed1/reactnativeblur/ReactNativeBlurSwitch.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ class ReactNativeBlurSwitch : BlurSwitchButtonView {
2222
private var onValueChangeListener: ((Boolean) -> Unit)? = null
2323
private var currentValue = false
2424
private var isDisabled = false
25+
private var currentBlurRounds = DEFAULT_BLUR_ROUNDS
2526

2627
companion object {
2728
private const val TAG = "ReactNativeBlurSwitch"
29+
private const val DEFAULT_BLUR_ROUNDS = 5
2830
private const val DEFAULT_WIDTH_DP = 65f
2931
private const val DEFAULT_HEIGHT_DP = 36f
3032
private const val MIN_BLUR_AMOUNT = 0f
@@ -70,7 +72,7 @@ class ReactNativeBlurSwitch : BlurSwitchButtonView {
7072
*/
7173
private fun initializeSwitch() {
7274
try {
73-
blurRounds = 5
75+
blurRounds = currentBlurRounds
7476

7577
setOnCheckedChangeListener { isChecked ->
7678
if (isDisabled) {
@@ -178,6 +180,7 @@ class ReactNativeBlurSwitch : BlurSwitchButtonView {
178180
*/
179181
fun setRounds(rounds: Int) {
180182
val blurRounds = rounds.coerceIn(1, 15)
183+
currentBlurRounds = blurRounds
181184
logDebug("setRounds: $rounds -> $blurRounds")
182185

183186
try {

android/src/main/java/com/sbaiahmed1/reactnativeblur/ReactNativeBlurView.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import android.view.View.MeasureSpec
3131
class ReactNativeBlurView : BlurViewGroup {
3232
private var currentBlurRadius = DEFAULT_BLUR_RADIUS
3333
private var currentOverlayColor = Color.TRANSPARENT
34+
private var currentBlurRounds = DEFAULT_BLUR_ROUNDS
3435
private var currentCornerRadius = 0f
3536
private var glassTintColor: Int = Color.TRANSPARENT
3637
private var glassOpacity: Float = 1.0f
@@ -44,6 +45,7 @@ class ReactNativeBlurView : BlurViewGroup {
4445
private const val TAG = "ReactNativeBlurView"
4546
private const val MAX_BLUR_RADIUS = 100f
4647
private const val DEFAULT_BLUR_RADIUS = 10f
48+
private const val DEFAULT_BLUR_ROUNDS = 5
4749
private const val DEBUG = false
4850

4951
// Cross-platform blur amount constants
@@ -93,7 +95,7 @@ class ReactNativeBlurView : BlurViewGroup {
9395
super.setBackgroundColor(currentOverlayColor)
9496
clipChildren = true
9597
clipToOutline = true
96-
blurRounds = 5
98+
blurRounds = currentBlurRounds
9799
super.setDownsampleFactor(6.0F)
98100
}
99101

@@ -296,6 +298,7 @@ class ReactNativeBlurView : BlurViewGroup {
296298
*/
297299
fun setRounds(rounds: Int) {
298300
val blurRounds = rounds.coerceIn(1, 15)
301+
currentBlurRounds = blurRounds
299302
logDebug("setRounds: $rounds -> $blurRounds")
300303

301304
try {

android/src/main/java/com/sbaiahmed1/reactnativeblur/ReactNativeProgressiveBlurView.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ReactNativeProgressiveBlurView : FrameLayout {
3131
private val gradientPaint = Paint(Paint.ANTI_ALIAS_FLAG)
3232

3333
private var currentBlurRadius = DEFAULT_BLUR_RADIUS
34+
private var currentBlurRounds = DEFAULT_BLUR_ROUNDS
3435
private var currentOverlayColor = Color.TRANSPARENT
3536
private var currentBlurType = "xlight"
3637
private var currentDirection = "topToBottom"
@@ -44,6 +45,7 @@ class ReactNativeProgressiveBlurView : FrameLayout {
4445
private const val TAG = "ReactNativeProgressiveBlur"
4546
private const val MAX_BLUR_RADIUS = 100f
4647
private const val DEFAULT_BLUR_RADIUS = 10f
48+
private const val DEFAULT_BLUR_ROUNDS = 5
4749
private const val DEBUG = false
4850

4951
// Cross-platform blur amount constants
@@ -131,7 +133,7 @@ class ReactNativeProgressiveBlurView : FrameLayout {
131133
blurView = BlurView(context, null).apply {
132134
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
133135
setDownsampleFactor(6.0F)
134-
blurRounds = 5
136+
blurRounds = currentBlurRounds
135137
}
136138
addView(blurView)
137139
}
@@ -466,6 +468,7 @@ class ReactNativeProgressiveBlurView : FrameLayout {
466468
*/
467469
fun setRounds(rounds: Int) {
468470
val blurRounds = rounds.coerceIn(1, 15)
471+
currentBlurRounds = blurRounds
469472
logDebug("setRounds: $rounds -> $blurRounds")
470473

471474
try {

0 commit comments

Comments
 (0)