-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix refresh control positioning #123
Conversation
@spinosa @ghiculescu @joemasilotti @Bramjetten I saw you guys were involved in the related PR (#73). |
|
||
/// 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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have to specify the height?
Internally, refresh control doesn't use autolayout for positioning its subviews. Its main frame doesn't reflect its true size. The main container height is 60pt, but the view where the refresh image/animation is has a height of 100pt. When using autolayout the latter is used. 🤷♂️ Even if we don't set the height, the refresh control will respect the safe area, but it won't be positioned as it should be.
![Screenshot 2023-05-17 at 11 52 53](https://private-user-images.githubusercontent.com/617660/239572391-49e2976b-5aa8-4350-b285-1162c2d38f86.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkwMDUxOTQsIm5iZiI6MTcxOTAwNDg5NCwicGF0aCI6Ii82MTc2NjAvMjM5NTcyMzkxLTQ5ZTI5NzZiLTVhYTgtNDM1MC1iMjg1LTExNjJjMmQzOGY4Ni5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNjIxJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDYyMVQyMTIxMzRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0xNzE4YjU2OTI5YzQxYmFmMTg1MzJkYTI1NjNjMjQ5MGJkMDhkNWZlNTM5NGUwNThhODhjNjA5MmMzM2RlY2MwJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.NHmtO8ZbG8P3gw2EMcCxK32iY0ez86AQV58V_PbcKpE)
NSLayoutConstraint.activate([ | ||
refreshControl.centerXAnchor.constraint(equalTo: centerXAnchor), | ||
refreshControl.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor), | ||
refreshControl.heightAnchor.constraint(equalToConstant: refreshControlHeight) | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using autolayout ensures the system takes care of updating the view's position as appropriate.
centerXAnchor
makes sure the control is always centered with the view’s horizontal center.
Pinning control's top anchor to the view's safe area top anchor ensures the control is positioned within the safe area.
Thanks for this! Will try it out in our apps next week and report back 👍 |
I have just tested and confirmed it works in my project! Thanks, this is much appreciated! |
That's great to hear @Bramjetten! Thanks! |
Summary
This PR fixes refresh control's positioning by using constraints.
Context
UIRefreshControl
is a critical component that enables users to refresh content by pulling down on a scroll view.The conventional approach involves assigning the
UIRefreshControl
directly to the web view's scroll view. However, in a specific case (usingviewport-fit=cover
), this approach did not provide the desired functionality. See #73.Solution
To address this issue, we have updated the
UIRefreshControl
positioning by utilizing constraints. With this approach, we can ensure theUIRefreshControl
adjusts properly within the safe area.