turbo-native-initializer 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb141a7b5a2949e9b65bdf004831663bf43377c858891129cd3a6959d73292f2
4
- data.tar.gz: d8636b8bbf702f0483dc737fd49182a887d610d614ae44779fe7191d9391f1c0
3
+ metadata.gz: c1f5d9801c82d83f38a465a6375d87b1b90ac03a19bcf292b78555f9bc925cee
4
+ data.tar.gz: 5405c39714a62d1f5823d46be8bb9935ac52743f2c02d9a0b544b82f73fd6f40
5
5
  SHA512:
6
- metadata.gz: 912afab330194fcaa45897f1f69e92aff243287ada0032322e704163bd6f91be9ab2055df64e635c1ea998de937af603b5b98e8f0add070f7a4507be4d4906f6
7
- data.tar.gz: bf237f3895adbc21f9095ea00ca016ac205ecad78d17da223a5227fa31afe2d207fd69c6c358c278654f897be06a6f50b2909a88618d3b8e342be9e25c330f47
6
+ metadata.gz: 65fbcd8000abe1b6c9c4c0c0ca4ab715ecbc8ac828ca1b859bc93b7d9a32718163913b12b881ee6ea2e41c244df50c7d869dc8fe420d86a09e9dfcd50b274a28
7
+ data.tar.gz: d3c907983b7c31767b99c9bd34bb0b0185fbb4bb8028c19a6c5e6648c739baf99a08e6a4318207ed25644a41c2a6d4d84bcabd529288dd85004c42b52f21f0a4
@@ -4,22 +4,44 @@ public extension UIViewController {
4
4
  func presentToast(_ message: String) {
5
5
  guard let root = view.window?.rootViewController else { return }
6
6
 
7
+ removeToastViews(from: root)
8
+
7
9
  let toastView = ToastView(message: message)
8
10
  toastView.translatesAutoresizingMaskIntoConstraints = false
9
11
 
10
12
  root.view.addSubview(toastView)
11
13
 
12
14
  NSLayoutConstraint.activate([
13
- toastView.centerXAnchor.constraint(equalTo: root.view.centerXAnchor),
14
15
  toastView.topAnchor.constraint(equalTo: root.view.safeAreaLayoutGuide.topAnchor),
15
- toastView.widthAnchor.constraint(equalTo: root.view.safeAreaLayoutGuide.widthAnchor, constant: -10)
16
+ toastView.centerXAnchor.constraint(equalTo: root.view.centerXAnchor)
17
+ ])
18
+
19
+ let widthConstraint = toastView.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -10)
20
+ widthConstraint.priority = .defaultHigh
21
+
22
+ let maxWidthConstraint = toastView.widthAnchor.constraint(lessThanOrEqualToConstant: 600)
23
+ maxWidthConstraint.priority = .required
24
+
25
+ NSLayoutConstraint.activate([
26
+ widthConstraint, maxWidthConstraint
16
27
  ])
17
28
  }
29
+
30
+ fileprivate func removeToastViews(from root: UIViewController) {
31
+ root.view.subviews.filter({ $0 is ToastView }).forEach({ toast in
32
+ toast.removeFromSuperview()
33
+ })
34
+ }
18
35
  }
19
36
 
