Skip to content

Commit

Permalink
Explicitly add refresh control as subview of scroll view, and use con…
Browse files Browse the repository at this point in the history
…straints for its positioning.
  • Loading branch information
svara committed May 17, 2023
1 parent 3847dcb commit a9c19d7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Source/Visitable/VisitableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ open class VisitableView: UIView {

open lazy var refreshControl: UIRefreshControl = {
let refreshControl = UIRefreshControl()
refreshControl.translatesAutoresizingMaskIntoConstraints = false
refreshControl.addTarget(self, action: #selector(refresh(_:)), for: .valueChanged)
return refreshControl
}()
Expand All @@ -67,13 +68,21 @@ open class VisitableView: UIView {
guard let scrollView = webView?.scrollView, allowsPullToRefresh else { return }

#if !targetEnvironment(macCatalyst)
scrollView.refreshControl = refreshControl
scrollView.addSubview(refreshControl)

let height = refreshControl.frame.height > 0 ? refreshControl.frame.height : 60

NSLayoutConstraint.activate([
refreshControl.centerXAnchor.constraint(equalTo: centerXAnchor),
refreshControl.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor),
refreshControl.heightAnchor.constraint(equalToConstant: height)
])
#endif
}

private func removeRefreshControl() {
refreshControl.endRefreshing()
webView?.scrollView.refreshControl = nil
refreshControl.removeFromSuperview()
}

@objc func refresh(_ sender: AnyObject) {
Expand Down

0 comments on commit a9c19d7

Please sign in to comment.