Cotton code
89 lines · 4.5 KB · SwiftRaw
// The GROUND the dock stands on — one view, because every host needs the// identical four behaviours and three copies of them is three chances to drift.//// What it is, in four points:////   • it **rides the keyboard**;//   • the **home-indicator inset melts away over the same travel** — once the//     keyboard is up it IS the floor, and keeping both would leave a band of//     ground under the field;//   • it is a **ground, not a card**: the page's own background, the content//     margin, and a hairline as the only thing separating it from the scroller//     above;//   • it hangs **outside the scroller**, so the page scrolls behind it and the//     field never leaves the screen.//// ## The keyboard, and why there is no transform here//// On the phone the first two points were arithmetic:// `translateY: keyboardHeight` (0 closed, NEGATIVE while up) and// `paddingBottom: Math.max(0, insets.bottom + keyboardHeight)`. Neither ports,// because in SwiftUI both are already true of a view mounted in the bottom// SAFE AREA:////   • The keyboard IS a safe-area inset. A `.safeAreaInset(edge: .bottom)` view//     is laid out against the bottom of the safe area, so it rises with the//     keyboard by LAYOUT — there is nothing to translate.//   • The melt is structural rather than computed: the keyboard REPLACES the//     bottom inset, it is not added to it, so the `max(0, …)` that kept the//     phone's two floors from stacking has nothing to subtract. The ground is//     painted through the home indicator with `.ignoresSafeArea(edges: .bottom)`//     so the dock still STANDS ON it while the keyboard is down, which is what//     the phone's `paddingBottom: insets.bottom` bought.//// ## `DockShell` versus `/thoughts` — the bug this comment exists to prevent//// Every host but one mounts the dock through the keyboard-riding form// (``SwiftUICore/View/dockShell(_:)``): the person page and the project page.// **`/thoughts` copies everything but the travel.** There, the dock is the last// element of a column that is ALREADY repositioned by ordinary keyboard// avoidance, and applying the travel a second time double-moves it: on the// phone that is the `translateY`, and the symptom was not a visual glitch but a// dead control — the dock was drawn where the finger was not, and every Send// tap fell through to the list behind it.//// The SwiftUI form of the same mistake is nesting: a `DockShell` mounted as a// bottom safe-area inset INSIDE a column that already ends at the keyboard gets// inset twice. So `/thoughts` uses ``DockShell`` as a plain view at the foot of// its own column — the same ground, the same margin, the same hairline, and no// inset of its own. The two forms are one view mounted two ways, deliberately,// so the ground can never drift between them.//// A host that needs something this lacks gets a PARAMETER here, never a fourth// copy.import SwiftUIpublic struct DockShell<Content: View>: View {    @Environment(\.theme) private var theme    private let content: Content    public init(@ViewBuilder content: () -> Content) {        self.content = content()    }    public var body: some View {        content            .cottonContentMargin()            // A ground, not a card: a hairline is the WHOLE of the separation            // from the scroller above — no radius, no shadow, no border.            .background(alignment: .top) {                Rectangle()                    .fill(CottonColors.hairline)                    .frame(height: ComposerCardKnobs.chromeHairline)            }            // Painted through the home indicator, so the dock stands ON the            // floor rather than above a band of page.            //            // **The PAGE's ground, read from the page.** This was            // `CottonColors.ground` — `#FFFFFF`, the token no paper screen has            // stood on since phase 20 — and the dock's own content margin is            // what made it visible: a white band down the leading edge of the            // column, between the list column's divider and the cream capture            // sheet (the walk's re-shoot, walk-13-v3). `PageGroundFill` reads            // `\.cottonPageGround`, which every host declares, so the ground            // under the dock is the ground beside it whatever it is — the            // thing this file's header has claimed since it was written.            .background(PageGroundFill().ignoresSafeArea(edges: .bottom))    }}