@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.
@@ -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 intensity: Double = 1.0
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
- guard style != self.blurStyle || intensity != self.intensity else { return }
25
- self.blurStyle = style
26
- self.intensity = intensity
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
- animator?.stopAnimation(true)
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
- currentEffectStyle = blurStyle
65
-
66
- let newAnimator = UIViewPropertyAnimator(duration: 1, curve: .linear)
67
- newAnimator.addAnimations { [weak self] in
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
- newAnimator.pausesOnCompletion = true
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
- if let animator = animator, animator.state == .active {
79
- animator.stopAnimation(true)
80
- }
48
+ animator?.stopAnimation(true)
81
49
  }
82
50
  }
83
51
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sbaiahmed1/react-native-blur",
3
- "version": "4.6.4-beta.01",
3
+ "version": "4.6.4-beta.03",
4
4
  "description": "React native modern blur view",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",