@@ -100,7 +100,7 @@ public class LoadingViewController: UIViewController {
100
100
return true
101
101
}
102
102
103
- func addLoadingView ( viewToAdd: UIView ) {
103
+ func addView ( viewToAdd: UIView ) {
104
104
view. addSubview ( viewToAdd)
105
105
viewToAdd. translatesAutoresizingMaskIntoConstraints = false
106
106
let bindings = [ " view " : viewToAdd]
@@ -109,34 +109,6 @@ public class LoadingViewController: UIViewController {
109
109
view. layoutIfNeeded ( )
110
110
}
111
111
112
- func addErrorView( viewToAdd: UIView ) {
113
- view. addSubview ( viewToAdd)
114
- viewToAdd. translatesAutoresizingMaskIntoConstraints = false
115
- let bindings = [ " view " : viewToAdd]
116
- view. addConstraints ( NSLayoutConstraint . constraintsWithVisualFormat ( " |[view]| " , options: [ . AlignAllLeading, . AlignAllTrailing] , metrics: nil , views: bindings) )
117
- view. addConstraints ( NSLayoutConstraint . constraintsWithVisualFormat ( " V:|[view]| " , options: [ . AlignAllTop, . AlignAllBottom] , metrics: nil , views: bindings) )
118
- view. layoutIfNeeded ( )
119
- }
120
-
121
- /*
122
- - (void)addErrorView:(UIView *)aView
123
- {
124
- [self.view addSubview:aView];
125
- aView.translatesAutoresizingMaskIntoConstraints = NO;
126
- [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:
127
- @"|[aView]|" options:NSLayoutFormatAlignAllTrailing |
128
- NSLayoutFormatAlignAllLeading metrics:nil views:
129
- NSDictionaryOfVariableBindings(aView)]];
130
- [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:
131
- @"V:[aView]|" options:NSLayoutFormatAlignAllBottom metrics:nil
132
- views:NSDictionaryOfVariableBindings(aView)]];
133
- [self.view addConstraint:[NSLayoutConstraint constraintWithItem:
134
- aView attribute:NSLayoutAttributeTop relatedBy:
135
- NSLayoutRelationEqual toItem:self.topGuideConstraint attribute:
136
- NSLayoutAttributeBottom multiplier:1.0 constant:self.contentInsets.top]];
137
- }
138
- */
139
-
140
112
func viewForScreen( contentType: ContentType ) -> UIView {
141
113
switch contentType {
142
114
case . Content:
@@ -155,14 +127,14 @@ public class LoadingViewController: UIViewController {
155
127
}
156
128
157
129
// TODO: add ActionHandler support to handle 'Retry' tap on ErrorViews
158
- public func setVisibleScreen( contentType: ContentType , actionHandler: ActionHandler ? = nil ) {
130
+ public func setVisibleScreen( contentType: ContentType , animated : Bool = true , actionHandler: ActionHandler ? = nil ) {
159
131
if visibleContentType != contentType {
160
132
visibleContentType = contentType
161
- setActiveView ( viewForScreen ( visibleContentType) )
133
+ setActiveView ( viewForScreen ( visibleContentType) , animated : animated )
162
134
}
163
135
}
164
136
165
- func setActiveView( viewToSet: UIView , animated: Bool = true ) {
137
+ func setActiveView( viewToSet: UIView , animated: Bool ) {
166
138
if viewToSet != activeView {
167
139
let oldView = activeView ?? nil
168
140
activeView = viewToSet
@@ -272,14 +244,7 @@ public class LoadingViewController: UIViewController {
272
244
startNextAnimationIfNeeded ( )
273
245
}
274
246
275
- switch contentType {
276
- case . Loading:
277
- addLoadingView ( toView)
278
- case . Failure:
279
- addErrorView ( toView)
280
- default :
281
- break
282
- }
247
+ addView ( toView)
283
248
284
249
let theFromView = fromView
285
250
let fromViewIsContentView = ( theFromView == self . contentView)
0 commit comments