// A CARD ON THE WHOLE SCREEN (door row 12). A pinch out on a card opens what // it holds (`DeckOpening`): a picture, a film or a document in the one // viewer, a note or a memory on its reading page (`ReadPage`), and every // other card as large as the screen allows, to read: // nothing on it edits, its own pages still turn with a swipe, and a pinch in // or the close X puts it back. import CottonKit import CottonPaper import SwiftUI enum DeckWholeCardKnobs { /// How far a pinch opens before the card goes whole, and closes before /// it goes back. static let opens: CGFloat = 1.15 static let closes: CGFloat = 0.87 static let inset: CGFloat = 16 /// The X's row over the card. static let top: CGFloat = 56 } extension View { /// A pinch out on this card opens what it holds (`opening`), standing /// open while `opened` is true, so a tap opens it as the pinch does /// (`DeckOpening.open`): a note's page in the middle third. func pinchOpens(_ opening: DeckOpening, opened: Binding) -> some View { modifier(PinchOpens(opening: opening, opened: opened)) } } extension DeckOpening { /// Opens it: the viewer by its own act, the reading page by standing its /// cover up (`shown`); a card with neither opens nothing. func open(_ shown: Binding) { switch self { case .viewer(let show): show() case .reading: shown.wrappedValue = true case .whole: break } } /// Whether a pinch out opens anything. var opens: Bool { if case .whole = self { return false } return true } } private struct PinchOpens: ViewModifier { let opening: DeckOpening let opened: Binding private func open() { opening.open(opened) } func body(content: Content) -> some View { content .simultaneousGesture( MagnifyGesture().onEnded { pinch in if pinch.magnification > DeckWholeCardKnobs.opens { open() } }) // The pinch, for VoiceOver: one named action, where it opens something. .accessibilityActions { if opening.opens { Button(ShellLines.line("cards", "deck.whole")) { open() } } } .wholeScreen(isPresented: opened) { if case .reading(let document) = opening { ReadPage(document: document) { opened.wrappedValue = false } } } } }