Skip to content

Commit bb2305e

Browse files
committed
style: 调整代码风格
Former-commit-id: e4cc35378b85bcef8d3a018d0ca1cc1fa1664137
1 parent 8507ee2 commit bb2305e

7 files changed

+73
-38
lines changed

LPHUD.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'LPHUD'
3-
s.version = '1.2.5'
3+
s.version = '1.2.6'
44
s.summary = 'An iOS activity indicator view.'
55
s.description = <<-DESC
66
LPHUD is an iOS drop-in class that displays a translucent HUD

Podfile.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- LPHUD (1.2.5)
2+
- LPHUD (1.2.6)
33

44
DEPENDENCIES:
55
- LPHUD (from `./`)
@@ -9,8 +9,8 @@ EXTERNAL SOURCES:
99
:path: "./"
1010

1111
SPEC CHECKSUMS:
12-
LPHUD: d8d6b51f84e03a78f77043e4a9a27273227f5b94
12+
LPHUD: bae4ed669fb72a7ad65d2298a83ecf9acb54f52d
1313

1414
PODFILE CHECKSUM: cb96999e54d9b7d880a0dc796c7465854b54539c
1515

16-
COCOAPODS: 1.11.2
16+
COCOAPODS: 1.11.3

Sources/Classes/BackgroundView.swift

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// This source code is licensed under the MIT-style license found in the
99
// LICENSE file in the root directory of this source tree.
1010
//
11+
// Forked from https://github.com/liam-i/HUD
12+
// Version 1.2.5
13+
//
1114

1215
import UIKit
1316

Sources/Classes/BarProgressView.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import UIKit
1313

