Skip to content

Commit

Permalink
Merge pull request #123 from hotwired/refresh-control-fix
Browse files Browse the repository at this point in the history
Fix refresh control positioning
  • Loading branch information
svara committed May 30, 2023
2 parents 2e0bce2 + 264ba08 commit 293150b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 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 @@ -68,6 +69,16 @@ open class VisitableView: UIView {

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

/// Infer refresh control's default height from its frame, if given.
/// Otherwise fallback to 60 (the default height).
let refreshControlHeight = 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: refreshControlHeight)
])
#endif
}

Expand Down

0 comments on commit 293150b

Please sign in to comment.