mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Enable pull to refresh on timeline and change refresh indicator to better show when it is successfully pulled. Issue #1520
This commit is contained in:
51
iOS/UIKit Extensions/AccountRefreshControl.swift
Normal file
51
iOS/UIKit Extensions/AccountRefreshControl.swift
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// AccountRefreshControl.swift
|
||||
// NetNewsWire-iOS
|
||||
//
|
||||
// Created by Maurice Parker on 1/2/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Account
|
||||
|
||||
class AccountRefreshControl: UIRefreshControl {
|
||||
|
||||
var errorHandler: ((Error) -> ())? = nil
|
||||
|
||||
init(errorHandler: @escaping (Error) -> ()) {
|
||||
super.init()
|
||||
self.errorHandler = errorHandler
|
||||
addTarget(self, action: #selector(refreshAccounts(_:)), for: .valueChanged)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
@objc func refreshAccounts(_ sender: Any) {
|
||||
|
||||
let checkImageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
|
||||
checkImageView.tintColor = .label
|
||||
checkImageView.translatesAutoresizingMaskIntoConstraints = false
|
||||
addSubview(checkImageView)
|
||||
NSLayoutConstraint.activate([
|
||||
checkImageView.heightAnchor.constraint(equalToConstant: 35.0),
|
||||
checkImageView.widthAnchor.constraint(equalToConstant: 35.0),
|
||||
checkImageView.centerXAnchor.constraint(equalTo: centerXAnchor),
|
||||
checkImageView.centerYAnchor.constraint(equalTo: centerYAnchor)
|
||||
])
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.33) {
|
||||
self.endRefreshing()
|
||||
checkImageView.removeFromSuperview()
|
||||
|
||||
// This is a hack to make sure that an error dialog doesn't interfere with dismissing the refreshControl.
|
||||
// If the error dialog appears too closely to the call to endRefreshing, then the refreshControl never disappears.
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||
AccountManager.shared.refreshAll(errorHandler: self.errorHandler!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user