1414
/// A flat bar progress view.
1515
public class BarProgressView: UIView, Progressive {
16-
1716
// MARK: - Properties
1817

1918
/// Progress (0.0 to 1.0)
@@ -66,6 +65,7 @@ public class BarProgressView: UIView, Progressive {
6665

6766
// MARK: - Drawing
6867

68+
// swiftlint:disable function_body_length
6969
public override func draw(_ rect: CGRect) {
7070
guard let context = UIGraphicsGetCurrentContext() else { return }
7171
context.setLineWidth(2.0)
@@ -96,7 +96,6 @@ public class BarProgressView: UIView, Progressive {
9696

9797
// Progress in the middle area
9898
if amount >= radius + 4 && amount <= (rect.size.width - radius - 4) {
99-
10099
context.move(to: CGPoint(x: 4.0, y: rect.height / 2.0))
101100
context.addArc(tangent1End: CGPoint(x: 4.0, y: 4.0),
102101
tangent2End: CGPoint(x: radius + 4, y: 4.0),
@@ -116,7 +115,6 @@ public class BarProgressView: UIView, Progressive {
116115

117116
// Progress in the right arc
118117
else if amount > radius + 4 {
119-
120118
let x = amount - (rect.width - radius - 4.0)
121119
context.move(to: CGPoint(x: 4.0, y: rect.height / 2.0))
122120
context.addArc(tangent1End: CGPoint(x: 4.0, y: 4.0),
@@ -157,7 +155,6 @@ public class BarProgressView: UIView, Progressive {
157155

158156
// Progress is in the left arc
159157
else if amount < radius + 4 && amount > 0 {
160-
161158
context.move(to: CGPoint(x: 4.0, y: rect.height / 2.0))
162159
context.addArc(tangent1End: CGPoint(x: 4.0, y: 4.0),
163160
tangent2End: CGPoint(x: radius + 4, y: 4.0),
@@ -173,4 +170,5 @@ public class BarProgressView: UIView, Progressive {
173170
context.fillPath()
174171
}
175172
}
173+
// swiftlint:enable function_body_length
176174
}

Sources/Classes/HUD.swift

+62-29
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ open class HUD: UIView {
2929
/// Called after the HUD is hidden.
3030
public var completionBlock: (() -> Void)?
3131

32-
/// The minimum time (in seconds) that the HUD is shown. This avoids the problem of the HUD being shown and than instantly hidden. Defaults to 0 (no minimum show time).
32+
/// The minimum time (in seconds) that the HUD is shown. This avoids the problem of the HUD being shown and than instantly hidden.
33+
/// Defaults to 0 (no minimum show time).
3334
/// - Note: The graceTime needs to be set before the hud is shown. You thus can't use `show(to:animated:)`,
3435
/// but instead need to alloc / init the HUD, configure the grace time and than show it manually.
3536
public var graceTime: TimeInterval = 0.0
3637

37-
/// The minimum time (in seconds) that the HUD is shown. This avoids the problem of the HUD being shown and than instantly hidden. Defaults to 0 (no minimum show time).
38+
/// The minimum time (in seconds) that the HUD is shown. This avoids the problem of the HUD being shown and than instantly hidden.
39+
/// Defaults to 0 (no minimum show time).
3840
public var minShowTime: TimeInterval = 0.0
3941

4042
/// Removes the HUD from its parent view when hidden. Defaults to true.
@@ -49,7 +51,8 @@ open class HUD: UIView {
4951
}
5052
}
5153

52-
/// A color that gets forwarded to all labels and supported indicators. Also sets the tintColor for custom views. Defaults to semi-translucent black.
54+
/// A color that gets forwarded to all labels and supported indicators. Also sets the tintColor for custom views.
55+
/// Defaults to semi-translucent black.
5356
public var contentColor: UIColor = {
5457
if #available(iOS 13.0, tvOS 13.0, *) {
5558
return UIColor.label.withAlphaComponent(0.7)
@@ -65,7 +68,8 @@ open class HUD: UIView {
6568
/// The animation type that should be used when the HUD is shown and hidden.
6669
public var animationType: HUDAnimation = .fade
6770

68-
/// The bezel offset relative to the center of the view. You can use `HUD.maxOffset` and `-HUD.maxOffset` to move the HUD all the way to the screen edge in each direction.
71+
/// The bezel offset relative to the center of the view. You can use `HUD.maxOffset` and `-HUD.maxOffset`
72+
/// to move the HUD all the way to the screen edge in each direction.
6973
/// E.g., `CGPoint(x: 0.0, y: HUD.maxOffset)` would position the HUD centered on the bottom edge.
7074
public var offset: CGPoint = .zero {
7175
didSet {
@@ -144,7 +148,8 @@ open class HUD: UIView {
144148
}
145149
}
146150

147-
/// A label that holds an optional short message to be displayed below the activity indicator. The HUD is automatically resized to fit the entire text.
151+
/// A label that holds an optional short message to be displayed below the activity indicator.
152+
/// The HUD is automatically resized to fit the entire text.
148153
public lazy var label = UILabel(frame: .zero)
149154

150155
/// A label that holds an optional details message displayed below the labelText message. The details text can span multiple lines.
@@ -260,7 +265,8 @@ extension HUD {
260265
if let showStarted = showStarted, minShowTime > 0.0 {
261266
let interv = Date().timeIntervalSince(showStarted)
262267
if interv < minShowTime {
263-
let timer = Timer(timeInterval: minShowTime - interv, target: self, selector: #selector(handleMinShowTimer), userInfo: nil, repeats: false)
268+
let timer = Timer(timeInterval: minShowTime - interv, target: self,
269+
selector: #selector(handleMinShowTimer), userInfo: nil, repeats: false)
264270
RunLoop.current.add(timer, forMode: .common)
265271
minShowTimer = timer
266272
return
@@ -315,7 +321,7 @@ extension HUD {
315321

316322
if animated && showStarted != nil {
317323
showStarted = nil
318-
animate(in: false, type: animationType, completion: { (finished) in
324+
animate(in: false, type: animationType, completion: { _ in
319325
self.done()
320326
})
321327
} else {
@@ -343,7 +349,8 @@ extension HUD {
343349
bezelView.transform = large
344350
}
345351

346-
UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.0, options: .beginFromCurrentState, animations: {
352+
UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 1.0,
353+
initialSpringVelocity: 0.0, options: .beginFromCurrentState, animations: {
347354
if animating {
348355
self.bezelView.transform = CGAffineTransform.identity
349356
} else if !animating && type == .zoomIn {
@@ -378,19 +385,22 @@ extension HUD {
378385
// MARK: - Timer callbacks
379386

380387
extension HUD {
381-
@objc private func handleHideTimer(_ timer: Timer) {
388+
@objc
389+
private func handleHideTimer(_ timer: Timer) {
382390
let animated = timer.userInfo as? Bool ?? true
383391
hide(animated: animated)
384392
}
385393

386-
@objc private func handleGraceTimer(_ timer: Timer) {
394+
@objc
395+
private func handleGraceTimer(_ timer: Timer) {
387396
// Show the HUD only if the task is still running
388397
if !isFinished {
389398
show(usingAnimation: useAnimation)
390399
}
391400
}
392401

393-
@objc private func handleMinShowTimer(_ timer: Timer) {
402+
@objc
403+
private func handleMinShowTimer(_ timer: Timer) {
394404
hide(usingAnimation: useAnimation)
395405
}
396406
}
@@ -468,6 +478,7 @@ extension HUD {
468478
bezelView.addSubview(bottomSpacer)
469479
}
470480

481+
// swiftlint:disable function_body_length
471482
private func updateIndicators() {
472483
switch mode {
473484
case .indeterminate:
@@ -527,6 +538,7 @@ extension HUD {
527538
updateViews(for: contentColor)
528539
setNeedsUpdateConstraints()
529540
}
541+
// swiftlint:enable function_body_length
530542

531543
private func updateViews(for color: UIColor) {
532544
label.textColor = color
@@ -574,6 +586,7 @@ extension HUD {
574586
// MARK: - Layout
575587

576588
extension HUD {
589+
// swiftlint:disable function_body_length
577590
open override func updateConstraints() {
578591
var bezelConstraints: [NSLayoutConstraint] = []
579592
let metrics = ["margin": margin]
@@ -594,63 +607,80 @@ extension HUD {
594607

595608
// Center bezel in container (self), applying the offset if set
596609
var centeringConstraints: [NSLayoutConstraint] = []
597-
centeringConstraints.append(NSLayoutConstraint(item: bezelView, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1.0, constant: offset.x))
598-
centeringConstraints.append(NSLayoutConstraint(item: bezelView, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: offset.y))
610+
centeringConstraints.append(NSLayoutConstraint(item: bezelView, attribute: .centerX, relatedBy: .equal, toItem: self,
611+
attribute: .centerX, multiplier: 1.0, constant: offset.x))
612+
centeringConstraints.append(NSLayoutConstraint(item: bezelView, attribute: .centerY, relatedBy: .equal, toItem: self,
613+
attribute: .centerY, multiplier: 1.0, constant: offset.y))
599614
apply(priority: UILayoutPriority(rawValue: 998.0), to: centeringConstraints)
600615
addConstraints(centeringConstraints)
601616

602617
// Ensure minimum side margin is kept
603618
var sideConstraints: [NSLayoutConstraint] = []
604-
sideConstraints.append(contentsOf: NSLayoutConstraint.constraints(withVisualFormat: "|-(>=margin)-[bezelView]-(>=margin)-|", options: NSLayoutConstraint.FormatOptions(rawValue: 0), metrics: metrics, views: ["bezelView": bezelView]))
605-
sideConstraints.append(contentsOf: NSLayoutConstraint.constraints(withVisualFormat: "V:|-(>=margin)-[bezelView]-(>=margin)-|", options: NSLayoutConstraint.FormatOptions(rawValue: 0), metrics: metrics, views: ["bezelView": bezelView]))
619+
sideConstraints.append(contentsOf: NSLayoutConstraint.constraints(withVisualFormat: "|-(>=margin)-[bezelView]-(>=margin)-|",
620+
options: NSLayoutConstraint.FormatOptions(rawValue: 0),
621+
metrics: metrics, views: ["bezelView": bezelView]))
622+
sideConstraints.append(contentsOf: NSLayoutConstraint.constraints(withVisualFormat: "V:|-(>=margin)-[bezelView]-(>=margin)-|",
623+
options: NSLayoutConstraint.FormatOptions(rawValue: 0),
624+
metrics: metrics, views: ["bezelView": bezelView]))
606625
apply(priority: UILayoutPriority(rawValue: 999.0), to: sideConstraints)
607626
addConstraints(sideConstraints)
608627

609628
// Minimum bezel size, if set
610629
if !minSize.equalTo(.zero) {
611630
var minSizeConstraints: [NSLayoutConstraint] = []
612-
minSizeConstraints.append(NSLayoutConstraint(item: bezelView, attribute: .width, relatedBy: .greaterThanOrEqual, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: minSize.width))
613-
minSizeConstraints.append(NSLayoutConstraint(item: bezelView, attribute: .height, relatedBy: .greaterThanOrEqual, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: minSize.height))
631+
minSizeConstraints.append(NSLayoutConstraint(item: bezelView, attribute: .width, relatedBy: .greaterThanOrEqual, toItem: nil,
632+
attribute: .notAnAttribute, multiplier: 1.0, constant: minSize.width))
633+
minSizeConstraints.append(NSLayoutConstraint(item: bezelView, attribute: .height, relatedBy: .greaterThanOrEqual, toItem: nil,
634+
attribute: .notAnAttribute, multiplier: 1.0, constant: minSize.height))
614635
apply(priority: UILayoutPriority(rawValue: 997.0), to: minSizeConstraints)
615636
bezelConstraints.append(contentsOf: minSizeConstraints)
616637
}
617638

618639
// Square aspect ratio, if set
619640
if isSquare {
620-
let square = NSLayoutConstraint(item: bezelView, attribute: .height, relatedBy: .equal, toItem: bezelView, attribute: .width, multiplier: 1.0, constant: 0.0)
641+
let square = NSLayoutConstraint(item: bezelView, attribute: .height, relatedBy: .equal, toItem: bezelView,
642+
attribute: .width, multiplier: 1.0, constant: 0.0)
621643
square.priority = UILayoutPriority(rawValue: 997.0)
622644
bezelConstraints.append(square)
623645
}
624646

625647
// Top and bottom spacing
626-
topSpacer.addConstraint(NSLayoutConstraint(item: topSpacer, attribute: .height, relatedBy: .greaterThanOrEqual, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: topBottomMargin))
627-
bottomSpacer.addConstraint(NSLayoutConstraint(item: bottomSpacer, attribute: .height, relatedBy: .greaterThanOrEqual, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: topBottomMargin))
648+
topSpacer.addConstraint(NSLayoutConstraint(item: topSpacer, attribute: .height, relatedBy: .greaterThanOrEqual, toItem: nil,
649+
attribute: .notAnAttribute, multiplier: 1.0, constant: topBottomMargin))
650+
bottomSpacer.addConstraint(NSLayoutConstraint(item: bottomSpacer, attribute: .height, relatedBy: .greaterThanOrEqual, toItem: nil,
651+
attribute: .notAnAttribute, multiplier: 1.0, constant: topBottomMargin))
628652

629653
// Top and bottom spaces should be equal
630-
bezelConstraints.append(NSLayoutConstraint(item: topSpacer, attribute: .height, relatedBy: .equal, toItem: bottomSpacer, attribute: .height, multiplier: 1.0, constant: 0.0))
654+
bezelConstraints.append(NSLayoutConstraint(item: topSpacer, attribute: .height, relatedBy: .equal, toItem: bottomSpacer,
655+
attribute: .height, multiplier: 1.0, constant: 0.0))
631656

632657
// Layout subviews in bezel
633658
var paddingConstraints: [NSLayoutConstraint] = []
634659
for (idx, view) in subviews.enumerated() {
635-
636660
// Center in bezel
637-
bezelConstraints.append(NSLayoutConstraint(item: view, attribute: .centerX, relatedBy: .equal, toItem: bezelView, attribute: .centerX, multiplier: 1.0, constant: 0.0))
661+
bezelConstraints.append(NSLayoutConstraint(item: view, attribute: .centerX, relatedBy: .equal, toItem: bezelView,
662+
attribute: .centerX, multiplier: 1.0, constant: 0.0))
638663

639664
// Ensure the minimum edge margin is kept
640-
bezelConstraints.append(contentsOf: NSLayoutConstraint.constraints(withVisualFormat: "|-(>=margin)-[view]-(>=margin)-|", options: NSLayoutConstraint.FormatOptions(rawValue: 0), metrics: metrics, views: ["view": view]))
665+
bezelConstraints.append(contentsOf: NSLayoutConstraint.constraints(withVisualFormat: "|-(>=margin)-[view]-(>=margin)-|",
666+
options: NSLayoutConstraint.FormatOptions(rawValue: 0),
667+
metrics: metrics, views: ["view": view]))
641668

642669
// Element spacing
643670
if idx == 0 {
644671
// First, ensure spacing to bezel edge
645-
bezelConstraints.append(NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal, toItem: bezelView, attribute: .top, multiplier: 1.0, constant: 0.0))
672+
bezelConstraints.append(NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal, toItem: bezelView,
673+
attribute: .top, multiplier: 1.0, constant: 0.0))
646674
} else if idx == subviews.count - 1 {
647675
// Last, ensure spacing to bezel edge
648-
bezelConstraints.append(NSLayoutConstraint(item: view, attribute: .bottom, relatedBy: .equal, toItem: bezelView, attribute: .bottom, multiplier: 1.0, constant: 0.0))
676+
bezelConstraints.append(NSLayoutConstraint(item: view, attribute: .bottom, relatedBy: .equal, toItem: bezelView,
677+
attribute: .bottom, multiplier: 1.0, constant: 0.0))
649678
}
650679

651680
if idx > 0 {
652681
// Has previous
653-
let padding = NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal, toItem: subviews[idx - 1], attribute: .bottom, multiplier: 1.0, constant: 0.0)
682+
let padding = NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal, toItem: subviews[idx - 1],
683+
attribute: .bottom, multiplier: 1.0, constant: 0.0)
654684
bezelConstraints.append(padding)
655685
paddingConstraints.append(padding)
656686
}
@@ -663,6 +693,7 @@ extension HUD {
663693

664694
super.updateConstraints()
665695
}
696+
// swiftlint:enable function_body_length
666697

667698
open override func layoutSubviews() {
668699
// There is no need to update constraints if they are going to
@@ -717,7 +748,8 @@ extension HUD {
717748
}
718749
}
719750

720-
@objc private func updateProgressFromProgressObject() {
751+
@objc
752+
private func updateProgressFromProgressObject() {
721753
guard let progressObject = progressObject else { return }
722754
progress = CGFloat(progressObject.fractionCompleted)
723755
}
@@ -735,7 +767,8 @@ extension HUD {
735767
NotificationCenter.default.removeObserver(self)
736768
}
737769

738-
@objc private func statusBarOrientationDidChange(_ notification: Notification) {
770+
@objc
771+
private func statusBarOrientationDidChange(_ notification: Notification) {
739772
guard superview != nil else { return }
740773
updateForCurrentOrientation(animated: true)
741774
}

Sources/Classes/Progressive.swift

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// LICENSE file in the root directory of this source tree.
1010
//
1111

12-
1312
import CoreGraphics
1413

1514
public protocol Progressive: AnyObject {

Sources/Classes/RoundProgressView.swift

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public class RoundProgressView: UIView, Progressive {
6565

6666
// MARK: - Drawing
6767

68+
// swiftlint:disable function_body_length
6869
public override func draw(_ rect: CGRect) {
6970
guard let context = UIGraphicsGetCurrentContext() else { return assert(false) }
7071
if isAnnular {
@@ -137,4 +138,5 @@ public class RoundProgressView: UIView, Progressive {
137138
processPath.stroke()
138139
}
139140
}
141+
// swiftlint:enable function_body_length
140142
}

0 commit comments

Comments
 (0)