Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions host/apple/Sources/ExactKit/LocalInsets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import CoreGraphics
package struct LocalInsetsReport {
/// Top, right, bottom, left, in points.
package var wanted: [UInt32?: [CGFloat]] = [:]
/// The owners whose insets are another's until their container gives them their own: a route UIKit has yet to
/// place, which holds those of the route its stack shows.
package var borrowed: Set<UInt32> = []
private var delivered: [UInt32?: [CGFloat]] = [:]
package init() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ extension NavigationHost {
let columns = nav.flatMap { n in (split?.detail === n ? split : nil) ?? tabSplits.values.first { $0.detail === n } }
let detail = columns != nil
for (index, c) in routes.enumerated() {
c.arriving = nav
// The bar is each route's (LLP 1115.000 D5.2, D5.3): its header,
// the system Back alone on a pushed route with none of its own
// (no header, a hidden one, one that is not a bar's), or no bar
Expand Down
24 changes: 20 additions & 4 deletions host/apple/Sources/ExactNavigation/IOS/NavigationCoversIOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -686,15 +686,25 @@ extension NavigationHost {
/// take the whole view, where `env()` is 0 but the screen's insets are not.
/// Whether any changed.
func reportLocalInsets() -> Bool {
var wanted: [UInt32?: [CGFloat]] = [:]
var wanted: [UInt32?: [CGFloat]] = [:], borrowed: Set<UInt32> = []
for c in controllers.values where presenter.views[c.node.id] === c.node {
let last = localInsets.wanted[c.node.id]
// What UIKit last gave the route: nothing while it holds insets it borrowed arriving (`arrivingInsets`)
let last = localInsets.borrowed.contains(c.node.id) ? nil : localInsets.wanted[c.node.id]
let stack = stackTransition(for: c)
let moving = stack != nil || c.navigationController?.transitionCoordinator != nil
let presenting = c.inPresentation && stack == nil
let view = c.surface
guard view.window != nil, c.node.window != nil, !c.safeAreaNeedsLayout, last == nil || !moving || c.appearing || presenting else {
wanted[c.node.id] = last
// A route written to a stack UIKit has yet to place it in borrows the insets of the route that stack
// shows, the safe area UIKit gives it there (`RouteController.arriving`): its content lays out where
// it will rest, and UIKit's first measure once it places the route changes nothing
if last == nil, view.window == nil, let insets = arrivingInsets(c) {
wanted[c.node.id] = insets
borrowed.insert(c.node.id)
} else {
wanted[c.node.id] = localInsets.wanted[c.node.id]
if localInsets.borrowed.contains(c.node.id) { borrowed.insert(c.node.id) }
}
continue
}
let box = c.node.convert(c.node.bounds, to: view)
Expand All @@ -719,10 +729,16 @@ extension NavigationHost {
let safe = ExactView.agentSize == nil ? view.safeAreaInsets : .zero
wanted[nil] = [safe.top, safe.right, safe.bottom, safe.left]
}
defer { localInsets.wanted = wanted }
defer { localInsets.wanted = wanted; localInsets.borrowed = borrowed }
return localInsets.wanted != wanted
}

/// The local insets of the route shown in the stack `route` is written to (`RouteController.arriving`).
private func arrivingInsets(_ route: RouteController) -> [CGFloat]? {
guard let shown = route.arriving?.stackRoutes.last as? RouteController, shown !== route else { return nil }
return localInsets.wanted[shown.node.id]
}

func padsTop(_ route: RouteController) -> Bool {
guard case .edges(let edges)? = covers[route.node.id] else { return false }
return edges.top > 0.5 && route.collapseScroll == nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,10 @@ final class RouteController: UIViewController, UIScrollViewDelegate {
/// for that Exact has not written yet.
var held = false
weak var lastStack: UINavigationController?
/// The stack the router last gave the route (`NavigationHost.prepareRoutes`), which UIKit places it in when it is
/// written there: until then the route borrows the local insets of the route that stack shows
/// (`reportLocalInsets`).
weak var arriving: UINavigationController?

/// The route's node, left in place after a batch removed the route while
/// UIKit still shows it (`NavigationHost.prepare`), until UIKit takes the
Expand Down
Loading