-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Singleton Only Presenter. Allow multiple presenters. #299
Changes from 6 commits
0054bc1
7106c33
4d456a9
71ce15f
6fbddce
abd0692
43fa684
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,8 +227,11 @@ public final class NVActivityIndicatorPresenter { | |
/// Current status of animation, read-only. | ||
public var isAnimating: Bool { return state == .animating || state == .waitingToStop } | ||
|
||
private init() {} | ||
|
||
public private(set) weak var presentingView: UIView? | ||
public private(set) weak var presentedView: UIView? | ||
public required init(presentingView: UIView? = nil) { | ||
self.presentingView = presentingView | ||
} | ||
// MARK: - Public interface | ||
|
||
/** | ||
|
@@ -263,8 +266,10 @@ public final class NVActivityIndicatorPresenter { | |
// MARK: - Helpers | ||
|
||
fileprivate func show(with activityData: ActivityData, _ fadeInAnimation: FadeInAnimation?) { | ||
let containerView = UIView(frame: UIScreen.main.bounds) | ||
|
||
guard let presentingView = self.presentingView ?? UIApplication.shared.keyWindow else { return } | ||
let containerViewFrame = self.presentingView?.bounds ?? UIScreen.main.bounds | ||
let containerView = UIView(frame: containerViewFrame) | ||
|
||
containerView.backgroundColor = activityData.backgroundColor | ||
containerView.restorationIdentifier = restorationIdentifier | ||
containerView.translatesAutoresizingMaskIntoConstraints = false | ||
|
@@ -286,7 +291,7 @@ public final class NVActivityIndicatorPresenter { | |
let yConstraint = NSLayoutConstraint(item: containerView, attribute: .centerY, relatedBy: .equal, toItem: activityIndicatorView, attribute: .centerY, multiplier: 1, constant: 0) | ||
|
||
containerView.addConstraints([xConstraint, yConstraint]) | ||
}()) | ||
}()) | ||
|
||
messageLabel.font = activityData.messageFont | ||
messageLabel.textColor = activityData.textColor | ||
|
@@ -299,41 +304,41 @@ public final class NVActivityIndicatorPresenter { | |
let trailingConstraint = NSLayoutConstraint(item: containerView, attribute: .trailing, relatedBy: .equal, toItem: messageLabel, attribute: .trailing, multiplier: 1, constant: 8) | ||
|
||
containerView.addConstraints([leadingConstraint, trailingConstraint]) | ||
}()) | ||
}()) | ||
({ | ||
let spacingConstraint = NSLayoutConstraint(item: messageLabel, attribute: .top, relatedBy: .equal, toItem: activityIndicatorView, attribute: .bottom, multiplier: 1, constant: activityData.messageSpacing) | ||
|
||
containerView.addConstraint(spacingConstraint) | ||
}()) | ||
}()) | ||
|
||
guard let keyWindow = UIApplication.shared.keyWindow else { return } | ||
|
||
keyWindow.addSubview(containerView) | ||
presentingView.addSubview(containerView) | ||
|
||
// Add constraints for `containerView`. | ||
({ | ||
let leadingConstraint = NSLayoutConstraint(item: keyWindow, attribute: .leading, relatedBy: .equal, toItem: containerView, attribute: .leading, multiplier: 1, constant: 0) | ||
let trailingConstraint = NSLayoutConstraint(item: keyWindow, attribute: .trailing, relatedBy: .equal, toItem: containerView, attribute: .trailing, multiplier: 1, constant: 0) | ||
let topConstraint = NSLayoutConstraint(item: keyWindow, attribute: .top, relatedBy: .equal, toItem: containerView, attribute: .top, multiplier: 1, constant: 0) | ||
let bottomConstraint = NSLayoutConstraint(item: keyWindow, attribute: .bottom, relatedBy: .equal, toItem: containerView, attribute: .bottom, multiplier: 1, constant: 0) | ||
|
||
keyWindow.addConstraints([leadingConstraint, trailingConstraint, topConstraint, bottomConstraint]) | ||
}()) | ||
let leadingConstraint = NSLayoutConstraint(item: presentingView, attribute: .leading, relatedBy: .equal, toItem: containerView, attribute: .leading, multiplier: 1, constant: 0) | ||
let trailingConstraint = NSLayoutConstraint(item: presentingView, attribute: .trailing, relatedBy: .equal, toItem: containerView, attribute: .trailing, multiplier: 1, constant: 0) | ||
let topConstraint = NSLayoutConstraint(item: presentingView, attribute: .top, relatedBy: .equal, toItem: containerView, attribute: .top, multiplier: 1, constant: 0) | ||
let bottomConstraint = NSLayoutConstraint(item: presentingView, attribute: .bottom, relatedBy: .equal, toItem: containerView, attribute: .bottom, multiplier: 1, constant: 0) | ||
|
||
presentingView.addConstraints([leadingConstraint, trailingConstraint, topConstraint, bottomConstraint]) | ||
}()) | ||
self.presentedView = containerView | ||
} | ||
|
||
fileprivate func hide(_ fadeOutAnimation: FadeOutAnimation?) { | ||
for window in UIApplication.shared.windows { | ||
for item in window.subviews | ||
where item.restorationIdentifier == restorationIdentifier { | ||
if let fadeOutAnimation = fadeOutAnimation { | ||
fadeOutAnimation(item) { | ||
item.removeFromSuperview() | ||
} | ||
} else { | ||
item.removeFromSuperview() | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines should not have trailing whitespace. |
||
if let fadeOutAnimation = fadeOutAnimation, | ||
let presentedView = self.presentedView { | ||
fadeOutAnimation(presentedView) { | ||
self.presentedView?.removeFromSuperview() | ||
self.presentedView = nil | ||
} | ||
} else { | ||
self.presentedView?.removeFromSuperview() | ||
self.presentedView = nil | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines should not have trailing whitespace. |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines should not have trailing whitespace. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Limit vertical whitespace to a single empty line. Currently 2. |
||
} | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines should not have trailing whitespace.