Skip to content

Commit

Permalink
PLAYRTS-5578 Adapt GoogleCast button position depending on size class
Browse files Browse the repository at this point in the history
  • Loading branch information
mutaben committed Nov 18, 2024
1 parent d43b704 commit 7ff8687
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Application/Sources/Content/PageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,19 @@ final class PageViewController: UIViewController {
view.addSubview(googleCastButton)
self.googleCastButton = googleCastButton

// Place the button where it would appear if a navigation bar was available. An offset is needed on iPads for a perfect
// result (might be fragile but should be enough).
let topOffset: CGFloat = (UIDevice.current.userInterfaceIdiom == .pad) ? 3 : 0
NSLayoutConstraint.activate([
googleCastButton.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor, constant: topOffset),
googleCastButton.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor)
])
// Place the button where it would appear if a navigation bar was available.
if traitCollection.horizontalSizeClass == .regular {
// Try to match the vertical alignment of the new floating UITabBar
NSLayoutConstraint.activate([
googleCastButton.topAnchor.constraint(equalTo: view.topAnchor, constant: 28),
googleCastButton.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor)
])
} else {
NSLayoutConstraint.activate([
googleCastButton.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor),
googleCastButton.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor)
])
}
}
} else {
googleCastButton?.removeFromSuperview()
Expand Down

0 comments on commit 7ff8687

Please sign in to comment.