-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFeedbackViewController.swift
137 lines (118 loc) · 3.73 KB
/
FeedbackViewController.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
//
// FeedbackViewController.swift
//
// Made with ❤️ by Novum
//
// Copyright © Telefonica. All rights reserved.
//
import UIKit
public class FeedbackViewController: UIViewController {
private let feedbackView: FeedbackView
private let configuration: FeedbackConfiguration
public init(configuration: FeedbackConfiguration) {
self.configuration = configuration
feedbackView = FeedbackView(configuration: configuration)
super.init(nibName: nil, bundle: nil)
if let modalPresentationStyle = configuration.modalPresentationStyle {
self.modalPresentationStyle = modalPresentationStyle
}
if configuration.shouldDisableSwipeToDismiss {
isModalInPresentation = true
}
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
public extension FeedbackViewController {
var assetAccessibilityIdentifier: String? {
get {
feedbackView.assetAccessibilityIdentifier
}
set {
feedbackView.assetAccessibilityIdentifier = newValue
}
}
var titleAccessibilityIdentifier: String? {
get {
feedbackView.titleAccessibilityIdentifier
}
set {
feedbackView.titleAccessibilityIdentifier = newValue
}
}
var subtitleAccessibilityIdentifier: String? {
get {
feedbackView.subtitleAccessibilityIdentifier
}
set {
feedbackView.subtitleAccessibilityIdentifier = newValue
}
}
var errorReferenceAccessibilityIdentifier: String? {
get {
feedbackView.errorReferenceAccessibilityIdentifier
}
set {
feedbackView.errorReferenceAccessibilityIdentifier = newValue
}
}
var primaryButtonAccessibilityIdentifier: String? {
get {
feedbackView.primaryButtonAccessibilityIdentifier
}
set {
feedbackView.primaryButtonAccessibilityIdentifier = newValue
}
}
var secondaryButtonAccessibilityIdentifier: String? {
get {
feedbackView.secondaryButtonAccessibilityIdentifier
}
set {
feedbackView.secondaryButtonAccessibilityIdentifier = newValue
}
}
override func viewDidLoad() {
super.viewDidLoad()
setupNavigationBar()
view.addSubview(withDefaultConstraints: feedbackView)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if configuration.backButton == .none {
navigationController?.interactivePopGestureRecognizer?.isEnabled = false
}
feedbackView.startAnimation()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.interactivePopGestureRecognizer?.isEnabled = true
}
override var preferredStatusBarStyle: UIStatusBarStyle {
MisticaConfig.brandStyle.preferredStatusBarStyle
}
}
private extension FeedbackViewController {
private func setupNavigationBar() {
navigationItem.largeTitleDisplayMode = .never
switch configuration.closeButton {
case .none:
navigationItem.rightBarButtonItem = nil
case .keep:
break
case .custom(let button):
navigationItem.rightBarButtonItem = button
}
switch configuration.backButton {
case .none:
navigationItem.hidesBackButton = true
navigationItem.leftBarButtonItem = nil
case .keep:
break
case .custom(let button):
navigationItem.leftBarButtonItem = button
}
}
}