Skip to content

A sheet's dismissal answers on iOS are kept in a trace file the app can share - #13

Merged
janicduplessis merged 2 commits into
mainfrom
@janic/sheet-dismiss-after-background
Nov 15, 2026
Merged

janicduplessis merged 2 commits into
mainfrom
@janic/sheet-dismiss-after-background

Conversation

@janicduplessis

@janicduplessis janicduplessis commented Nov 15, 2026 •

Copy link
Copy Markdown

Description

On iPhones, a sheet sometimes refuses its swipe down and a tap behind it after the app comes back from the background; its close button still works. It shows on an iPhone 17 Pro (iOS 27) and an iPhone 12 Pro (iOS 18.7) in builds from this fork's main, and I couldn't reproduce it on iOS 27.0 simulators. This PR records each dismissal decision on the phone so the next report says which check refused.

Solution

Diagnostic only: it writes a line on every sheet decision in Release builds. Remove it, or put it behind a flag, once the cause is found.

ModalHost refuses in two places: isModalInPresentation, written at the end of each navigation sync, and presentationControllerShouldDismiss, which UIKit asks only while that flag is false. SheetTrace (SheetTraceIOS.swift) writes each decision to app:/cache/exact-sheet-trace.log and to the unified log under exact-sheet, with the flag and every term refusesDismissal reads. An app shares the file with share(files=[...]) and the fs.read grant.

  • Logged: a presentation, each flip updatePermissions makes, shouldDismiss, didAttemptToDismiss, will/did dismiss, closeTop, a sync deferred while a sheet is up, and each sheet's state at every lifecycle edge.
  • shouldDismiss builds its line, which reads the runtime, only when the answer, the flag, the route or the selected route changes, since UIKit asks every frame of a drag.
  • The location beneath the route is logged as present or not, never its text.
  • Each launch starts with the OS version and build number. The file is cut to its last 200 KB once it passes 400 KB.

Side finding: a sync that holds a push inside a sheet (liftHeld) flips the flag false -> true for about 30 ms, until the next sync. A swipe's first touch produces a batch whose sync clears it, so it's probably not the phone bug.

Test plan

  • bun host/apple/build.mjs --test --ios --only ModalStackIOSTests on an iOS 27.0 iPhone 17 Pro simulator: all pass, including the new testTheSheetTraceRecordsEachDismissalAnswerAndWhatItRead. It answers UIKit's shouldDismiss before and after a push inside a sheet, then reads both lines back from the file.
  • A Release simulator build of an app on this branch: the app's share sheet offers the file, and the trace shows background, foreground and swipe for each scenario I tried.

…an share

A sheet that refuses its swipe down and a tap behind it after the app comes
back from the background was reported on phones and could not be reproduced on
iOS 27.0 simulators. ModalHost now writes each decision with the terms it read
to app:/cache/exact-sheet-trace.log and to the unified log (exact-sheet): the
presentation and its isModalInPresentation, every change updatePermissions
makes to it, UIKit's presentationControllerShouldDismiss (a line only when what
it read changes, since UIKit asks every frame of a drag), a refused attempt,
the dismissal, closeTop, a navigation sync deferred while a sheet is up, and
each sheet's state at every lifecycle edge and one turn after it. The file
opens each launch with the system version and build, and keeps its last
200 to 400 KB. An app shares it with share(files=[...]) and the fs.read grant.
… forgets its observers, and keeps no locations
@janicduplessis
janicduplessis marked this pull request as ready for review November 15, 2026 14:24
@janicduplessis
janicduplessis merged commit 4d765ec into main Nov 15, 2026
2 checks passed
@janicduplessis
janicduplessis deleted the @janic/sheet-dismiss-after-background branch November 15, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant