@sbaiahmed1/react-native-blur 4.6.1-beta.2 → 4.6.1-beta.4

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,11 +1,8 @@
1
- import SwiftUI
2
1
  import UIKit
3
2
 
4
- // MARK: - UIKit Wrapper for Blur
5
-
6
3
  @objc public class AdvancedBlurView: UIView {
7
-
8
- private var hostingController: UIHostingController<BasicColoredView>?
4
+ private let blurEffectView = BlurEffectView(effect: nil)
5
+ private let fallbackView = UIView()
9
6
 
10
7
  @objc public var blurAmount: Double = 10.0 {
11
8
  didSet {
@@ -29,79 +26,63 @@ import UIKit
29
26
  didSet {
30
27
  updateView()
31
28
  }
32
- }
29
+ }
33
30
 
34
31
  public override init(frame: CGRect) {
35
32
  super.init(frame: frame)
33
+ setupViews()
36
34
  }
37
35
 
38
36
  required init?(coder: NSCoder) {
39
37
  super.init(coder: coder)
38
+ setupViews()
40
39
  }
41
40
 
42
- public override func layoutSubviews() {
43
- super.layoutSubviews()
44
- // Defer controller setup until we have a valid frame to avoid issues with initial render
45
- // in complex layouts (e.g. FlashList with dynamic content)
46
- if hostingController == nil && bounds.width > 0 && bounds.height > 0 {
47
- setupHostingController()
48
- }
41
+ private func setupViews() {
42
+ blurEffectView.isUserInteractionEnabled = false
43
+ fallbackView.isUserInteractionEnabled = false
44
+ addSubview(fallbackView)
45
+ addSubview(blurEffectView)
46
+ syncBackgroundLayersToBack()
47
+ updateView()
49
48
  }
50
49
 
51
- private func setupHostingController() {
52
- // Completely remove old hosting controller
53
- if let oldHosting = hostingController {
54
- oldHosting.view.removeFromSuperview()
55
- oldHosting.removeFromParent()
50
+ private func syncBackgroundLayersToBack() {
51
+ if fallbackView.superview === self {
52
+ sendSubviewToBack(fallbackView)
53
+ }
54
+ if blurEffectView.superview === self {
55
+ sendSubviewToBack(blurEffectView)
56
56
  }
57
- hostingController = nil
57
+ }
58
58
 
59
- let blurStyle = blurStyleFromString(blurTypeString)
60
- let swiftUIView = BasicColoredView(
61
- blurAmount: blurAmount,
62
- blurStyle: blurStyle,
63
- ignoreSafeArea: ignoreSafeArea,
64
- reducedTransparencyFallbackColor: reducedTransparencyFallbackColor
65
- )
66
-
67
- let hosting = UIHostingController(rootView: swiftUIView)
68
- hosting.view.backgroundColor = .clear
69
- hosting.view.translatesAutoresizingMaskIntoConstraints = false
70
-
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)
59
+ public override func didAddSubview(_ subview: UIView) {
60
+ super.didAddSubview(subview)
61
+ if subview !== blurEffectView && subview !== fallbackView {
62
+ syncBackgroundLayersToBack()
77
63
  }
78
-
79
- NSLayoutConstraint.activate([
80
- hosting.view.topAnchor.constraint(equalTo: topAnchor),
81
- hosting.view.leadingAnchor.constraint(equalTo: leadingAnchor),
82
- hosting.view.trailingAnchor.constraint(equalTo: trailingAnchor),
83
- hosting.view.bottomAnchor.constraint(equalTo: bottomAnchor)
84
- ])
85
-
86
- self.hostingController = hosting
64
+ }
65
+
66
+ public override func layoutSubviews() {
67
+ super.layoutSubviews()
68
+ fallbackView.frame = bounds
69
+ blurEffectView.frame = bounds
87
70
  }
88
71
 
89
72
  private func updateView() {
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()
73
+ if UIAccessibility.isReduceTransparencyEnabled {
74
+ fallbackView.isHidden = false
75
+ blurEffectView.isHidden = true
76
+ fallbackView.backgroundColor = reducedTransparencyFallbackColor
77
+ return
104
78
  }
79
+
80
+ fallbackView.isHidden = true
81
+ blurEffectView.isHidden = false
82
+ let blurStyle = blurStyleFromString(blurTypeString)
83
+ let intensity = mapBlurAmountToIntensity(blurAmount)
84
+ blurEffectView.updateBlur(style: blurStyle, intensity: intensity)
85
+ blurEffectView.setNeedsDisplay()
105
86
  }
106
87
 
107
88
  public override func didMoveToSuperview() {
@@ -115,11 +96,5 @@ import UIKit
115
96
  }
116
97
  }
117
98
 
118
- deinit {
119
- if let hosting = hostingController {
120
- hosting.view.removeFromSuperview()
121
- hosting.removeFromParent()
122
- }
123
- hostingController = nil
124
- }
99
+ deinit {}
125
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sbaiahmed1/react-native-blur",
3
- "version": "4.6.1-beta.2",
3
+ "version": "4.6.1-beta.4",
4
4
  "description": "React native modern blur view",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",