Skip to content

Commit

Permalink
format swift source
Browse files Browse the repository at this point in the history
  • Loading branch information
Adar Porat committed Sep 4, 2020
1 parent 2d54e7e commit e735756
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 83 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.2
10 changes: 5 additions & 5 deletions KKProgressToolbar.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
103 changes: 52 additions & 51 deletions KKProgressToolbar/KKProgressToolbar.swift
Original file line number Diff line number Diff line change
@@ -1,148 +1,150 @@
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)
button.translatesAutoresizingMaskIntoConstraints = false
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)

addSubview(mainBackgroundView)
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 {
Expand All @@ -154,22 +156,22 @@ 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?()
}
}
} else {
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 {
Expand All @@ -181,18 +183,17 @@ 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?()
}
}
} else {
completion?()
}
}
@objc public func didCancelButtonPressed(_ sender: Any?) {

@objc public func didCancelButtonPressed(_: Any?) {
actionDelegate?.didCancelButtonPressed(self)
}

}
6 changes: 2 additions & 4 deletions KKProgressToolbarTests/ProgressToolbarTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand All @@ -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.
}
}

}
9 changes: 5 additions & 4 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -15,6 +15,6 @@ SPEC CHECKSUMS:
GTProgressBar: a480283ecb0ada50de16c71e634892826928f640
SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb

PODFILE CHECKSUM: abca5ce242a26142784e42f0e498a30bd395f2d9
PODFILE CHECKSUM: 989309dde513cf19341aff547928388aede592c6

COCOAPODS: 1.10.0.beta.2
6 changes: 3 additions & 3 deletions example/KKProgressToolbarExample/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
23 changes: 10 additions & 13 deletions example/KKProgressToolbarExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {}
}

0 comments on commit e735756

Please sign in to comment.