From 86581223ea96b944a077afa07feec20a85c48f95 Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 31 Aug 2020 23:09:34 +0300 Subject: [PATCH] Add comments --- .../Sources/Views/RefreshControl/RefreshControl.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/TIUIElements/Sources/Views/RefreshControl/RefreshControl.swift b/TIUIElements/Sources/Views/RefreshControl/RefreshControl.swift index 64c4baab..129b84d4 100644 --- a/TIUIElements/Sources/Views/RefreshControl/RefreshControl.swift +++ b/TIUIElements/Sources/Views/RefreshControl/RefreshControl.swift @@ -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