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 +4 -4
- data/lib/turbo_native_initializer/templates/ios_stack/TurboNativeProject/Controllers/UIViewController+Toast.swift +28 -8
- data/lib/turbo_native_initializer/templates/ios_tabs/TurboNativeProject/Controllers/UIViewController+Toast.swift +28 -8
- data/lib/turbo_native_initializer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1f5d9801c82d83f38a465a6375d87b1b90ac03a19bcf292b78555f9bc925cee
|
4
|
+
data.tar.gz: 5405c39714a62d1f5823d46be8bb9935ac52743f2c02d9a0b544b82f73fd6f40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
|
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() +
|
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.
|
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
|
-
|
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() +
|
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()
|
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.
|
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-
|
11
|
+
date: 2023-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|