Cotton code
123 lines · 5.6 KB · SwiftRaw
// THE SHELL'S CARDS ABOVE AN APP (21 Nov 2026): the// sealed key, another device asking to be let in, a new device asking to sign// in, the recovery cards and, in a look, an assistant's unlock request. They// stand above the app and push it down; they never cover its Back, Info or// More, and at the largest text they stay compact.//// **Why not a top safe-area inset.** RootView laid them in a// `.safeAreaInset(edge: .top)`, which only tells the app where its safe area// now begins. Story, Days, Words and Comms do not all lay themselves out by// it: a scroll view keeps its offset when the inset grows under it, so a card// arriving with a sync pass stood over Story's home title; UIKit pieces (a// conversation's table) read their own frame; and the tests found Back, Info// and More under the card. Laid in a stack instead, the app's frame itself// starts below the cards, so every screen, scroller and UIKit view in it is// pushed down with no help of its own. With no card the band is empty and// the app stands at the top, its own grounds running under the clock.//// Paper apps (the fan's) keep the inset: their screen bars measure the// window's inset once (`MeasuresTopInset`) and would add it again below a// band.//// **A panel has the screen.** While one of the app's panels stands (a// LookPanel or a panel drawn in an app's own shape, `LookPanelUp`), the band// steps aside, so the panel and its keyboard have the room they have with no// card: under a card Story's speaker chooser had its Find field crushed to// nothing above the keyboard, and its rows ran under the home bar. The cards// stay in the tree, so a sheet one of them opened stays; they come back as// the panel closes.//// **Compact at the largest text.** The words wrap; their size is held at the// largest size below the accessibility sizes (in every app's faces:// `VaultLook.font(_:at:)`); the band is never taller than `most` of the// screen (`mostAtLargeText` at the accessibility sizes, so the app's own// tall rows still stand whole) and scrolls inside when its cards are taller// still, so Refuse and every act stay on screen and reachable.import SwiftUIenum ShellCardsKnobs {    /// The most of the app's height the cards take before they scroll.    static let most: CGFloat = 0.42    /// The same at the accessibility text sizes, where the app's own rows are    /// tallest: Words' rows at the largest size are taller than what 42% left    /// of the list, so no row stood whole and the last note could not be read.    static let mostAtLargeText: CGFloat = 0.26    /// The largest text the cards are drawn at.    static let largestText = DynamicTypeSize.xxxLarge}extension View {    /// The shell's `cards` above this view. `pushes`: laid above it in a    /// stack (apps with a look of their own); otherwise in the top safe-area    /// inset, as paper apps measure it. `ground`: what stands behind the    /// cards and under the clock while they stand.    func shellCardsAbove<Cards: View>(pushes: Bool, ground: Color?, @ViewBuilder cards: @escaping () -> Cards) -> some View {        modifier(ShellCardsAbove(pushes: pushes, ground: ground, cards: cards))    }}private struct ShellCardsAbove<Cards: View>: ViewModifier {    let pushes: Bool    let ground: Color?    let cards: () -> Cards    /// The height the app and its cards share.    @State private var room: CGFloat = 0    /// One of the app's panels stands.    @State private var panelUp = false    @Environment(\.dynamicTypeSize) private var textSize    /// The most height the band takes.    private var most: CGFloat {        room * (textSize.isAccessibilitySize ? ShellCardsKnobs.mostAtLargeText : ShellCardsKnobs.most)    }    func body(content: Content) -> some View {        if pushes {            VStack(spacing: 0) {                ShellCardsBand(most: most, ground: ground, aside: panelUp, cards: cards)                content                    .frame(maxWidth: .infinity, maxHeight: .infinity)                    .onPreferenceChange(LookPanelUp.self) { up in panelUp = up }            }            .animation(.easeOut(duration: 0.2), value: panelUp)            .onGeometryChange(for: CGFloat.self, of: { $0.size.height }) { room = $0 }        } else {            content                .onGeometryChange(for: CGFloat.self, of: { $0.size.height }) { room = $0 }                .safeAreaInset(edge: .top, spacing: 0) {                    ShellCardsBand(most: most, ground: ground, aside: false, cards: cards)                }        }    }}/// The cards at their own height, at most `most`, scrolling inside beyond/// it; no height at all while they stand `aside`.private struct ShellCardsBand<Cards: View>: View {    let most: CGFloat    let ground: Color?    let aside: Bool    let cards: () -> Cards    /// The cards' own height: zero while none stands.    @State private var tall: CGFloat = 0    var body: some View {        ScrollView(.vertical) {            cards()                .dynamicTypeSize(...ShellCardsKnobs.largestText)                .frame(maxWidth: .infinity)                .onGeometryChange(for: CGFloat.self, of: { $0.size.height }) { tall = $0 }        }        .scrollBounceBehavior(.basedOnSize)        .scrollIndicators(tall > most && most > 0 ? .automatic : .hidden)        .frame(height: aside ? 0 : most > 0 ? min(tall, most) : tall)        .clipped()        .background {            if let ground, tall > 0, !aside { ground.ignoresSafeArea(edges: .top) }        }        .opacity(aside ? 0 : 1)        .allowsHitTesting(!aside)        .accessibilityHidden(aside)    }}