Created
November 4, 2017 13:40
-
-
Save douglastaquary/a48b64727ebea4447689fd6341d98d4e to your computer and use it in GitHub Desktop.
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
| // | |
| // ConceptPopupManager.swift | |
| // ConceoptTec | |
| // | |
| // Created by Douglas Taquary on 04/11/17. | |
| // Copyright © 2017 Douglas Taquary. All rights reserved. | |
| // | |
| import UIKit | |
| import KLCPopup | |
| public struct ConpectPopupThemeProps { | |
| var backgroundColor:UIColor | |
| var textColor:UIColor | |
| var image:UIImage | |
| } | |
| public enum ConceptPopupTheme{ | |
| case success, warning, error, email, custom | |
| func backgroundColor() -> UIColor { | |
| switch self { | |
| case .success: return UIColor.nextLightGreen() | |
| case .warning: return UIColor.nextYellow() | |
| case .error: return UIColor.nextRed() | |
| case .email: return UIColor.nextLighterGray() | |
| case .custom: return UIColor.nextLighterGray() | |
| } | |
| } | |
| func textColor() -> UIColor { | |
| switch self { | |
| case .success: return UIColor.nextGray() | |
| case .warning: return UIColor.nextGray() | |
| case .error: return UIColor.nextWhite() | |
| case .email: return UIColor.nextGray() | |
| case .custom: return UIColor.nextGray() | |
| } | |
| } | |
| func image() -> UIImage? { | |
| switch self { | |
| case .success: return UIImage(named: "cashin-boleto-generated-icon") | |
| case .warning: return UIImage(named: "icon-face-serious") | |
| case .error: return UIImage(named: "vaquinha-temp-icon") | |
| case .email: return UIImage(named: "vaquinha-temp-icon") | |
| case .custom: return UIImage(named: "icon-face-serious") | |
| } | |
| } | |
| } | |
| public class ConceptPopupManager : PopupModelViewDelegate { | |
| public typealias PopupClosureType = () -> (Void) | |
| public typealias PopupResultClosureType = (String) -> (Void) | |
| var klcPopup: KLCPopup! | |
| //private (set) public var showing: Bool = false | |
| public var confirmClosure: PopupClosureType? | |
| public var dismissClousure: PopupClosureType? | |
| public var cancelClosure: PopupClosureType? | |
| public var resultClosure: PopupResultClosureType? | |
| public static let sharedInstance = ConceptPopupManager() | |
| fileprivate init() { | |
| } | |
| public func popupSuccess(_ message: String, confirmClosure: PopupClosureType?) { | |
| popupSimple(message, theme: .success, confirmClosure: confirmClosure) | |
| } | |
| public func popupWarning(_ message: String, height: CGFloat = 300.0, confirmClosure: PopupClosureType?) { | |
| popupSimple(message, theme: .warning, height: height, confirmClosure: confirmClosure) | |
| } | |
| public func popupError(_ message: String, confirmClosure: PopupClosureType?) { | |
| popupSimple(message, theme: .error, confirmClosure: confirmClosure) | |
| } | |
| public func popupConfirm(_ message: String, confirmTitle: String = "Confirmar", cancelTitle: String = "Cancelar", confirmClosure: @escaping PopupClosureType, cancelClosure: @escaping PopupClosureType) { | |
| popupSimple(message, theme: .warning, confirmTitle: confirmTitle, cancelTitle: cancelTitle, confirmClosure: confirmClosure, cancelClosure: cancelClosure) | |
| } | |
| public func popupConfirm(_ message: String, confirmTitle: String = "Confirmar", image: String, confirmClosure: @escaping PopupClosureType, cancelClosure: @escaping PopupClosureType) { | |
| popupCustom(message, theme: .warning, confirmTitle: confirmTitle, color: NextPopupTheme.warning.backgroundColor(), imageName: image, buttonStyle: NextButtonStyle.white, confirmClosure: confirmClosure, cancelClosure: cancelClosure) | |
| } | |
| public func popupConfirm(_ message: NSAttributedString, confirmTitle: String = "Confirmar", image: String, confirmClosure: @escaping PopupClosureType, cancelClosure: @escaping PopupClosureType) { | |
| popupCustom(message: message, theme: .warning, confirmTitle: confirmTitle, color: NextPopupTheme.warning.backgroundColor(), imageName: image, buttonStyle: NextButtonStyle.white, confirmClosure: confirmClosure, cancelClosure: cancelClosure) | |
| } | |
| public func popupEmail(_ message: String, resultClosure: PopupResultClosureType?) { | |
| popupInput(message, theme: .email, resultClosure: resultClosure) | |
| } | |
| public func popupSimple( | |
| _ message: String, | |
| theme: ConceptPopupTheme, | |
| confirmTitle: String = "OK", | |
| cancelTitle: String = "Cancelar", | |
| height: CGFloat = 300.0, | |
| confirmClosure: PopupClosureType?, | |
| cancelClosure: PopupClosureType? = nil) { | |
| self.confirmClosure = confirmClosure | |
| self.cancelClosure = cancelClosure | |
| var frame = UIScreen.main.bounds | |
| frame = frame.insetBy(dx: 30, dy: 0) | |
| frame.size.height = height | |
| let hasCancelClousure = cancelClosure != nil | |
| if !hasCancelClousure { | |
| self.dismissClousure = confirmClosure | |
| } | |
| let popup = SimpleAlert( | |
| frame: frame, | |
| theme: theme, | |
| delegate: self, | |
| message: message, | |
| cancelTitle: cancelTitle, | |
| confirmTitle: confirmTitle, | |
| hasCancelButton: hasCancelClousure | |
| ) | |
| present(popup) | |
| } | |
| public func popupCustom( | |
| _ message: String, | |
| theme: NextPopupTheme, | |
| confirmTitle: String = "OK", | |
| cancelTitle: String = "Cancelar", | |
| color: UIColor, | |
| imageName: String, | |
| buttonStyle: NextButtonStyle = .default, | |
| confirmClosure: PopupClosureType?, | |
| cancelClosure: PopupClosureType? = nil | |
| ) { | |
| self.confirmClosure = confirmClosure | |
| self.cancelClosure = cancelClosure | |
| var frame = UIScreen.main.bounds | |
| frame.size.width = 260 | |
| frame.size.height = 320 | |
| let popup = SimpleAlert( | |
| frame: frame, | |
| theme: theme, | |
| delegate: self, | |
| message: message, | |
| cancelTitle: cancelTitle, | |
| confirmTitle: confirmTitle, | |
| color: color, | |
| imageName: imageName, | |
| hasCancelButton: cancelClosure != nil, | |
| buttonStyle: buttonStyle | |
| ) | |
| present(popup) | |
| } | |
| public func popupCustom ( | |
| message: NSAttributedString, | |
| theme: ConceptPopupTheme, | |
| confirmTitle: String = "OK", | |
| cancelTitle: String = "Cancelar", | |
| color: UIColor, | |
| imageName: String, | |
| buttonStyle: NextButtonStyle = .default, //criar custom button style | |
| confirmClosure: PopupClosureType?, | |
| cancelClosure: PopupClosureType? = nil | |
| ) { | |
| self.confirmClosure = confirmClosure | |
| self.cancelClosure = cancelClosure | |
| var frame = UIScreen.main.bounds | |
| frame.size.width = 260 | |
| frame.size.height = 320 | |
| let popup = SimpleAlert( | |
| frame: frame, | |
| theme: theme, | |
| delegate: self, | |
| message: message, | |
| cancelTitle: cancelTitle, | |
| confirmTitle: confirmTitle, | |
| color: color, | |
| imageName: imageName, | |
| hasCancelButton: cancelClosure != nil, | |
| buttonStyle: buttonStyle | |
| ) | |
| present(popup) | |
| } | |
| public func popupInput( | |
| _ message: String, | |
| theme: ConceptPopupTheme, | |
| resultClosure: PopupResultClosureType?, | |
| cancelClosure: PopupClosureType? = nil) { | |
| self.resultClosure = resultClosure | |
| self.cancelClosure = cancelClosure | |
| var frame = UIScreen.main.bounds | |
| frame = frame.insetBy(dx: 15, dy: 0) | |
| frame.size.height = 320 | |
| let popup = InputAlert(frame: frame) | |
| popup.theme = theme | |
| popup.delegate = self | |
| // popup.configureView(message, buttonLabel: "Enviar") | |
| present(popup) | |
| } | |
| public func popupForm( | |
| _ message: String, | |
| color: UIColor, | |
| imageName: String, | |
| cancelClosure: PopupClosureType?, | |
| resultClosure: PopupResultClosureType?) { | |
| } | |
| fileprivate func present(_ popup: UIView) { | |
| //if !showing { | |
| klcPopup = KLCPopup(contentView: popup, | |
| showType: .bounceInFromBottom, | |
| dismissType: .bounceOutToBottom, | |
| maskType: .dimmed, | |
| dismissOnBackgroundTouch: true, | |
| dismissOnContentTouch: false) | |
| klcPopup.show() | |
| klcPopup.didFinishDismissingCompletion = self.dismissClousure | |
| //showing = true | |
| //} | |
| } | |
| internal func onPopupConfirmation() { | |
| KLCPopup.dismissAllPopups() | |
| //klcPopup.dismiss(true) | |
| //showing = false | |
| klcPopup.didFinishDismissingCompletion = confirmClosure | |
| } | |
| internal func onPopupConfirmationResult(_ result: String) { | |
| //klcPopup.dismiss(true) | |
| KLCPopup.dismissAllPopups() | |
| klcPopup.didFinishDismissingCompletion = { [unowned self] in | |
| //self.showing = false | |
| if let resultClosure = self.resultClosure { | |
| resultClosure(result) | |
| } | |
| } | |
| } | |
| internal func onPopupCancelation() { | |
| KLCPopup.dismissAllPopups() | |
| //klcPopup.dismiss(true) | |
| //showing = false | |
| klcPopup.didFinishDismissingCompletion = cancelClosure | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment