// How far the live page under Home's fan has scrolled (lane fan, stage 4).// The page is whatever screen the tile opens — a list, a board, Home's own// board — each with its own scroll view, so the fan finds the one scroll view// that fills the page area in the window and watches its offset, rather than// asking every screen to report it.#if os(iOS)import UIKit@MainActorfinalclassFanScrollWatch {privatevar observation: NSKeyValueObservation?privateweakvar watched: UIScrollView?/// Bumped by every stop: a transition's end that finds the page again/// does so only for the watch it was asked for.privatevar generation = 0/// Watches the scroll view filling `area` (window points); `onOffset`/// gets how far below its top the page is, how far it can scroll, in/// points, and whether a finger moved it (dragging, or its fling running/// on). A page too short to scroll is at its top; only its pull down/// is read (`FanCollapseRule.reading`).func watch(in area: CGRect, onOffset: @escaping @MainActor (_ offset: Double, _ end: Double, _ byFinger: Bool) -> Void) {guardlet scroll = Self.scrollView(in: area) else { return stop() }// Mid-push or mid-pop, the page leaving can still cover the area:// the page is found again once the transition ends (fancollapse// review, 15 Oct 2026: after a record closed by the edge swipe, the// fan watched the record's scroll and no scroll up bloomed it).iflet transition = Self.transition(of: scroll) {let asked = generation + (scroll === watched ? 0 : 1) transition.animate(alongsideTransition: nil) { [weakself] _ inMainActor.assumeIsolated {guardletself, self.generation == asked else { return }self.watch(in: area, onOffset: onOffset) } } }guard scroll !== watched else { return } stop() watched = scroll observation = scroll.observe(\.contentOffset, options: [.initial, .new]) { scroll, _ inMainActor.assumeIsolated {let inset = scroll.adjustedContentInsetlet read = FanCollapseRule.reading( below: Double(scroll.contentOffset.y + inset.top), scrollable: Double(scroll.contentSize.height + inset.top + inset.bottom - scroll.bounds.height)) onOffset(read.offset, read.end, scroll.isTracking || scroll.isDecelerating) } } }func stop() { generation += 1 observation?.invalidate() observation = nil watched = nil }/// The navigation transition `view` stands in, while one runs.staticfunc transition(of view: UIView) -> UIViewControllerTransitionCoordinator? {var responder: UIResponder? = viewwhilelet next = responder?.next {iflet navigation = next as? UINavigationController, let coordinator = navigation.transitionCoordinator {return coordinator } responder = next }returnnil }/// The scroll view that covers most of `area`: the page's own. A text/// view scrolls too, and is not the page. Only Home's own presentation is/// searched: a sheet over it (the Databases sheet) stands in the same/// window, and its scroll folded the dial under it and was let go with/// the sheet, so no scroll of the page bloomed it again (walker pass 3,/// 16 Oct 2026).staticfunc scrollView(in area: CGRect) -> UIScrollView? {guardlet window = PagePictures.keyWindow, area.width > 0, area.height > 0,let home = window.rootViewController?.viewelse { returnnil }var best: (view: UIScrollView, cover: CGFloat)?func visit(_ view: UIView) {iflet scroll = view as? UIScrollView, !(scroll is UITextView), !scroll.isHidden, scroll.isScrollEnabled {let frame = scroll.convert(scroll.bounds, to: window).intersection(area)let cover = frame.isNull ? 0 : frame.width * frame.heightif cover > area.width * area.height / 2, cover > (best?.cover ?? 0) { best = (scroll, cover) } } view.subviews.forEach(visit) } visit(home)return best?.view }/// The largest scroll view inside `view`: an off-screen page's own.staticfunc scrollView(within view: UIView) -> UIScrollView? {var best: (view: UIScrollView, area: CGFloat)?func visit(_ view: UIView) {iflet scroll = view as? UIScrollView, !(scroll is UITextView), !scroll.isHidden, scroll.isScrollEnabled {let area = scroll.bounds.width * scroll.bounds.heightif area > (best?.area ?? 0) { best = (scroll, area) } } view.subviews.forEach(visit) } visit(view)return best?.view }/// The page stands at its top: no scroll view is at its top too.staticfunc atTop(_ scroll: UIScrollView?) -> Bool {guardlet scroll else { returntrue }return scroll.contentOffset.y + scroll.adjustedContentInset.top <= 1 }}#endif