Skip to content

Commit a9c19d7

Browse files
committed
Explicitly add refresh control as subview of scroll view, and use constraints for its positioning.
1 parent 3847dcb commit a9c19d7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Source/Visitable/VisitableView.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ open class VisitableView: UIView {
4545

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

6970
#if !targetEnvironment(macCatalyst)
70-
scrollView.refreshControl = refreshControl
71+
scrollView.addSubview(refreshControl)
72+
73+
let height = refreshControl.frame.height > 0 ? refreshControl.frame.height : 60
74+
75+
NSLayoutConstraint.activate([
76+
refreshControl.centerXAnchor.constraint(equalTo: centerXAnchor),
77+
refreshControl.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor),
78+
refreshControl.heightAnchor.constraint(equalToConstant: height)
79+
])
7180
#endif
7281
}
7382

7483
private func removeRefreshControl() {
7584
refreshControl.endRefreshing()
76-
webView?.scrollView.refreshControl = nil
85+
refreshControl.removeFromSuperview()
7786
}
7887

7988
@objc func refresh(_ sender: AnyObject) {

0 commit comments

Comments
 (0)