// Capture as a layer: the capture surface (the picture path) or New thought's // overlay, whichever the raise asked for, drawn by the host it rose over. // // Home draws it in the board's place when capture rises over Home itself. // Over pushed screens the phone's stack host draws it OVER the whole stack and // pops nothing (mini RJ11, S2): capture used to pop to Home and put back only // the navigator's path, so every screen pushed by `navigationDestination(item:)` // — a Todos group, a todo opened from it, a linked record — was gone when the // capture was cancelled, and the person landed on the Todos root. import SwiftUI struct CaptureLayer: View { /// A thought the capture surface kept (the picture path), on the /// overlay's receipt until it is let go — the host's, so it outlives the /// surface that kept it. @Binding var kept: ThoughtFiled? /// The capture up is the picture path's (`CapturePictureLatch`). let pictureCapture: Bool /// Something was written or taken back: the host reads again. let onChanged: () -> Void @Environment(Navigator.self) private var navigator: Navigator? @Environment(DatabaseScene.self) private var scene: DatabaseScene? @Environment(DatabasesModel.self) private var databases: DatabasesModel? @Environment(\.records) private var records var body: some View { if let start = navigator?.capture, pictureCapture || navigator?.waitingPicture != nil { captureSurface(start) } else { thoughtOverlay(navigator?.capture) } } /// The capture surface, built from the core by `Hosted`; the navigator's /// flag comes down when it closes. @ViewBuilder private func captureSurface(_ start: CaptureStart) -> some View { Hosted(unwired: { core, _ in CaptureSurfaceModel( read: ScreenRead(core: core, read: CaptureSurfaceModel.readName, families: [.core]), dictionary: { await VoiceBias.hints(core: core) } ) }) { surface in CaptureSurface( model: surface, start: start, onKept: { filed in kept = filed // The receipt shows first; its Done puts the screen back. navigator?.closeCapture(restoring: false) onChanged() }, onDiscarded: { navigator?.closeCapture() } ) } } /// New thought's own overlay (`NewThoughtOverlay.swift`): the pill's two /// paths and the receipt, over the same dock the capture surface mounts. @ViewBuilder private func thoughtOverlay(_ start: CaptureStart?) -> some View { Hosted(unwired: { core, _ in CaptureSurfaceModel( read: ScreenRead(core: core, read: CaptureSurfaceModel.readName, families: [.core]), dictionary: { await VoiceBias.hints(core: core) } ) }) { surface in NewThoughtOverlay( model: surface, start: start, kept: kept, personalName: databases.flatMap { model in model.held.first(where: \.isPersonal).map { model.capName($0) } } ?? DatabaseCap.personal, pageDatabaseId: scene?.shownId, screen: CaptureScreen(navigator?.stack.last ?? .home), onDone: { kept = nil navigator?.closeCapture() onChanged() }) } } } /// The capture up is the picture path's: latched when the picture is held, /// because the capture surface TAKES the picture as it mounts and a body /// reading `waitingPicture` alone would swap the surface out under it. Worn /// by the always-mounted host, never by the layer itself. struct CapturePictureLatch: ViewModifier { @Binding var pictureCapture: Bool let navigator: Navigator? func body(content: Content) -> some View { content .onChange(of: navigator?.waitingPicture != nil, initial: true) { _, held in if held { pictureCapture = true } } .onChange(of: navigator?.capture == nil) { _, closed in if closed { pictureCapture = false } } } }