-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdaptiveModalBasicUsage01.swift
160 lines (127 loc) · 4.11 KB
/
AdaptiveModalBasicUsage01.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//
// AdaptiveModalBasicUsage01.swift
// adaptive-modal-example
//
// Created by Dominic Go on 8/26/23.
//
import UIKit
import AdaptiveModal
import ComputableLayout
fileprivate class ModalViewController: UIViewController {
weak var modalManager: AdaptiveModalManager?;
override func viewDidLoad() {
self.view.backgroundColor = .clear;
let dismissButton: UIButton = {
let button = UIButton();
button.setTitle("Dismiss Modal", for: .normal);
if #available(iOS 15.0, *) {
button.configuration = .filled()
};
button.addTarget(
self,
action: #selector(self.onPressButtonDismiss(_:)),
for: .touchUpInside
);
button.sizeToFit();
return button;
}();
let controlsView: UIStackView = {
let stack = UIStackView();
stack.axis = .vertical;
stack.distribution = .equalSpacing;
stack.alignment = .center;
stack.spacing = 10;
stack.addArrangedSubview(dismissButton);
return stack;
}();
controlsView.translatesAutoresizingMaskIntoConstraints = false;
self.view.addSubview(controlsView);
NSLayoutConstraint.activate([
controlsView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
controlsView.centerYAnchor.constraint(equalTo: self.view.centerYAnchor),
]);
};
@objc func onPressButtonDismiss(_ sender: UIButton){
self.modalManager?.dismissModal(
animated: true,
animationConfig: .presetCurve(
duration: 0.275,
curve: .easeInOut
)
);
};
};
class AdaptiveModalBasicUsage01 : UIViewController {
var adaptiveModalManager: AdaptiveModalManager?;
override func viewDidLoad() {
self.view.backgroundColor =
UIColor(red: 0.8, green: 0.8, blue: 1, alpha: 1);
let presentButton: UIButton = {
let button = UIButton();
button.setTitle("Present View Controller", for: .normal);
button.setTitleColor(.white, for: .normal);
button.configuration = .filled();
button.layer.cornerRadius = 10;
button.addTarget(
self,
action: #selector(self.onPressButtonPresentViewController(_:)),
for: .touchUpInside
);
return button;
}();
let stackView: UIStackView = {
let stack = UIStackView();
stack.axis = .vertical;
stack.distribution = .equalSpacing;
stack.alignment = .center;
stack.spacing = 7;
stack.addArrangedSubview(presentButton);
return stack;
}();
stackView.translatesAutoresizingMaskIntoConstraints = false;
self.view.addSubview(stackView);
NSLayoutConstraint.activate([
stackView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
stackView.centerYAnchor.constraint(equalTo: self.view.centerYAnchor),
]);
};
@objc func onPressButtonPresentViewController(_ sender: UIButton) {
let modalConfig = AdaptiveModalConfig(
snapPoints: [
// snap point - 1
AdaptiveModalSnapPointConfig(
layoutConfig: ComputableLayout(
horizontalAlignment: .center,
verticalAlignment: .bottom,
width: .stretch,
height: .percent(percentValue: 0.7)
),
keyframeConfig: AdaptiveModalKeyframeConfig(
modalShadowColor: .black,
modalShadowOpacity: 0.1,
modalShadowRadius: 10,
modalCornerRadius: 15,
modalMaskedCorners: .topCorners,
backgroundColor: .black,
backgroundOpacity: 0.2
)
),
],
snapDirection: .bottomToTop,
undershootSnapPoint: .automatic,
overshootSnapPoint: AdaptiveModalSnapPointPreset(
layoutPreset: .fitScreenVertically
)
);
let modalManager = AdaptiveModalManager(
presentingViewController: self,
staticConfig: modalConfig
);
let modalVC = ModalViewController();
modalVC.modalManager = modalManager;
modalManager.presentModal(
viewControllerToPresent: modalVC,
presentingViewController: self
);
};
};