// The shell's writing editors over the whole stack (`StackHost`): the // short-text input over the dimmed deck while a line is written, the // full-screen editor while a long text is (`DeckEditor.writing`). Nothing // under the dim moves for the keyboard either raises: from the moment a // writer opens until its keyboard has gone (`DeckEditor.holdsKeyboard`) // every page ignores the keyboard, so no card, deck or fan is laid out // again for it; the input alone rides the keyboard. // // WHERE THE KEYBOARD IS IGNORED. Every page stands in a UIKit host of its // own (`TileStack`'s root and record hosts: Home's, and each fan tile's), // and a host lays its own content out for the keyboard, past any modifier // outside it: ignored over the stack alone, Home's host still lifted the // fan over the keyboard, and the deck's card, standing above the fan, // squeezed into the strip left (walk 332). So each host's content ignores // it itself (`deckStillUnderWriter`), as this stack's does. A window of the // writer's own would not do: a host lays itself out for any keyboard in the // scene, whichever window's field raised it. import SwiftUI extension View { /// The shell's writing editors over this stack. func deckWriting() -> some View { modifier(DeckWritingLayer()) } /// A page host's content under the shell's writer: it ignores the /// keyboard while the writer holds it (`DeckEditor.holdsKeyboard`). func deckStillUnderWriter() -> some View { modifier(DeckStillUnderWriter()) } } struct DeckStillUnderWriter: ViewModifier { private var editor: DeckEditor { .session } func body(content: Content) -> some View { content.ignoresSafeArea(.keyboard, edges: editor.holdsKeyboard ? .bottom : []) } } struct DeckWritingLayer: ViewModifier { @Environment(\.fanCover) private var cover @Environment(ToastCenter.self) private var toasts: ToastCenter? private var editor: DeckEditor { .session } private var line: DeckWriting? { editor.writing.flatMap { [.line, .amount].contains($0.editor) ? $0 : nil } } func body(content: Content) -> some View { content .deckStillUnderWriter() .overlay(alignment: .top) { if let draft = editor.draft { GeometryReader { room in OpenedDraftCard(draft: draft, editor: editor) .environment(\.deckEditor, editor) .frame(height: max(0, room.size.height - (cover?.scrollClearance ?? 0))) } } } .overlay { if let line { DeckLineInput(writing: line, commit: { editor.commit($0) }, dismiss: { editor.dismissWriting() }) .id(line.id) .transition(.opacity) } } .animation(.easeOut(duration: 0.18), value: line?.id) // A write the deck could not make is said where it was made, and // stands until the next tap: read, not glimpsed. .onChange(of: editor.refusal) { _, refused in if let refused { _ = toasts?.show(refused.sentence, tone: .error, window: ToastWindow.untilTap) } } .fullScreenCover(item: Binding( get: { editor.writing?.editor == .page && editor.writing?.overReader == false ? editor.writing : nil }, set: { if $0 == nil, editor.writing?.editor == .page, editor.writing?.overReader == false { editor.dismissWriting() } })) { page in DeckLongTextEditor(title: page.title, words: page.words, voice: page.voicePlan(surface: "note")) { text in if let text { editor.commit(text) } else { editor.dismissWriting() } } } #if os(iOS) .onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardWillShowNotification)) { _ in editor.keyboard(shown: true) } .onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardDidHideNotification)) { _ in editor.keyboard(shown: false) } #endif } }