This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ErrorView: UIView, NibLoadable { | |
| // MARK: Properties | |
| weak var delegate: ErrorViewDelegate? | |
| var animationDuration = 0.3 | |
| fileprivate(set) var isAnimating = false | |
| // MARK: - Overrides | |
| override func awakeFromNib() { | |
| super.awakeFromNib() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MARK: - ErrorDisplayable | |
| extension ErrorView: ErrorDisplayable { | |
| static func show<T: ErrorView>( | |
| fromViewController viewController: UIViewController, | |
| animated: Bool = true, | |
| completion: ((Bool) -> Swift.Void)? = nil) -> T { | |
| guard let subview = loadFromNib() as? T else { | |
| fatalError("The subview is expected to be of type \(T.self)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MARK: - ErrorAnimatable | |
| extension ErrorView: ErrorAnimatable { | |
| func playAnimation() { | |
| self.isAnimating = true | |
| } | |
| func stopAnimation() { | |
| self.isAnimating = false | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ProgressView: UIView, NibLoadable { | |
| // MARK: Properties | |
| var animationDuration = 0.3 | |
| fileprivate(set) var isAnimating = false | |
| // MARK: - Overrides | |
| override func awakeFromNib() { | |
| super.awakeFromNib() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol Localizable { | |
| var localizedMessage: String { get } | |
| } | |
| protocol Underlying { | |
| var underlying: Swift.Error? { get } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Error { | |
| var localizedMessage: String { | |
| if let error = self as? SignIn.Error { return error.underlying?.localizedMessage ?? error.localizedMessage } | |
| if let error = self as? Network.Error { return error.localizedMessage } | |
| if let error = self as? Store.Error { return error.localizedMessage } | |
| return L10n.commonErrorMessage // Fallback error message | |
| } | |
| var underlying: Swift.Error? { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct SignIn { | |
| enum Error: Swift.Error, Localizable, Underlying { | |
| case unknown(underlying: Swift.Error?) | |
| case invalidCredentials(underlying: Swift.Error?) | |
| case mailEmpty | |
| case mailIncorrect | |
| case passwordIncorrect | |
| case serviceInconsistency |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MARK: - UIViewController Default implementation | |
| extension FailableCore where Self: UIViewController { | |
| func showError(_ error: Swift.Error?) { | |
| let errorMessage = error?.localizedMessage ?? L10n.commonErrorMessage | |
| SwiftMessages.showAlert(title: errorMessage) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MARK: - ViewController Default implementation | |
| extension Failable where Self: ViewController { | |
| func showError<T: ErrorDisplayable>(_ error: Swift.Error?, errorView: T.Type, _ reloadable: Reloadable) { | |
| self.errorView = errorView.show(fromView: self.view, insets: .zero, animated: true, completion: nil) | |
| if var errorViewRetryable = self.errorView as? ErrorRetryable { | |
| errorViewRetryable.retry = { reloadable.reloadData() } | |
| errorViewRetryable.message = error?.localizedMessage | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ViewController: UIViewController { | |
| var errorView: ErrorView? | |
| var progressView: ProgressView? | |
| } |