Skip to content

Commit 6204740

Browse files
authored
Merge pull request #139 from cashapp/entin/activation-point-view
Modernize ActivationPointViewController
2 parents 788822f + b75e77b commit 6204740

File tree

1 file changed

+51
-26
lines changed

1 file changed

+51
-26
lines changed

Example/AccessibilitySnapshot/ActivationPointViewController.swift

+51-26
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,69 @@ import UIKit
1919

2020
final class ActivationPointViewController: AccessibilityViewController {
2121

22-
// MARK: - Private Properties
22+
override func loadView() {
23+
view = View()
24+
}
2325

24-
// A button for demonstrating what a standard activation point looks like.
25-
private let button: UIButton = .init()
26+
}
2627

27-
private let customActivationPointView: CustomActivationPointView = .init()
28+
// MARK: -
2829

29-
private var views: [UIView] {
30-
return [
31-
button,
32-
customActivationPointView,
33-
]
34-
}
30+
private extension ActivationPointViewController {
3531

36-
// MARK: - UIViewController
32+
final class View: UIView {
3733

38-
override func viewDidLoad() {
39-
super.viewDidLoad()
34+
// MARK: - Life Cycle
4035

41-
button.setTitle("Do Something", for: .normal)
42-
button.setTitleColor(.black, for: .normal)
36+
override init(frame: CGRect) {
37+
super.init(frame: frame)
4338

44-
views.forEach { view.addSubview($0) }
45-
}
39+
button.setTitle("Do Something", for: .normal)
40+
button.setTitleColor(.black, for: .normal)
41+
addSubview(button)
4642

47-
override func viewDidLayoutSubviews() {
48-
super.viewDidLayoutSubviews()
43+
addSubview(customActivationPointView)
44+
}
4945

50-
views.forEach { $0.frame.size = $0.sizeThatFits(view.bounds.size) }
46+
@available(*, unavailable)
47+
required init?(coder: NSCoder) {
48+
fatalError("init(coder:) has not been implemented")
49+
}
50+
51+
// MARK: - Private Properties
52+
53+
// A button for demonstrating what a standard activation point looks like.
54+
private let button: UIButton = .init()
5155

52-
let statusBarHeight = UIApplication.shared.statusBarFrame.height
56+
private let customActivationPointView: CustomActivationPointView = .init()
5357

54-
var distributionSpecifiers: [ViewDistributionSpecifying] = [ statusBarHeight.fixed, 1.flexible ]
55-
for subview in views {
56-
distributionSpecifiers.append(subview)
57-
distributionSpecifiers.append(1.flexible)
58+
private var views: [UIView] {
59+
return [
60+
button,
61+
customActivationPointView,
62+
]
5863
}
59-
view.applySubviewDistribution(distributionSpecifiers)
64+
65+
// MARK: - UIView
66+
67+
override func layoutSubviews() {
68+
button.resize(toFit: bounds.size)
69+
customActivationPointView.resize(toFit: bounds.size)
70+
71+
let statusBarHeight = window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0
72+
73+
applySubviewDistribution(
74+
[
75+
statusBarHeight.fixed,
76+
1.flexible,
77+
button,
78+
1.flexible,
79+
customActivationPointView,
80+
1.flexible,
81+
]
82+
)
83+
}
84+
6085
}
6186

6287
}

0 commit comments

Comments
 (0)