-
-
Notifications
You must be signed in to change notification settings - Fork 721
/
DescriptionWelcomeContainerViewController.swift
76 lines (64 loc) 路 2.86 KB
/
DescriptionWelcomeContainerViewController.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
class DescriptionWelcomeContainerViewController: UIViewController, Themeable {
private var theme = Theme.standard
func apply(theme: Theme) {
self.theme = theme
}
@IBOutlet private var topContainerView:UIView!
@IBOutlet private var bottomContainerView:UIView!
@IBOutlet private var overallContainerStackView:UIStackView!
@IBOutlet private var overallContainerStackViewCenterYConstraint:NSLayoutConstraint!
@IBOutlet private var topContainerViewHeightConstraint:NSLayoutConstraint!
var pageType:DescriptionWelcomePageType = .intro
weak var welcomeNavigationDelegate:DescriptionWelcomeNavigationDelegate? = nil
private var hasAlreadyFadedInAndUp = false
private var needsDeviceAdjustments = true
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if (shouldFadeInAndUp() && !hasAlreadyFadedInAndUp) {
view.wmf_zeroLayerOpacity()
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if (shouldFadeInAndUp() && !hasAlreadyFadedInAndUp) {
view.wmf_fadeInAndUpWithDuration(0.4, delay: 0.1)
hasAlreadyFadedInAndUp = true
}
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
adjustTheme(previousTraitCollection)
}
private func shouldFadeInAndUp() -> Bool {
switch pageType {
case .intro:
return false
case .exploration:
return true
}
}
override func updateViewConstraints() {
super.updateViewConstraints()
if needsDeviceAdjustments {
useBottomAlignmentIfPhone()
needsDeviceAdjustments = false
}
}
private func useBottomAlignmentIfPhone() {
assert(Int(overallContainerStackViewCenterYConstraint.priority.rawValue) == 999, "The Y centering constraint must not have required '1000' priority because on non-tablets we add a required bottom alignment constraint on overallContainerView which we want to be favored when present.")
if (UI_USER_INTERFACE_IDIOM() == .phone) {
overallContainerStackView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: 0).isActive = true
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let vc = segue.destination as? DescriptionWelcomePanelViewController {
vc.pageType = pageType
vc.apply(theme: theme)
} else if let vc = segue.destination as? DescriptionWelcomeImageViewController{
vc.pageType = pageType
}
}
@IBAction private func next(withSender sender: AnyObject) {
welcomeNavigationDelegate?.showNextWelcomePage(self)
}
}