Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
66 lines
2.5 KiB
Swift
Executable File
66 lines
2.5 KiB
Swift
Executable File
// PushChrome — where the header's controls (home, search, playlists,
|
|
// the ⋯ menu, the avatar) live outside a page's own header.
|
|
//
|
|
// - iPhone: a pushed page's bar is the library's
|
|
// `.rwPushChrome(backButton:divider:content:)` (AppShell's destinationView)
|
|
// with the controls where the back arrow was. Back is the leading-edge
|
|
// swipe below.
|
|
// - Mac: the window's TITLE BAR on every page — RedWhiteUI's
|
|
// `.rwTitleBar`, applied once in AppShell's body, with the back /
|
|
// forward chevrons (RwBackForward, ⌘[ / ⌘]) on the left and the controls
|
|
// on the right. Pushed pages draw no bar and no arrow.
|
|
//
|
|
// Either way a page's own header copy steps aside, so they never show twice.
|
|
|
|
import RedWhiteUI
|
|
import SwiftUI
|
|
|
|
extension EnvironmentValues {
|
|
/// True on a page pushed onto a stack. ShellHeaderControls hides there —
|
|
/// the bar carries them instead.
|
|
@Entry var isPushedPage = false
|
|
/// True inside the bar that carries the controls (an iPhone's push bar, a
|
|
/// Mac's title bar), where ShellHeaderControls does draw.
|
|
@Entry var inPushBar = false
|
|
}
|
|
|
|
/// What the back / forward chevrons need: whether each way is open, and how to
|
|
/// go. AppShell builds one for whichever stack is on screen.
|
|
struct PageHistory {
|
|
var canGoBack: Bool
|
|
var canGoForward: Bool
|
|
var back: () -> Void
|
|
var forward: () -> Void
|
|
}
|
|
|
|
|
|
extension View {
|
|
/// A drag that starts at the LEADING EDGE and travels right — the platform's
|
|
/// back idiom, borrowed for the drawer on root screens.
|
|
///
|
|
/// `simultaneousGesture`, not `gesture`: this must observe alongside
|
|
/// whatever is underneath rather than win against it, or it would steal
|
|
/// vertical scrolling from every list and sideways drags from the Discover
|
|
/// rails. The filter is deliberately strict — the drag has to begin within
|
|
/// 24pt of the edge, travel 90pt right, and stay under 60pt of vertical
|
|
/// wander — so a diagonal flick through a list never counts.
|
|
///
|
|
/// iOS only. macOS has no touch surface for this, and a trackpad two-finger
|
|
/// swipe is already the system's own navigation gesture.
|
|
public func leadingEdgeSwipe(perform action: @escaping () -> Void) -> some View {
|
|
#if os(iOS)
|
|
return simultaneousGesture(
|
|
DragGesture(minimumDistance: 24, coordinateSpace: .global)
|
|
.onEnded { value in
|
|
guard value.startLocation.x <= 24,
|
|
value.translation.width > 90,
|
|
abs(value.translation.height) < 60
|
|
else { return }
|
|
action()
|
|
})
|
|
#else
|
|
return self
|
|
#endif
|
|
}
|
|
}
|