@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.
- package/ios/Views/AdvancedBlurView.swift +42 -67
- package/package.json +1 -1
|
@@ -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
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
private func syncBackgroundLayersToBack() {
|
|
51
|
+
if fallbackView.superview === self {
|
|
52
|
+
sendSubviewToBack(fallbackView)
|
|
53
|
+
}
|
|
54
|
+
if blurEffectView.superview === self {
|
|
55
|
+
sendSubviewToBack(blurEffectView)
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
}
|