@sbaiahmed1/react-native-blur 4.6.1-beta.1 → 4.6.1-beta.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.
- package/ios/Views/BlurEffectView.swift +27 -41
- package/package.json +1 -1
|
@@ -7,63 +7,49 @@ import UIKit
|
|
|
7
7
|
|
|
8
8
|
class BlurEffectView: UIVisualEffectView {
|
|
9
9
|
private var animator: UIViewPropertyAnimator?
|
|
10
|
-
private var blurStyle: UIBlurEffect.Style = .systemMaterial
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
private var blurStyle: UIBlurEffect.Style = .systemMaterial {
|
|
11
|
+
didSet {
|
|
12
|
+
visualEffect = UIBlurEffect(style: blurStyle)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
private var intensity: Double = 0.1 {
|
|
16
|
+
didSet {
|
|
17
|
+
setNeedsDisplay()
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
private var visualEffect: UIVisualEffect = UIBlurEffect(style: .systemMaterial) {
|
|
21
|
+
didSet {
|
|
22
|
+
setNeedsDisplay()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
13
25
|
|
|
14
26
|
override init(effect: UIVisualEffect?) {
|
|
15
|
-
super.init(effect:
|
|
27
|
+
super.init(effect: nil)
|
|
16
28
|
}
|
|
17
29
|
|
|
18
30
|
required init?(coder: NSCoder) {
|
|
19
|
-
|
|
31
|
+
return nil
|
|
20
32
|
}
|
|
21
33
|
|
|
22
34
|
func updateBlur(style: UIBlurEffect.Style, intensity: Double) {
|
|
23
|
-
|
|
24
|
-
self.intensity = intensity
|
|
25
|
-
|
|
26
|
-
setupBlur()
|
|
35
|
+
blurStyle = style
|
|
36
|
+
self.intensity = max(0.0, min(1.0, intensity))
|
|
37
|
+
setNeedsDisplay()
|
|
27
38
|
}
|
|
28
39
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if let animator = animator {
|
|
32
|
-
animator.stopAnimation(true)
|
|
33
|
-
animator.finishAnimation(at: .current)
|
|
34
|
-
}
|
|
35
|
-
animator = nil
|
|
36
|
-
|
|
37
|
-
// Reset effect
|
|
40
|
+
override func draw(_ rect: CGRect) {
|
|
41
|
+
super.draw(rect)
|
|
38
42
|
effect = nil
|
|
39
|
-
|
|
40
|
-
// Create new animator
|
|
43
|
+
animator?.stopAnimation(true)
|
|
41
44
|
animator = UIViewPropertyAnimator(duration: 1, curve: .linear)
|
|
42
|
-
animator?.addAnimations { [
|
|
43
|
-
self
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Set intensity
|
|
47
|
-
animator?.fractionComplete = intensity
|
|
48
|
-
// Stop the animation at the current state
|
|
49
|
-
DispatchQueue.main.async { [weak self, weak animator] in
|
|
50
|
-
guard let self = self, let currentAnimator = self.animator, currentAnimator === animator else { return }
|
|
51
|
-
currentAnimator.stopAnimation(true)
|
|
52
|
-
currentAnimator.finishAnimation(at: .current)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
override func didMoveToWindow() {
|
|
57
|
-
super.didMoveToWindow()
|
|
58
|
-
if window != nil && hasConfiguredBlur {
|
|
59
|
-
setupBlur()
|
|
45
|
+
animator?.addAnimations { [unowned self] in
|
|
46
|
+
self.effect = visualEffect
|
|
60
47
|
}
|
|
48
|
+
animator?.fractionComplete = CGFloat(intensity)
|
|
61
49
|
}
|
|
62
50
|
|
|
63
51
|
deinit {
|
|
64
|
-
|
|
65
|
-
animator.stopAnimation(true)
|
|
66
|
-
animator.finishAnimation(at: .current)
|
|
52
|
+
animator?.stopAnimation(true)
|
|
67
53
|
}
|
|
68
54
|
}
|
|
69
55
|
|