iOS: Duo layout fixes for every fold and orientation
- Split panes get portrait-phone traits (regular height, compact width), so unfolded landscape no longer stacks nav bar buttons down the pane's trailing edge, eating its width and sliding under the rail when swapped. - Wide Now Playing column never drops below what the transport needs; the transport shrinks when narrow instead of spilling onto the art and under the rail (landscape folded, portrait unfolded). - Stacked Now Playing controls match the art's width. - Docked wide art gets a smaller inset so it fills more of the pane. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
02f8452be2
commit
2d7ee03626
2 files changed
+49
-19
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
enum Tab: String, CaseIterable, Hashable {
|
||||
case Library, Songs, Albums, Artists, Genres, Playlists, Search, Downloads, Settings
|
||||
@@ -103,6 +104,18 @@ final class Ui {
|
||||
// Only an iPhone Duo ever splits, so from here on folded Now Playing uses its tighter layout.
|
||||
UserDefaults.standard.set(true, forKey: "duoSeen")
|
||||
}
|
||||
// Each pane is phone-sized, so give it portrait-phone traits. Unfolded landscape is
|
||||
// otherwise compact-height, which moves nav bar buttons into a column down the pane's
|
||||
// trailing edge (eating its width, and landing under the rail on the right pane).
|
||||
for case let scene as UIWindowScene in UIApplication.shared.connectedScenes {
|
||||
if on {
|
||||
scene.traitOverrides.verticalSizeClass = .regular
|
||||
scene.traitOverrides.horizontalSizeClass = .compact
|
||||
} else {
|
||||
scene.traitOverrides.remove(UITraitVerticalSizeClass.self)
|
||||
scene.traitOverrides.remove(UITraitHorizontalSizeClass.self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Switches to the Library tab and pushes [r] there.
|
||||
|
||||
@@ -112,6 +112,10 @@ struct NowPlayingScreen: View {
|
||||
/// width than a regular iPhone's, so the controls pack tighter and the art gets the room.
|
||||
@AppStorage("duoSeen") private var duoSeen = false
|
||||
private var tight: Bool { docked || duoSeen }
|
||||
/// Size of the art panel in the stacked layout, so the controls can match the art's width.
|
||||
@State private var artBox: CGSize = .zero
|
||||
private var artInset: CGFloat { tight ? 18 : 28 }
|
||||
private var hPad: CGFloat { tight ? 20 : 28 }
|
||||
private var g: AppGraph { .shared }
|
||||
|
||||
var body: some View {
|
||||
@@ -124,20 +128,28 @@ struct NowPlayingScreen: View {
|
||||
let wide = geo.size.width > geo.size.height * 0.9
|
||||
if let track {
|
||||
if wide {
|
||||
// The column never drops below what the transport row needs, so the buttons
|
||||
// can't spill onto the art or under the Duo rail.
|
||||
let col = tight ? min(max(geo.size.width * 0.46, 300), 420) : min(geo.size.width * 0.48, 440)
|
||||
HStack(spacing: 0) {
|
||||
panelView(track, header: false)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.transition(.opacity.combined(with: .scale(scale: 0.96)))
|
||||
controls(track, wide: true)
|
||||
.frame(width: min(geo.size.width * 0.48, 440))
|
||||
controls(track, wide: true, width: col)
|
||||
.frame(width: col)
|
||||
.frame(maxHeight: .infinity)
|
||||
}
|
||||
} else {
|
||||
let cap: CGFloat = tight ? 520 : 560
|
||||
// Controls line up with the art's edges instead of running wider than it.
|
||||
let art = min(artBox.width - 2 * artInset, artBox.height - 16)
|
||||
let w = panel == .Art && art > 0 ? min(cap, max(300, art + 2 * hPad)) : cap
|
||||
VStack(spacing: 0) {
|
||||
panelView(track, header: true)
|
||||
.frame(maxHeight: .infinity)
|
||||
.onGeometryChange(for: CGSize.self) { $0.size } action: { artBox = $0 }
|
||||
.transition(.opacity.combined(with: .scale(scale: 0.96)))
|
||||
controls(track, wide: false).frame(maxWidth: tight ? 520 : 560)
|
||||
controls(track, wide: false, width: min(w, geo.size.width)).frame(maxWidth: w)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
@@ -176,16 +188,19 @@ struct NowPlayingScreen: View {
|
||||
@ViewBuilder
|
||||
private func panelView(_ track: Track, header: Bool) -> some View {
|
||||
switch panel {
|
||||
case .Art: ArtPanel(thumb: track.thumb, playing: g.playback.playWhenReady, inset: tight ? 18 : 28).contentShape(Rectangle())
|
||||
case .Art: ArtPanel(thumb: track.thumb, playing: g.playback.playWhenReady, inset: header || !tight ? artInset : 12).contentShape(Rectangle())
|
||||
case .Mixer: VStack(spacing: 0) { if header { MiniHeader(track: track) }; MixerPanel() }
|
||||
case .Queue: VStack(spacing: 0) { if header { MiniHeader(track: track).contentShape(Rectangle()).gesture(screenDrag) }; QueuePanel(close: { show(.Queue) }) }
|
||||
case .Lyrics: VStack(spacing: 0) { if header { MiniHeader(track: track).contentShape(Rectangle()).gesture(screenDrag) }; LyricsPanel(track: track) }
|
||||
}
|
||||
}
|
||||
|
||||
private func controls(_ track: Track, wide: Bool) -> some View {
|
||||
private func controls(_ track: Track, wide: Bool, width: CGFloat) -> some View {
|
||||
let pm = g.playback
|
||||
let c = tint.map { base.tinted($0) } ?? base
|
||||
let pad: CGFloat = wide && tight ? 14 : hPad
|
||||
// Full-size transport needs 312 pt; below that the buttons shrink to fit.
|
||||
let narrow = width - 2 * pad < 312
|
||||
return VStack(spacing: 0) {
|
||||
if wide || panel == .Art {
|
||||
HStack(alignment: .center) {
|
||||
@@ -204,25 +219,25 @@ struct NowPlayingScreen: View {
|
||||
}
|
||||
ProgressVolumeBar(played: c.label, unplayed: c.label3, centerLabel: badge(track))
|
||||
.padding(.top, tight ? (wide ? 14 : 18) : wide ? 24 : panel == .Art ? 34 : 30)
|
||||
HStack {
|
||||
SideToggle(symbol: "shuffle", on: pm.shuffle, action: pm.toggleShuffle)
|
||||
Spacer()
|
||||
TransportButton(symbol: "backward.fill", size: 34, action: pm.previous)
|
||||
Spacer()
|
||||
HStack(spacing: 0) {
|
||||
SideToggle(symbol: "shuffle", on: pm.shuffle, action: pm.toggleShuffle, width: narrow ? 36 : 40)
|
||||
Spacer(minLength: 2)
|
||||
TransportButton(symbol: "backward.fill", size: narrow ? 28 : 34, box: narrow ? 52 : 72, action: pm.previous)
|
||||
Spacer(minLength: 2)
|
||||
Button(action: pm.togglePlay) {
|
||||
ZStack {
|
||||
if pm.buffering && pm.playWhenReady { ProgressView().controlSize(.large).tint(c.label) }
|
||||
else { Image(systemName: pm.playWhenReady ? "pause.fill" : "play.fill").font(.system(size: 48)).foregroundStyle(c.label).contentTransition(.symbolEffect(.replace)) }
|
||||
else { Image(systemName: pm.playWhenReady ? "pause.fill" : "play.fill").font(.system(size: narrow ? 42 : 48)).foregroundStyle(c.label).contentTransition(.symbolEffect(.replace)) }
|
||||
}
|
||||
.animation(.snappy(duration: 0.25), value: pm.playWhenReady)
|
||||
.frame(width: 80, height: 80)
|
||||
.frame(width: narrow ? 64 : 80, height: narrow ? 64 : 80)
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(PressFade())
|
||||
Spacer()
|
||||
TransportButton(symbol: "forward.fill", size: 34, action: pm.next, hold: pm.nextAlbum)
|
||||
Spacer()
|
||||
SideToggle(symbol: pm.repeatMode == .One ? "repeat.1" : "repeat", on: pm.repeatMode != .Off, action: pm.cycleRepeat)
|
||||
Spacer(minLength: 2)
|
||||
TransportButton(symbol: "forward.fill", size: narrow ? 28 : 34, box: narrow ? 52 : 72, action: pm.next, hold: pm.nextAlbum)
|
||||
Spacer(minLength: 2)
|
||||
SideToggle(symbol: pm.repeatMode == .One ? "repeat.1" : "repeat", on: pm.repeatMode != .Off, action: pm.cycleRepeat, width: narrow ? 36 : 40)
|
||||
}
|
||||
.frame(height: tight ? 76 : 84)
|
||||
.padding(.top, tight ? 4 : 14)
|
||||
@@ -246,7 +261,7 @@ struct NowPlayingScreen: View {
|
||||
.buttonStyle(PressFade())
|
||||
.gesture(swipe(up: panel != .Queue)) }
|
||||
}
|
||||
.padding(.horizontal, tight ? 20 : 28)
|
||||
.padding(.horizontal, pad)
|
||||
}
|
||||
|
||||
/// Opens a panel, or goes back to the art if it's already open.
|
||||
@@ -333,12 +348,13 @@ struct PressFade: ButtonStyle {
|
||||
private struct TransportButton: View {
|
||||
let symbol: String
|
||||
let size: CGFloat
|
||||
var box: CGFloat = 72
|
||||
let action: () -> Void
|
||||
var hold: (() -> Void)?
|
||||
@Environment(\.palette) private var p
|
||||
var body: some View {
|
||||
HoldButton(action: action, hold: hold) {
|
||||
Image(systemName: symbol).font(.system(size: size)).foregroundStyle(p.label).frame(width: 72, height: 72).contentShape(Rectangle())
|
||||
Image(systemName: symbol).font(.system(size: size)).foregroundStyle(p.label).frame(width: box, height: box).contentShape(Rectangle())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -368,6 +384,7 @@ private struct SideToggle: View {
|
||||
let symbol: String
|
||||
let on: Bool
|
||||
let action: () -> Void
|
||||
var width: CGFloat = 40
|
||||
@Environment(\.palette) private var p
|
||||
var body: some View {
|
||||
Button(action: action) {
|
||||
@@ -376,7 +393,7 @@ private struct SideToggle: View {
|
||||
Circle().frame(width: 4, height: 4).opacity(on ? 1 : 0)
|
||||
}
|
||||
.foregroundStyle(on ? p.label : p.label3)
|
||||
.frame(width: 40, height: 56)
|
||||
.frame(width: width, height: 56)
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(PressFade())
|
||||
|
||||
Reference in new issue
Block a user