Skip to content

Commit

Permalink
Adding a partial compatibility layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Coeur committed May 28, 2019
1 parent c593180 commit 4856e3a
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
1 change: 1 addition & 0 deletions EFCountingLabel/Classes/EFCount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// THE SOFTWARE.

import Foundation
import QuartzCore

public protocol EFTiming {
func update(_ time: CGFloat) -> CGFloat
Expand Down
80 changes: 80 additions & 0 deletions EFCountingLabel/Classes/EFCountAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,46 @@ extension EFCountAdapter {

open class EFCountingButton: UIButton, EFCountAdapter {
public private(set) var counter = EFCounter()

open var formatBlock: ((CGFloat) -> String)? {
set {
if let formatBlock = newValue {
setUpdateBlock { value, button in button.setTitle(formatBlock(value), for: .normal) }
} else {
setUpdateBlock(nil)
}
}
@available(*, unavailable)
get {
return nil
}
}
open var attributedFormatBlock: ((CGFloat) -> NSAttributedString)? {
set {
if let attributedFormatBlock = newValue {
setUpdateBlock { value, button in button.setAttributedTitle(attributedFormatBlock(value), for: .normal) }
} else {
setUpdateBlock(nil)
}
}
@available(*, unavailable)
get {
return nil
}
}
open var completionBlock: (() -> Void)? {
set {
if let completionBlock = newValue {
setCompletionBlock { _ in completionBlock() }
} else {
setCompletionBlock(nil)
}
}
@available(*, unavailable)
get {
return nil
}
}

deinit {
counter.invalidate()
Expand All @@ -68,6 +108,46 @@ open class EFCountingButton: UIButton, EFCountAdapter {
open class EFCountingLabel: UILabel, EFCountAdapter {
public private(set) var counter = EFCounter()

open var formatBlock: ((CGFloat) -> String)? {
set {
if let formatBlock = newValue {
setUpdateBlock { value, label in label.text = formatBlock(value) }
} else {
setUpdateBlock(nil)
}
}
@available(*, unavailable)
get {
return nil
}
}
open var attributedFormatBlock: ((CGFloat) -> NSAttributedString)? {
set {
if let attributedFormatBlock = newValue {
setUpdateBlock { value, label in label.attributedText = attributedFormatBlock(value) }
} else {
setUpdateBlock(nil)
}
}
@available(*, unavailable)
get {
return nil
}
}
open var completionBlock: (() -> Void)? {
set {
if let completionBlock = newValue {
setCompletionBlock { _ in completionBlock() }
} else {
setCompletionBlock(nil)
}
}
@available(*, unavailable)
get {
return nil
}
}

deinit {
counter.invalidate()
}
Expand Down
2 changes: 1 addition & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 18006cf8308f1ddc4db21317a6cf556416d587b1

COCOAPODS: 1.7.0.rc.1
COCOAPODS: 1.7.0
2 changes: 1 addition & 1 deletion Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4856e3a

Please sign in to comment.