Skip to content

fix(ios): animate sheet back to detent on keyboard dismiss#604

Open
TheOmran wants to merge 1 commit intolodev09:mainfrom
TheOmran:fix/ios-keyboard-dismiss-animation
Open

fix(ios): animate sheet back to detent on keyboard dismiss#604
TheOmran wants to merge 1 commit intolodev09:mainfrom
TheOmran:fix/ios-keyboard-dismiss-animation

Conversation

@TheOmran
Copy link

Bug

When using custom detents (especially 'auto'), dismissing the keyboard causes the sheet to snap back to its detent position instead of smoothly animating the transition. This affects any sheet with text inputs that uses custom or auto-sized detents.

Root Cause

TrueSheetKeyboardObserver checks isFirstResponderWithinSheet before forwarding keyboardWillChangeFrame: notifications to delegates. When the keyboard hides, the first responder has already resigned by the time the notification fires, so the check returns NO and the hide event is silently dropped.

Without the hide event being forwarded, UISheetPresentationController recalculates the custom detent position without being wrapped in an animateChanges: block, causing the snap instead of a smooth animation.

Fix

  1. Track keyboard state per sheet — Added _wasShowingForSheet flag to TrueSheetKeyboardObserver. When the keyboard shows for this sheet, the flag is set. On keyboard hide, the first-responder check is skipped if the flag was set (then reset), ensuring the hide event is always forwarded when the keyboard was previously shown for this sheet.

  2. Forward keyboard hide to the sheet — Registered TrueSheetContainerView as a keyboard observer delegate. On keyboardWillHide:, it notifies the delegate via a new optional containerViewKeyboardWillHide method.

  3. Force animated detent reconfigurationTrueSheetView implements containerViewKeyboardWillHide by calling setupSheetDetentsForSizeChange, which wraps the detent reconfiguration in [sheet animateChanges:], forcing UIKit to animate the transition back to the custom detent.

Files Changed

  • ios/core/TrueSheetKeyboardObserver.mm — State tracking for keyboard show/hide per sheet
  • ios/TrueSheetContainerView.h — New optional delegate method
  • ios/TrueSheetContainerView.mm — Keyboard observer delegate implementation
  • ios/TrueSheetView.mm — Animated detent reconfiguration on keyboard hide

When using custom detents (especially 'auto'), the sheet snaps back
to its detent position instead of animating when the keyboard dismisses.

The root cause is that keyboardWillChangeFrame: checks
isFirstResponderWithinSheet before forwarding events. When the keyboard
hides, the first responder has already resigned, so the hide event is
silently dropped and UISheetPresentationController recalculates the
custom detent without an animation block.

Fix:
- Track whether keyboard was shown for this sheet (_wasShowingForSheet)
- On keyboard hide, skip the first-responder check if the flag is set
- Register TrueSheetContainerView as a keyboard observer delegate
- On keyboardWillHide, call setupSheetDetentsForSizeChange which wraps
  the detent reconfiguration in [sheet animateChanges:], forcing UIKit
  to animate the transition back to the custom detent
@vercel
Copy link

vercel bot commented Mar 15, 2026

@TheOmran is attempting to deploy a commit to the Jovanni's projects Team on Vercel.

A member of the Team first needs to authorize it.

@TheOmran
Copy link
Author

@lodev09 🙏🏼

@lodev09
Copy link
Owner

lodev09 commented Mar 15, 2026

@TheOmran do you have a video showing before/after?

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.

2 participants