From e7357565ea622d74ff3f664748527006663fb684 Mon Sep 17 00:00:00 2001 From: Adar Porat Date: Fri, 4 Sep 2020 11:29:25 -0500 Subject: [PATCH] format swift source --- .swift-version | 1 + KKProgressToolbar.podspec | 10 +- KKProgressToolbar/KKProgressToolbar.swift | 103 +++++++++--------- .../ProgressToolbarTests.swift | 6 +- Podfile | 9 +- Podfile.lock | 6 +- .../AppDelegate.swift | 6 +- .../ViewController.swift | 23 ++-- 8 files changed, 81 insertions(+), 83 deletions(-) create mode 100644 .swift-version diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..ef425ca --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +5.2 diff --git a/KKProgressToolbar.podspec b/KKProgressToolbar.podspec index 924bbeb..3827729 100644 --- a/KKProgressToolbar.podspec +++ b/KKProgressToolbar.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'KKProgressToolbar' s.module_name = 'KKProgressToolbar' - s.version = '3.0.0' + s.version = '3.0.2' s.summary = 'KKProgressToolbar is an iOS drop-in class that displays a translucent UIToolbar with a progress indicator' s.homepage = 'https://github.com/aporat/KKProgressToolbar' s.license = 'MIT' @@ -11,8 +11,8 @@ Pod::Spec.new do |s| s.requires_arc = true s.source = { :git => 'https://github.com/aporat/KKProgressToolbar.git', :tag => s.version.to_s } s.source_files = 'KKProgressToolbar/*.{swift}' - s.swift_version = '5.0' - s.dependency 'GTProgressBar' - s.dependency 'SnapKit' - + s.swift_version = '5.2' + s.dependency 'GTProgressBar', "~> 0.3" + s.dependency 'SnapKit', "~> 5.0" + end diff --git a/KKProgressToolbar/KKProgressToolbar.swift b/KKProgressToolbar/KKProgressToolbar.swift index e27998e..2f7570f 100644 --- a/KKProgressToolbar/KKProgressToolbar.swift +++ b/KKProgressToolbar/KKProgressToolbar.swift @@ -1,27 +1,27 @@ -import UIKit import GTProgressBar import SnapKit +import UIKit -public protocol KKProgressToolbarDelegate: class { +public protocol KKProgressToolbarDelegate: AnyObject { func didCancelButtonPressed(_ toolbar: KKProgressToolbar) } public final class KKProgressToolbar: UIView { - fileprivate var didSetupConstraints = false fileprivate let orientationDidChange = UIDevice.orientationDidChangeNotification - weak public var actionDelegate: KKProgressToolbarDelegate? + public weak var actionDelegate: KKProgressToolbarDelegate? public var isShown = false - + public var text: String? { didSet { titleLabel.text = text } } - + // MARK: - UI Elements - lazy fileprivate var stopButton: UIButton = { + + fileprivate lazy var stopButton: UIButton = { let button = UIButton(type: .custom) button.backgroundColor = .clear button.setImage(UIImage(named: "toolbar-stop"), for: .normal) @@ -29,88 +29,90 @@ public final class KKProgressToolbar: UIView { button.addTarget(self, action: #selector(didCancelButtonPressed(_:)), for: .touchUpInside) return button }() - + // MARK: - UI Elements - lazy fileprivate var mainBackgroundView: UIView = { + + fileprivate lazy var mainBackgroundView: UIView = { let view = UIView() view.backgroundColor = .black view.alpha = 0.75 - + return view }() - - lazy fileprivate var titleLabel: UILabel = { + + fileprivate lazy var titleLabel: UILabel = { let view = UILabel() view.font = UIFont.systemFont(ofSize: 13) view.textColor = .white view.textAlignment = .center view.backgroundColor = .clear - + return view }() - - lazy public var progressBar: GTProgressBar = { + + public lazy var progressBar: GTProgressBar = { let view = GTProgressBar() view.displayLabel = true view.font = UIFont.systemFont(ofSize: 13) view.labelTextColor = .white view.progressLabelInsetRight = 15 view.barFillInset = 1 - + return view }() - + // MARK: - UIView - required override init(frame: CGRect) { + + override required init(frame: CGRect) { super.init(frame: frame) setupSubviews() } - - required init?(coder aDecoder: NSCoder) { + + @available(*, unavailable) + required init?(coder _: NSCoder) { fatalError("init(coder:) has not been implemented") } - + override public func awakeFromNib() { super.awakeFromNib() setupSubviews() } - + deinit { - NotificationCenter.default.removeObserver(self) + NotificationCenter.default.removeObserver(self) } - + override public func updateConstraints() { super.updateConstraints() - + if !didSetupConstraints { - mainBackgroundView.snp.makeConstraints { make in make.edges.equalTo(self) } - + stopButton.snp.makeConstraints { make in make.centerY.equalTo(self) make.size.equalTo(25) make.trailing.equalTo(self).offset(-14) } - + titleLabel.snp.makeConstraints { make in make.top.equalTo(self).offset(5) make.height.equalTo(16) make.centerX.equalTo(self) } - + progressBar.snp.makeConstraints { make in make.top.equalTo(titleLabel.snp.bottom).offset(2) make.height.equalTo(12) make.leading.equalTo(self).offset(14) make.trailing.equalTo(stopButton.snp.leading).offset(-10) } - + didSetupConstraints = true } } - + fileprivate func setupSubviews() { NotificationCenter.default.addObserver(self, selector: #selector(setupPosition), name: orientationDidChange, object: nil) @@ -118,31 +120,31 @@ public final class KKProgressToolbar: UIView { addSubview(stopButton) addSubview(titleLabel) addSubview(progressBar) - + setNeedsUpdateConstraints() } - + @objc fileprivate func setupPosition() { - if self.isShown { - self.hide(false) { + if isShown { + hide(false) { self.isHidden = false self.show(false) } } else { - self.setNeedsLayout() + setNeedsLayout() } } - + public func show(_ animated: Bool, completion: (() -> Void)? = nil) { if !isShown { isShown = true - + stopButton.isEnabled = true - + if let superview = self.superview { - self.frame = CGRect(x: 0, y: superview.bounds.size.height, width: superview.bounds.size.width, height: 55) + frame = CGRect(x: 0, y: superview.bounds.size.height, width: superview.bounds.size.width, height: 55) } - + if animated { UIView.animate(withDuration: 0.4, delay: 0.0, options: [], animations: { if let superview = self.superview { @@ -154,8 +156,8 @@ public final class KKProgressToolbar: UIView { } } else { if let superview = self.superview { - self.frame = CGRect(x: 0, y: superview.bounds.size.height - 55, width: superview.bounds.size.width, height: 55) - self.isHidden = false + frame = CGRect(x: 0, y: superview.bounds.size.height - 55, width: superview.bounds.size.width, height: 55) + isHidden = false completion?() } } @@ -163,13 +165,13 @@ public final class KKProgressToolbar: UIView { completion?() } } - + public func hide(_ animated: Bool, completion: (() -> Void)? = nil) { if isShown { isShown = false - + stopButton.isEnabled = false - + if animated { UIView.animate(withDuration: 0.4, delay: 1.0, options: [], animations: { if let superview = self.superview { @@ -181,8 +183,8 @@ public final class KKProgressToolbar: UIView { } } else { if let superview = self.superview { - self.frame = CGRect(x: 0, y: superview.bounds.size.height, width: superview.bounds.size.width, height: 55) - self.isHidden = true + frame = CGRect(x: 0, y: superview.bounds.size.height, width: superview.bounds.size.width, height: 55) + isHidden = true completion?() } } @@ -190,9 +192,8 @@ public final class KKProgressToolbar: UIView { completion?() } } - - @objc public func didCancelButtonPressed(_ sender: Any?) { + + @objc public func didCancelButtonPressed(_: Any?) { actionDelegate?.didCancelButtonPressed(self) } - } diff --git a/KKProgressToolbarTests/ProgressToolbarTests.swift b/KKProgressToolbarTests/ProgressToolbarTests.swift index 8219a59..92eb496 100644 --- a/KKProgressToolbarTests/ProgressToolbarTests.swift +++ b/KKProgressToolbarTests/ProgressToolbarTests.swift @@ -6,11 +6,10 @@ // Copyright © 2020 Adar Porat. All rights reserved. // -import XCTest @testable import KKProgressToolbar +import XCTest class ProgressToolbarTests: XCTestCase { - override func setUpWithError() throws { // Put setup code here. This method is called before the invocation of each test method in the class. } @@ -26,9 +25,8 @@ class ProgressToolbarTests: XCTestCase { func testPerformanceExample() throws { // This is an example of a performance test case. - self.measure { + measure { // Put the code you want to measure the time of here. } } - } diff --git a/Podfile b/Podfile index 4b6ba1f..6d77365 100644 --- a/Podfile +++ b/Podfile @@ -4,11 +4,12 @@ source 'https://github.com/CocoaPods/Specs.git' use_frameworks! target 'KKProgressToolbar' do - pod 'GTProgressBar' - pod 'SnapKit' + pod 'GTProgressBar', "~> 0.3" + pod 'SnapKit', "~> 5" end target 'KKProgressToolbarTests' do - pod 'GTProgressBar' - pod 'SnapKit' + pod 'GTProgressBar', "~> 0.3" + pod 'SnapKit', "~> 5" + end diff --git a/Podfile.lock b/Podfile.lock index dc55fc1..e82fd3f 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -3,8 +3,8 @@ PODS: - SnapKit (5.0.1) DEPENDENCIES: - - GTProgressBar - - SnapKit + - GTProgressBar (~> 0.3) + - SnapKit (~> 5) SPEC REPOS: https://github.com/CocoaPods/Specs.git: @@ -15,6 +15,6 @@ SPEC CHECKSUMS: GTProgressBar: a480283ecb0ada50de16c71e634892826928f640 SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb -PODFILE CHECKSUM: abca5ce242a26142784e42f0e498a30bd395f2d9 +PODFILE CHECKSUM: 989309dde513cf19341aff547928388aede592c6 COCOAPODS: 1.10.0.beta.2 diff --git a/example/KKProgressToolbarExample/AppDelegate.swift b/example/KKProgressToolbarExample/AppDelegate.swift index 6e555f1..1ae5781 100644 --- a/example/KKProgressToolbarExample/AppDelegate.swift +++ b/example/KKProgressToolbarExample/AppDelegate.swift @@ -11,9 +11,9 @@ import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + + func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. - return true + true } } diff --git a/example/KKProgressToolbarExample/ViewController.swift b/example/KKProgressToolbarExample/ViewController.swift index b460697..e36c2fb 100644 --- a/example/KKProgressToolbarExample/ViewController.swift +++ b/example/KKProgressToolbarExample/ViewController.swift @@ -6,12 +6,11 @@ // Copyright © 2020 Adar Porat. All rights reserved. // -import UIKit import KKProgressToolbar +import UIKit class ViewController: UIViewController { - - lazy fileprivate var loadingToolbar: KKProgressToolbar = { + fileprivate lazy var loadingToolbar: KKProgressToolbar = { let view = KKProgressToolbar() view.progressBar.barBorderColor = .black view.progressBar.barBackgroundColor = .black @@ -20,30 +19,28 @@ class ViewController: UIViewController { view.isHidden = true return view }() - + override func viewDidLoad() { super.viewDidLoad() - + loadingToolbar.actionDelegate = self loadingToolbar.frame = CGRect(x: 0, y: view.bounds.size.height, width: view.bounds.size.width, height: 55) view.addSubview(loadingToolbar) - } - - @IBAction func showToolbar(_ sender: Any) { + + @IBAction func showToolbar(_: Any) { loadingToolbar.show(true, completion: nil) loadingToolbar.text = NSLocalizedString("Loading...", comment: "") loadingToolbar.progressBar.progress = 0.5 } - - @IBAction func hideToolbar(_ sender: Any) { + + @IBAction func hideToolbar(_: Any) { loadingToolbar.hide(true, completion: nil) } } // MARK: - KKProgressToolbarDelegate + extension ViewController: KKProgressToolbarDelegate { - func didCancelButtonPressed(_ toolbar: KKProgressToolbar) { - - } + func didCancelButtonPressed(_: KKProgressToolbar) {} }