-
-
Notifications
You must be signed in to change notification settings - Fork 721
/
BatchEditToolbarViewController.swift
52 lines (44 loc) 路 1.62 KB
/
BatchEditToolbarViewController.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
import UIKit
public final class BatchEditToolbarViewController: UIViewController {
@IBOutlet private weak var stackView: UIStackView?
@IBOutlet private weak var bottomConstraint: NSLayoutConstraint!
@IBOutlet private weak var separatorView: UIView?
public var items: [UIButton] = []
private var theme: Theme = Theme.standard
public func setItemsEnabled(_ enabled: Bool) {
for item in items {
item.isEnabled = enabled
}
}
public func remove() {
self.willMove(toParent: nil)
view.removeFromSuperview()
self.removeFromParent()
}
public override func didMove(toParent parent: UIViewController?) {
if let parent = parent, let safeAreaOwningView = view.safeAreaLayoutGuide.owningView {
bottomConstraint.constant = max(0, parent.view.safeAreaInsets.bottom - safeAreaOwningView.frame.height)
}
}
public override func viewDidLoad() {
super.viewDidLoad()
for item in items {
stackView?.addArrangedSubview(item)
}
apply(theme: theme)
}
override public func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
adjustTheme(previousTraitCollection)
}
}
extension BatchEditToolbarViewController: Themeable {
public func apply(theme: Theme) {
self.theme = theme
guard viewIfLoaded != nil else {
return
}
view.backgroundColor = theme.colors.midBackground
separatorView?.backgroundColor = theme.colors.border
}
}