Add comments

This commit is contained in:
Vlad 2020-08-31 23:09:34 +03:00
parent d29903d51b
commit 86581223ea
1 changed files with 5 additions and 0 deletions

View File

@ -4,6 +4,7 @@ open class RefreshControl: UIRefreshControl {
private var action: Selector?
private var target: NSObjectProtocol?
// Handle .valueChanged event of refresh control
public override func addTarget(_ target: Any?, action: Selector, for controlEvents: UIControl.Event) {
guard case .valueChanged = controlEvents else {
return super.addTarget(target, action: action, for: controlEvents)
@ -28,18 +29,22 @@ open class RefreshControl: UIRefreshControl {
return super.sendActions(for: controlEvents)
}
// Perform target's action
if action != nil, target != nil {
performRefreshAction()
}
}
open override func endRefreshing() {
// Due to Apple's recommends
CFRunLoopPerformBlock(CFRunLoopGetMain(), CFRunLoopMode.defaultMode.rawValue) {
super.endRefreshing()
}
}
private func performRefreshAction() {
// It is implemented the combined behavior of `touchUpInside` and `touchUpOutside` using `CFRunLoopPerformBlock`,
// which `UIRefreshControl` does not support
CFRunLoopPerformBlock(CFRunLoopGetMain(), CFRunLoopMode.defaultMode.rawValue) { [weak self] in
guard let action = self?.action else {
return