Compare commits

...
3 changed files with 62 additions and 29 deletions

No files matched your search

+35 -20
View File
@@ -137,45 +137,60 @@ final class Ui {
lockOrientation()
}
/// Split (unfolded) goes landscape at once. Portrait waits a moment and checks again, so a
/// frame without a hinge reading mid-rotation can't throw an unfolded phone back upright.
/// Back in the foreground: the phone may have been folded or unfolded meanwhile.
/// The split/unfolded flags are from before the app left, so locking on them at once can force
/// landscape on a phone folded meanwhile. Free the rotation while away and decide again once
/// the window has settled to the screen it came back on.
/// The Duo is never free to turn: folded is portrait only, unfolded is landscape only.
/// Hinge readings flicker while the window settles (coming back from the background, mid
/// fold), so the lock only changes once a reading has held for a moment. Other iPhones turn freely.
private var lockGen = 0
func resumed() {
lockOrientation()
if away { showPlayingFolded() }
away = false
}
/// Leaves the lock as it is: freeing it let iOS turn the window while audio kept the app alive.
func backgrounded() { away = true }
private var away = false
/// Folded with something playing, the app comes back on Now Playing.
private func showPlayingFolded() {
guard folded, !nowPlayingOpen, AppGraph.shared.playback.current != nil else { return }
// Back from the background folded with something playing: Now Playing slides up as if
// swiped open, once the app's own opening animation has landed.
Task { @MainActor in
try? await Task.sleep(for: .milliseconds(300))
self.lockOrientation()
try? await Task.sleep(for: .milliseconds(180))
guard self.folded, !self.nowPlayingOpen, AppGraph.shared.playback.current != nil else { return }
self.nowPlayingOpen = true
}
}
/// Folded stays locked upright: while audio plays the app lives on in the background and iOS
/// would turn the free window with the phone, so it came back sideways. Unfolding meanwhile is
/// still caught on return (upright unfolded marks the phone unfolded and turns it).
/// Unfolded frees rotation, so a phone folded meanwhile isn't held in landscape.
func backgrounded() {
if folded { Orientation.lock(.portrait) } else { Orientation.lock(.allButUpsideDown) }
}
private func lockOrientation() {
if split || unfolded { Orientation.lock(.landscape); return }
guard folded else { Orientation.lock(.allButUpsideDown); return }
guard duo || split || unfolded else { Orientation.lock(.allButUpsideDown); return }
let want: UIInterfaceOrientationMask = (split || unfolded) ? .landscape : .portrait
lockGen += 1
let gen = lockGen
Task { @MainActor in
try? await Task.sleep(for: .milliseconds(400))
if self.folded { Orientation.lock(.portrait) }
try? await Task.sleep(for: .milliseconds(450))
guard gen == self.lockGen else { return }
let now: UIInterfaceOrientationMask = (self.split || self.unfolded) ? .landscape : .portrait
guard now == want else { return }
Log.shared.info("orient", "lock \(want == .landscape ? "landscape" : "portrait") split=\(self.split) unfolded=\(self.unfolded)")
Orientation.lock(want)
}
}
func setUnfolded(_ on: Bool) {
guard on != unfolded else { return }
unfolded = on
Log.shared.info("orient", "unfolded \(on)")
lockOrientation()
}
func setSplit(_ on: Bool) {
guard on != split else { return }
split = on
Log.shared.info("orient", "split \(on)")
lockOrientation()
if on {
nowPlayingOpen = false
+26 -8
View File
@@ -3,6 +3,14 @@ import UIKit
enum NpPanel { case Art, Mixer, Queue, Lyrics }
/// The close drag's offset. Only DropOffset reads it, so dragging re-renders just the offset.
@Observable final class DropState { var y: CGFloat = 0 }
private struct DropOffset: ViewModifier {
let state: DropState
func body(content: Content) -> some View { content.offset(y: state.y) }
}
func deviceIcon(_ d: OutputDevice) -> (String, UInt32) {
switch d.kind {
case .Speaker: ("iphone", 0x8E8E93)
@@ -62,8 +70,9 @@ struct NowPlayingScreen: View {
@Environment(\.palette) private var base
@Environment(\.dismiss) private var dismiss
@State private var panel = NpPanel.Art
/// How far the screen is being dragged down to close it.
@State private var drop: CGFloat = 0
/// How far the screen is being dragged down to close it. Kept out of the view's own state so a
/// drag only moves the screen (DropOffset) instead of rebuilding all of Now Playing each frame.
@State private var drop = DropState()
/// Docked beside the hinge the pane is narrow, so the controls pack tighter. Full screen
/// (folded or any other iPhone) uses the roomy layout across the whole window.
private var tight: Bool { docked }
@@ -75,6 +84,8 @@ struct NowPlayingScreen: View {
@State private var ctlH: CGFloat = 0
/// The screen's height, for the strip at the top that a drag down closes from.
@State private var screenH: CGFloat = 0
/// Where the art sits on screen: folded, a drag down that starts on it closes Now Playing.
@State private var artFrame: CGRect = .zero
@Environment(\.verticalSizeClass) private var vSize
/// Folded iPhone Duo: the outer display keeps a status column down the right edge.
@State private var folded = false
@@ -151,7 +162,7 @@ struct NowPlayingScreen: View {
.gesture(screenDrag(header: true)) }
}
.onGeometryChange(for: CGFloat.self) { $0.size.height } action: { screenH = $0 }
.offset(y: drop)
.modifier(DropOffset(state: drop))
// Drag down from the top strip (or the song header) to close, so it never fights the
// stem faders. Swipe up anywhere on the art for the queue.
.simultaneousGesture(screenDrag(), including: panel == .Art ? .all : .subviews)
@@ -167,6 +178,7 @@ struct NowPlayingScreen: View {
switch panel {
case .Art: ArtPanel(thumb: track.thumb, playing: g.playback.playWhenReady, inset: header ? artInset : 12,
leading: folded && !docked && !ui.split && g.settings.foldedArtLeft, edge: hPad).contentShape(Rectangle())
.onGeometryChange(for: CGRect.self) { $0.frame(in: .global) } action: { if drop.y == 0 { artFrame = $0 } }
case .Mixer: VStack(spacing: 0) { if header { mini(track) }; MixerPanel(spread: folded) }
case .Queue: VStack(spacing: 0) { if header { mini(track) }; QueuePanel(close: { show(.Queue) }) }
case .Lyrics: VStack(spacing: 0) { if header { mini(track) }; LyricsPanel(track: track) }
@@ -287,19 +299,25 @@ struct NowPlayingScreen: View {
}
/// Drag down to close: from the grabber or song header, or anywhere in the top tenth of the screen.
/// Folded, also from the art (only while it shows, so never over the stem dials).
private func fromTop(_ v: DragGesture.Value, header: Bool) -> Bool {
header || v.startLocation.y < max(screenH * 0.1, 56)
|| (folded && !docked && panel == .Art && artFrame.contains(v.startLocation))
}
private func screenDrag(header: Bool = false) -> some Gesture {
DragGesture(minimumDistance: 20)
DragGesture(minimumDistance: 20, coordinateSpace: .global)
.onChanged { v in
let dy = v.translation.height
let top = header || v.startLocation.y < max(screenH * 0.1, 56)
drop = !docked && top && dy > 0 && dy > abs(v.translation.width) ? dy : 0
let top = fromTop(v, header: header)
drop.y = !docked && top && dy > 0 && dy > abs(v.translation.width) ? dy : 0
}
.onEnded { v in
let dy = v.translation.height
let vertical = abs(dy) > abs(v.translation.width)
let top = header || v.startLocation.y < max(screenH * 0.1, 56)
let top = fromTop(v, header: header)
if !docked && top && vertical && (dy > 120 || v.predictedEndTranslation.height > 300) { dismiss(); return }
withAnimation(.spring(duration: 0.3, bounce: 0.1)) { drop = 0 }
withAnimation(.spring(duration: 0.3, bounce: 0.1)) { drop.y = 0 }
// Never from the stems: a slightly upward fader drag or scroll there kept opening the queue.
if !docked && vertical && dy < -50 && panel != .Mixer && g.settings.swipeUpQueue {
withAnimation(.spring(duration: 0.38, bounce: 0.12)) { panel = .Queue }
+1 -1
View File
@@ -9,7 +9,7 @@ settings:
# iOS needs a plain number for the bundle version; the label is what the app and releases show.
MARKETING_VERSION: "0.10.1"
VERSION_LABEL: "0.10.1"
CURRENT_PROJECT_VERSION: "53"
CURRENT_PROJECT_VERSION: "58"
# Dev builds override these (build-ipa.sh dev) so they install next to the release app.
APP_ID: org.cdnutter.stemify
APP_NAME: Stemify