Cotton code
59 lines · 2.7 KB · SwiftRaw
import SwiftUI/// Home's fan's page area as the live page lays itself out in it (fan3 part/// 8): its frame in the window — inside the safe area, below the status bar/// — and the safe-area insets that reach out of it, up to the window's top./// A page (`PaperScreen`) draws its ground and scroll through those insets/// and clears its head row below them, so what the live page draws is the/// frame grown by its insets (`drawn`), not the frame.////// A picture of the page is that drawn region: painted into it (`painted`)/// or taken from the window at it, and shown back over it (`inPageArea`)./// Painted into the bare frame and shown from its top, every picture stood/// one status bar (~60 pt) below the live page that replaced it and its foot/// fade ended a status bar short of the fan, in a white band and a hard line/// (owner, build 283).struct PageRegion: Equatable {    var frame: CGRect = .zero    var insets = EdgeInsets()    /// What the live page draws, in the window: the frame grown by the    /// insets that reach out of it.    var drawn: CGRect {        CGRect(            x: frame.minX - insets.leading, y: frame.minY - insets.top,            width: frame.width + insets.leading + insets.trailing,            height: frame.height + insets.top + insets.bottom)    }    /// A page laid out as it is live, in a host of exactly the drawn    /// region's size that has no safe area of its own: the insets are handed    /// to it as safe area, so it clears the status bar — and draws its ground    /// through it — as the live page does.    func painted(_ page: some View) -> some View {        page            .safeAreaPadding(insets)            .frame(width: drawn.width, height: drawn.height)    }}extension View {    /// A picture of the page area shown in it: from the top leading corner of    /// what the live page draws — the area grown by its safe area — never    /// from the frame's top, a status bar lower. The picture is taller than    /// the frame by those insets; the area keeps its own size (minimum zero),    /// or the fan under it is pushed down.    func inPageArea() -> some View {        frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)            .clipped()            .ignoresSafeArea()    }    /// Measures the page area's region: its frame in the window and the    /// safe-area insets that reach out of it.    func measuresPageRegion(_ changed: @escaping (PageRegion) -> Void) -> some View {        onGeometryChange(for: PageRegion.self, of: { PageRegion(frame: $0.frame(in: .global), insets: $0.safeAreaInsets) }) {            changed($0)        }    }}