Skip to content

Commit 7ee974b

Browse files
BalazsSzamodyMaherKSantina
authored andcommitted
loadable(shouldLoad:) convenience method (#6)
A convenience method for controlling the loadable's loading with a boolean
1 parent 9367b49 commit 7ee974b

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

DSLoadable/Classes/DSLoadable.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ extension DSLoadable where Self: UIButton {
7777
public func loadableStopLoading() {
7878
return loadableStopLoading(loadingViewType: DSLoadingView.self)
7979
}
80+
81+
/**
82+
Convenience method for controling the loading with a boolean value
83+
84+
- parameter shouldLoad: The boolean value that controls the loading overlay
85+
*/
86+
public func loadable(shouldLoad: Bool) {
87+
switch shouldLoad {
88+
case true:
89+
loadableStartLoading()
90+
case false:
91+
loadableStopLoading()
92+
}
93+
}
8094
}
8195

8296
extension DSLoadable where Self: UIView {
@@ -104,6 +118,22 @@ extension DSLoadable where Self: UIView {
104118
configuration?(self, loadingView)
105119
loadingView.removeFromSuperview()
106120
}
121+
122+
/**
123+
Convenience method for controling the loading with a boolean value
124+
125+
- parameter shouldLoad: The boolean value that controls the loading overlay
126+
- parameter loadingViewType: The type of the loading view
127+
- parameter configuration: The configuration closure that will be executed on the loading view
128+
*/
129+
public func loadable(shouldLoad: Bool, loadingViewType: UIView.Type = DSLoadingView.self, configuration: ((UIView, UIView) -> Void)? = nil) {
130+
switch shouldLoad {
131+
case true:
132+
loadableStartLoading(loadingViewType: loadingViewType, configuration: configuration)
133+
case false:
134+
loadableStopLoading(loadingViewType: loadingViewType)
135+
}
136+
}
107137
}
108138

109139
extension DSLoadable where Self: UIView, Self: DSLoadableConfigurable {
@@ -114,6 +144,20 @@ extension DSLoadable where Self: UIView, Self: DSLoadableConfigurable {
114144
public func loadableStopLoading() {
115145
return loadableStopLoading(loadingViewType: loadableLoadingViewType)
116146
}
147+
148+
/**
149+
Convenience method for controling the loading with a boolean value
150+
151+
- parameter shouldLoad: The boolean value that controls the loading overlay
152+
*/
153+
public func loadable(shouldLoad: Bool) {
154+
switch shouldLoad {
155+
case true:
156+
loadableStartLoading()
157+
case false:
158+
loadableStopLoading()
159+
}
160+
}
117161
}
118162

119163
extension UIView: DSLoadable { }

0 commit comments

Comments
 (0)