@sbaiahmed1/react-native-blur 4.6.1-beta.0 → 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.
@@ -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
- private var intensity: Double = 1.0
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
+ }
12
25
 
13
26
  override init(effect: UIVisualEffect?) {
14
- super.init(effect: effect)
15
- setupBlur()
27
+ super.init(effect: nil)
16
28
  }
17
29
 
18
30
  required init?(coder: NSCoder) {
19
- super.init(coder: coder)
20
- setupBlur()
31
+ return nil
21
32
  }
22
33
 
23
34
  func updateBlur(style: UIBlurEffect.Style, intensity: Double) {
24
- self.blurStyle = style
25
- self.intensity = intensity
26
- setupBlur()
35
+ blurStyle = style
36
+ self.intensity = max(0.0, min(1.0, intensity))
37
+ setNeedsDisplay()
27
38
  }
28
39
 
29
- private func setupBlur() {
30
- // Clean up existing animator
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 { [weak self] in
43
- self?.effect = UIBlurEffect(style: self?.blurStyle ?? .systemMaterial)
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 {
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
- guard let animator = animator, animator.state == .active else { return }
65
- animator.stopAnimation(true)
66
- animator.finishAnimation(at: .current)
52
+ animator?.stopAnimation(true)
67
53
  }
68
54
  }
69
55
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sbaiahmed1/react-native-blur",
3
- "version": "4.6.1-beta.0",
3
+ "version": "4.6.1-beta.2",
4
4
  "description": "React native modern blur view",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",