Skip to content

Commit 3da8a26

Browse files
committed
fix(android,ios): prevent blur initialization delay and z-ordering bug
1 parent ad7864a commit 3da8a26

2 files changed

Lines changed: 28 additions & 12 deletions

File tree

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,12 @@ class ReactNativeBlurView : BlurViewGroup {
107107

108108
if (isBlurInitialized) return
109109

110-
// Defer the blur root swap to next frame so the view tree is fully mounted
111-
val runnable = Runnable {
112-
initRunnable = null
113-
if (isBlurInitialized) return@Runnable
114-
swapBlurRootToScreenAncestor()
115-
initializeBlur()
116-
}
117-
initRunnable = runnable
118-
post(runnable)
110+
// Immediately try to swap blur root and initialize.
111+
// We avoid posting a runnable to prevent the 1-second delay artifact.
112+
// If the parent hierarchy is not ready yet (unlikely in onAttachedToWindow),
113+
// we could fall back to post, but for now we prioritize immediate execution.
114+
swapBlurRootToScreenAncestor()
115+
initializeBlur()
119116
}
120117

121118
/**

ios/Views/AdvancedBlurView.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ import UIKit
6868
hosting.view.backgroundColor = .clear
6969
hosting.view.translatesAutoresizingMaskIntoConstraints = false
7070

71-
addSubview(hosting.view)
71+
// Insert at index 0 to ensure it stays behind any potential subviews (though usually this view has no children)
72+
// This fixes the z-ordering bug where blur covers content
73+
if !subviews.isEmpty {
74+
insertSubview(hosting.view, at: 0)
75+
} else {
76+
addSubview(hosting.view)
77+
}
78+
7279
NSLayoutConstraint.activate([
7380
hosting.view.topAnchor.constraint(equalTo: topAnchor),
7481
hosting.view.leadingAnchor.constraint(equalTo: leadingAnchor),
@@ -80,8 +87,20 @@ import UIKit
8087
}
8188

8289
private func updateView() {
83-
if hostingController != nil {
84-
setupHostingController()
90+
if let hosting = hostingController {
91+
// Update the existing controller's root view to avoid expensive recreation
92+
// This fixes performance bottlenecks and state synchronization issues
93+
let blurStyle = blurStyleFromString(blurTypeString)
94+
let swiftUIView = BasicColoredView(
95+
blurAmount: blurAmount,
96+
blurStyle: blurStyle,
97+
ignoreSafeArea: ignoreSafeArea,
98+
reducedTransparencyFallbackColor: reducedTransparencyFallbackColor
99+
)
100+
hosting.rootView = swiftUIView
101+
hosting.view.setNeedsLayout()
102+
} else {
103+
setupHostingController()
85104
}
86105
}
87106

0 commit comments

Comments
 (0)