@sbaiahmed1/react-native-blur 4.6.4-beta.1 → 4.6.4-beta.3
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 +18 -50
- package/package.json +1 -1
|
@@ -7,77 +7,45 @@ import UIKit
|
|
|
7
7
|
class BlurEffectView: UIVisualEffectView {
|
|
8
8
|
private var animator: UIViewPropertyAnimator?
|
|
9
9
|
private var blurStyle: UIBlurEffect.Style = .systemMaterial
|
|
10
|
-
private var
|
|
11
|
-
private var currentEffectStyle: UIBlurEffect.Style?
|
|
10
|
+
private var blurIntensity: Double = 1.0
|
|
12
11
|
|
|
13
12
|
override init(effect: UIVisualEffect?) {
|
|
14
13
|
super.init(effect: effect)
|
|
15
|
-
setupBlur()
|
|
16
14
|
}
|
|
17
15
|
|
|
18
16
|
required init?(coder: NSCoder) {
|
|
19
17
|
super.init(coder: coder)
|
|
20
|
-
setupBlur()
|
|
21
18
|
}
|
|
22
19
|
|
|
23
20
|
func updateBlur(style: UIBlurEffect.Style, intensity: Double) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
blurStyle = style
|
|
22
|
+
blurIntensity = intensity
|
|
23
|
+
setNeedsDisplay()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// draw(_:) is called by UIVisualEffectView whenever the effect needs to refresh —
|
|
27
|
+
// including when the view re-enters a window after navigation. Rebuilding the
|
|
28
|
+
// animator here ensures intensity is always correct on re-appearance.
|
|
29
|
+
override func draw(_ rect: CGRect) {
|
|
30
|
+
super.draw(rect)
|
|
27
31
|
|
|
28
32
|
// Paused animators hang Detox indefinitely — use on/off blur when Detox is running
|
|
29
33
|
if isDetoxPresent() {
|
|
30
|
-
|
|
31
|
-
animator = nil
|
|
32
|
-
effect = intensity > 0 ? UIBlurEffect(style: style) : nil
|
|
34
|
+
effect = blurIntensity > 0 ? UIBlurEffect(style: blurStyle) : nil
|
|
33
35
|
return
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
if intensity == 1.0 {
|
|
37
|
-
animator?.stopAnimation(true)
|
|
38
|
-
animator = nil
|
|
39
|
-
currentEffectStyle = style
|
|
40
|
-
effect = UIBlurEffect(style: style)
|
|
41
|
-
} else if intensity == 0.0 {
|
|
42
|
-
animator?.stopAnimation(true)
|
|
43
|
-
animator = nil
|
|
44
|
-
currentEffectStyle = nil
|
|
45
|
-
effect = nil
|
|
46
|
-
} else {
|
|
47
|
-
if let existing = animator,
|
|
48
|
-
(existing.state == .active || existing.state == .inactive),
|
|
49
|
-
currentEffectStyle == style {
|
|
50
|
-
existing.fractionComplete = intensity
|
|
51
|
-
} else {
|
|
52
|
-
setupBlur()
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private func setupBlur() {
|
|
58
|
-
if let existing = animator, existing.state == .active {
|
|
59
|
-
existing.stopAnimation(true)
|
|
60
|
-
}
|
|
61
|
-
animator = nil
|
|
62
|
-
|
|
63
38
|
effect = nil
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
self?.effect = UIBlurEffect(style: self?.blurStyle ?? .systemMaterial)
|
|
39
|
+
animator?.stopAnimation(true)
|
|
40
|
+
animator = UIViewPropertyAnimator(duration: 1, curve: .linear) { [weak self] in
|
|
41
|
+
guard let self else { return }
|
|
42
|
+
self.effect = UIBlurEffect(style: self.blurStyle)
|
|
69
43
|
}
|
|
70
|
-
|
|
71
|
-
newAnimator.startAnimation()
|
|
72
|
-
newAnimator.pauseAnimation()
|
|
73
|
-
newAnimator.fractionComplete = intensity
|
|
74
|
-
animator = newAnimator
|
|
44
|
+
animator?.fractionComplete = CGFloat(blurIntensity)
|
|
75
45
|
}
|
|
76
46
|
|
|
77
47
|
deinit {
|
|
78
|
-
|
|
79
|
-
animator.stopAnimation(true)
|
|
80
|
-
}
|
|
48
|
+
animator?.stopAnimation(true)
|
|
81
49
|
}
|
|
82
50
|
}
|
|
83
51
|
|