[iOS] A detents change made just after present() starts is never applied, so the sheet stays at the old detent
Before submitting a new issue
- [ ] I tested using the latest version of the library. — Reproduced on 4.0.1. Not run on 4.1.2, but the code involved (
updateProps,finalizeUpdates,presentAtIndex,viewControllerDidPresentAtIndexinios/TrueSheetView.mm) is unchanged in 4.1.2 and onmain(checked by diff). - [x] I tested using a supported version of React Native.
- [x] I checked for existing issues that might answer my question. (Related: #555, and #1022 for Android.)
Bug Summary
On iOS, a detents change that lands after presentViewController: is called but before UIKit marks the controller as being presented is never applied. The sheet stays at the detent it was presented with, while the controller and onDidPresent report the new detent.
Why:
presentAtIndex:builds the UIKit sheet's detents (setupSheetDetents) and then callspresentViewController:.- A detents change is parked for didPresent only while
_controller.isBeingPresentedis YES (the fix for #555). - If UIKit starts the transition after
presentViewController:returns, a change in that window takes the direct branch:updatePropssets_controller.detents(the controller'ssetDetents:stores it and returns early, since!_isPresented), andfinalizeUpdatestakes no branch (not presented, not being presented)._pendingPropsUpdatestays NO, so didPresent has nothing to apply, and the sheet keeps the old detent until some later prop change rebuilds it.
A smaller related case: between viewDidAppear (which sets _isPresented) and the async viewControllerDidPresentAtIndex, a direct-branch commit updates the controller but leaves an older _pendingDetents in place, and applySheetPropsUpdate at didPresent then applies the older array over the newer one.
We hit this with a sheet whose first detent is computed from measured content: the first detent is an estimate, and the measured one can arrive while the sheet presents. On a physical device (iPhone 13 Pro, iOS 27.2) the first present after a cold start stays at the estimate (3 of 3 tries); later presents and a slow network are fine. With the patch described below, the same device reaches the measured detent on every first present (7 of 7 cold starts). On the iOS 26.4 simulator UIKit starts the transition inside presentViewController: (isBeingPresented is already YES when it returns), so the window is empty and it does not reproduce there without the delay below. We did not instrument the device, so we have not confirmed that iOS 27.2 starts the transition later; the patch fixing it there points that way, and the deterministic repro below forces it.
Affected Platforms
- [x] iOS
Library Version
4.0.1 (same logic in 4.1.2 and on main)
Environment Info
React Native 0.86.3, New Architecture (Fabric), Hermes. Xcode 26.4.1, iPhone 17 simulator on iOS 26.4. Symptom seen on an iPhone 13 Pro on iOS 27.2.
Steps to Reproduce
- A sheet with
detents={[first, 0.81, 1]}, wherefirststarts at 0.3 and is set to a measured value (0.447 here) about 150 ms afterpresent()is called. - To open the window deterministically on iOS 26, delay the present in
presentAtIndex:by wrapping[presentingViewController presentViewController:…](and the transition-coordinator block after it) indispatch_after(400 ms, main queue). - Present the sheet.
Expected: the sheet ends at 0.447. Actual: it stays at 0.3. Logged: updateProps detents=0.447… beingPresented=0 presented=0 → presentViewController now controller=0.447… sheet=custom-0.300000… → didPresent detent=0.447 pendingProps=0 … selected=custom-0.300000.
Repro
The steps above with the dispatch_after change in ios/TrueSheetView.mm; happy to push a branch of the example app if that helps.
Additional Context
A local patch on 4.0.1 fixes it. On the iPhone 13 Pro on iOS 27.2 the first present after a cold start now reaches the measured detent (7 of 7 cold starts), and five other sheets in the app, one of them presented over another sheet, still open at the right height. On the simulator, under the delay, the sheet presents at 0.3 and moves to 0.447 at didPresent; without the delay nothing changes (the new branch is never taken on iOS 26.4). It is about 40 lines in TrueSheetView.mm:
- An
_isPresentStartingflag, set right beforepresentViewController:, cleared inviewControllerDidPresentAtIndex,viewControllerDidDismiss,prepareForRecycle, and at the start of each non-deferredpresentAtIndex. isBeingPresented || (_isPresentStarting && !isPresented)replacesisBeingPresentedinupdateProps(park_pendingDetents),finalizeUpdates(_pendingPropsUpdate) andsetupSheetDetentsForSizeChange(_pendingSizeChange).presentAtIndexapplies leftover_pendingDetentsbeforesetupSheetDetents.updateProps' direct branch clears_pendingDetents, so newer props win over parked ones.
The deferred present (_isPresentPending) is untouched: changes during that wait still reach the controller and the deferred presentAtIndex builds from them. An alternative is an iOS version of #1022 (compare the controller's detents with the sheet's at didPresent and rebuild when they differ), though that does not cover auto/peek size changes inside the window. Happy to open a PR with either.
Hey @nikolllay! Thanks for opening the issue.
It looks like your issue is missing a valid reproduction link.
A minimal reproduction helps us investigate and fix the issue faster. Without one, we may not be able to help.
Please provide one of the following:
- A GitHub repository under your username
- An Expo Snack
See "How to create a Minimal, Reproducible Example" for more guidance.
You can edit your original issue or leave a comment with the repro link. Issues without reproductions may be closed after 14 days.