Add FXIOS-14817 [BrowserKit] Centralize the usage of UIScreen.main.value(forKey: _displayCornerRadius) to get device corner radius#34565
Conversation
🧹 Tidy commitJust 3 file(s) touched. Thanks for keeping it clean and review-friendly! 🙌 Friday high-fiveThanks for pushing us across the finish line this week! 🙌 ✅ Code coverage
Client.app: Coverage: 43.51
Generated by 🚫 Danger Swift against 3fac2ef |
| open class DeviceInfo { | ||
| @MainActor | ||
| public static var deviceCornerRadius: CGFloat? { | ||
| return UIScreen.main.value(forKey: "_displayCornerRadius") as? CGFloat |
There was a problem hiding this comment.
Let's use UICornerConfiguration on iOS 26 instead.
There was a problem hiding this comment.
I checked online @thatswinnie and i think UICornerConfiguration doesn't support querying the screen corner radius, we should use just the private one i guess
There was a problem hiding this comment.
During the liquid glass event from Apple in Berlin they recommended using this API as it will match the devices corner radius which makes the UI feel more organic. Yes, it does not give you a number for the corner radius but I think we should still use it and only fall back to querying UIScreen when the new API is not available. For iOS 27 Apple says to avoid using UIScreen as this API is not reliable anymore with resizable shared screens, etc. and there is will an initiative to get rid of all the UIScreen uses in our code before iOS 27 is released. So using the new API here would help us in the long run.
Using the new API would look something like this:
view.cornerConfiguration = UICornerConfiguration.corners(radius: containerConcentric(minimum: 12))
view.cornerConfiguration = UICornerConfiguration.corners(radius: containerConcentric())
|
|
||
| @MainActor | ||
| @available(iOS 26.0, *) | ||
| open class func deviceCornerConfiguration(minimumRadius: CGFloat) -> UICornerConfiguration { |
There was a problem hiding this comment.
Thanks for adding these. However I don't think we should add methods that are not used at the moment and as they are simple calls to the native API I am not sure we need them at all. What I'd rather like to see is using the new API in the CrossDissolveTransitionAnimator for iOS 26 and the screenCornerRadius for any version below.
There was a problem hiding this comment.
yes i totally agree @thatswinnie what if we add directly an extension to UIViewExtension inside common something like this:
extension UIView {
func applyScreenCornerRadius(minimumCornerRadius: CGFloat = 0) {
if #available(iOS 26) {
view.cornerConfiguration = UICornerConfiguration.
} else {
view.layer.cornerRadius = UIScreen.main.value(for: "") ?? minimumCornerRadius
}
}
}There was a problem hiding this comment.
@FilippoZazzeroni great idea 🎉 Just wondering if we really need the minimumCornerRadius. Seems like we don't have that currently either.
There was a problem hiding this comment.
Thanks @thatswinnie 🎉 , yes we don't need that, we can just default to 0 for the legacy path
FilippoZazzeroni
left a comment
There was a problem hiding this comment.
LGTM @Alex-Bangu just a couple of nits left and we should be good 💪
| @MainActor | ||
| static let screenCornerRadius: CGFloat = { | ||
| return UIScreen.main.value(forKey: "_displayCornerRadius") as? CGFloat ?? 0.0 | ||
| return DeviceInfo.deviceCornerRadius ?? 0.0 |
There was a problem hiding this comment.
This doesn't exists anymore we can just apply the screen corner radius directly to the view that needs it
| private var layoutWasInvalidated = false | ||
| private var screenCornerRadius: CGFloat { | ||
| return UIScreen.main.value(forKey: "_displayCornerRadius") as? CGFloat ?? 0.0 | ||
| return DeviceInfo.deviceCornerRadius ?? 0.0 |
There was a problem hiding this comment.
same for this one
| /// Sets the corner radius to the devices current corner radius | ||
| func applyScreenCornerRadius() { | ||
| if #available(iOS 26.0, *) { | ||
| self.cornerConfiguration = UICornerConfiguration.corners(radius: .containerConcentric(minimum: 0)) |
There was a problem hiding this comment.
nit: self can be removed here and in the else branch
FilippoZazzeroni
left a comment
There was a problem hiding this comment.
Looks great @Alex-Bangu 🔥
|
Tick the box to add this pull request to the merge queue (same as
|
|
🚀 PR merged to |
📜 Tickets
Jira ticket
Github issue
💡 Description
Added a static variable to
DeviceInfoand replaced existing usages ofUIScreen.main.value(forKey: _displayCornerRadius)withDeviceInfo.deviceCornerRadius.📝 Checklist