-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3e5820
commit 5bb8fd3
Showing
5 changed files
with
432 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import UIKit | ||
|
||
public protocol BackgroundColorable { | ||
@discardableResult | ||
func background(_ color: UIColor) -> Self | ||
|
||
@discardableResult | ||
func background(_ number: Int) -> Self | ||
|
||
@discardableResult | ||
func background(_ state: State<UIColor>) -> Self | ||
|
||
@discardableResult | ||
func background<V>(_ expressable: ExpressableState<V, UIColor>) -> Self | ||
|
||
@discardableResult | ||
func background(_ identifier: FontIdentifier, _ size: CGFloat) -> Self | ||
} | ||
|
||
protocol _BackgroundColorable: BackgroundColorable { | ||
func _setBackgroundColor(_ v: UIColor) | ||
} | ||
|
||
extension BackgroundColorable { | ||
@discardableResult | ||
public func background(_ number: Int) -> Self { | ||
background(number.color) | ||
} | ||
|
||
@discardableResult | ||
public func background(_ state: State<UIColor>) -> Self { | ||
background(state.wrappedValue) | ||
state.listen { | ||
self.background($0) | ||
} | ||
return self | ||
} | ||
|
||
@discardableResult | ||
public func background<V>(_ expressable: ExpressableState<V, UIColor>) -> Self { | ||
background(expressable.value()) | ||
expressable.state.listen { | ||
self.background(expressable.value()) | ||
} | ||
return self | ||
} | ||
} | ||
|
||
@available(iOS 13.0, *) | ||
extension BackgroundColorable { | ||
@discardableResult | ||
public func background(_ color: UIColor) -> Self { | ||
guard let s = self as? _BackgroundColorable else { return self } | ||
s._setBackgroundColor(color) | ||
return self | ||
} | ||
} | ||
|
||
// for iOS lower than 13 | ||
extension _BackgroundColorable { | ||
@discardableResult | ||
public func background(_ color: UIColor) -> Self { | ||
_setBackgroundColor(color) | ||
return self | ||
} | ||
} |
Oops, something went wrong.