fix(ios): animate sheet back to detent on keyboard dismiss#604
Open
TheOmran wants to merge 1 commit intolodev09:mainfrom
Open
fix(ios): animate sheet back to detent on keyboard dismiss#604TheOmran wants to merge 1 commit intolodev09:mainfrom
TheOmran wants to merge 1 commit intolodev09:mainfrom
Conversation
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
|
@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. |
Author
|
@lodev09 🙏🏼 |
Owner
|
@TheOmran do you have a video showing before/after? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
TrueSheetKeyboardObserverchecksisFirstResponderWithinSheetbefore forwardingkeyboardWillChangeFrame:notifications to delegates. When the keyboard hides, the first responder has already resigned by the time the notification fires, so the check returnsNOand the hide event is silently dropped.Without the hide event being forwarded,
UISheetPresentationControllerrecalculates the custom detent position without being wrapped in ananimateChanges:block, causing the snap instead of a smooth animation.Fix
Track keyboard state per sheet — Added
_wasShowingForSheetflag toTrueSheetKeyboardObserver. 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.Forward keyboard hide to the sheet — Registered
TrueSheetContainerViewas a keyboard observer delegate. OnkeyboardWillHide:, it notifies the delegate via a new optionalcontainerViewKeyboardWillHidemethod.Force animated detent reconfiguration —
TrueSheetViewimplementscontainerViewKeyboardWillHideby callingsetupSheetDetentsForSizeChange, 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 sheetios/TrueSheetContainerView.h— New optional delegate methodios/TrueSheetContainerView.mm— Keyboard observer delegate implementationios/TrueSheetView.mm— Animated detent reconfiguration on keyboard hide