20
37
  public class ToastView: UIView {
38
+
39
+ private var duration = 2.5
40
+
21
41
  convenience init(message: String) {
22
42
  self.init(frame: .zero)
43
+
44
+ self.alpha = .zero
23
45
  self.backgroundColor = .black
24
46
  self.layer.cornerRadius = 10
25
47
 
@@ -40,17 +62,15 @@ public class ToastView: UIView {
40
62
 
41
63
  addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(dismiss)))
42
64
 
43
- self.alpha = .zero
44
-
45
- UIView.animate(withDuration: 0.5, delay: .zero, animations: {
65
+ UIView.animate(withDuration: 0.5, delay: .zero, options: .curveEaseIn, animations: {
46
66
  self.alpha = 0.9
47
67
  }, completion: { _ in
48
- DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { self.dismiss() }
68
+ DispatchQueue.main.asyncAfter(deadline: .now() + self.duration) { self.dismiss() }
49
69
  })
50
70
  }
51
71
 
52
- @objc func dismiss() {
53
- UIView.animate(withDuration: 0.5, delay: .zero, animations: {
72
+ @objc private func dismiss() {
73
+ UIView.animate(withDuration: 0.5, delay: .zero, options: .curveEaseOut, animations: {
54
74
  self.alpha = .zero
55
75
  }, completion: { _ in
56
76
  self.removeFromSuperview()
@@ -4,22 +4,44 @@ public extension UIViewController {
4
4
  func presentToast(_ message: String) {
5
5
  guard let root = view.window?.rootViewController else { return }
6
6
 
7
+ removeToastViews(from: root)
8
+
7
9
  let toastView = ToastView(message: message)
8
10
  toastView.translatesAutoresizingMaskIntoConstraints = false
9
11
 
10
12
  root.view.addSubview(toastView)
11
13
 
12
14
  NSLayoutConstraint.activate([
13
- toastView.centerXAnchor.constraint(equalTo: root.view.centerXAnchor),
14
15
  toastView.topAnchor.constraint(equalTo: root.view.safeAreaLayoutGuide.topAnchor),
15
- toastView.widthAnchor.constraint(equalTo: root.view.safeAreaLayoutGuide.widthAnchor, constant: -10)
16
+ toastView.centerXAnchor.constraint(equalTo: root.view.centerXAnchor)
17
+ ])
18
+
19
+ let widthConstraint = toastView.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -10)
20
+ widthConstraint.priority = .defaultHigh
21
+
22
+ let maxWidthConstraint = toastView.widthAnchor.constraint(lessThanOrEqualToConstant: 600)
23
+ maxWidthConstraint.priority = .required
24
+
25
+ NSLayoutConstraint.activate([
26
+ widthConstraint, maxWidthConstraint
16
27
  ])
17
28
  }
29
+
30
+ fileprivate func removeToastViews(from root: UIViewController) {
31
+ root.view.subviews.filter({ $0 is ToastView }).forEach({ toast in
32
+ toast.removeFromSuperview()
33
+ })
34
+ }
18
35
  }
19
36
 
20
37
  public class ToastView: UIView {
38
+
39
+ private var duration = 2.5
40
+
21
41
  convenience init(message: String) {
22
42
  self.init(frame: .zero)
43
+
44
+ self.alpha = .zero
23
45
  self.backgroundColor = .black
24
46
  self.layer.cornerRadius = 10
25
47
 
@@ -40,17 +62,15 @@ public class ToastView: UIView {
40
62
 
41
63
  addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(dismiss)))
42
64
 
43
- self.alpha = .zero
44
-
45
- UIView.animate(withDuration: 0.5, delay: .zero, animations: {
65
+ UIView.animate(withDuration: 0.5, delay: .zero, options: .curveEaseIn, animations: {
46
66
  self.alpha = 0.9
47
67
  }, completion: { _ in
48
- DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { self.dismiss() }
68
+ DispatchQueue.main.asyncAfter(deadline: .now() + self.duration) { self.dismiss() }
49
69
  })
50
70
  }
51
71
 
52
- @objc func dismiss() {
53
- UIView.animate(withDuration: 0.5, delay: .zero, animations: {
72
+ @objc private func dismiss() {
73
+ UIView.animate(withDuration: 0.5, delay: .zero, options: .curveEaseOut, animations: {
54
74
  self.alpha = .zero
55
75
  }, completion: { _ in
56
76
  self.removeFromSuperview()
@@ -1,3 +1,3 @@
1
1
  module TurboNativeInitializer
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo-native-initializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nixon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-28 00:00:00.000000000 Z
11
+ date: 2023-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor