Fix missing toolbar on SwiftUI keyboard on iOS 26 and above.#21
Open
Cheeezcake wants to merge 1 commit into
Open
Fix missing toolbar on SwiftUI keyboard on iOS 26 and above.#21Cheeezcake wants to merge 1 commit into
Cheeezcake wants to merge 1 commit into
Conversation
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.
Description
Fix keyboard toolbar disappearance after navigation or app backgrounding.
Root cause analysis
The previous implementation used
UIApplication.didBecomeActiveNotificationto callreloadInputViews(). This approach had two major flaws:It only handled app backgrounding, but the same problem occurs after any event that temporarily hides the keyboard without resigning first responder (e.g., navigation push/pop, modal presentation). In those cases
didBecomeActivenever fires, so the toolbar was never restored.Timing issue – even for the background case,
didBecomeActivefires before the keyboard has fully reappeared. CallingreloadInputViews()at that moment has no effect because the keyboard system isn't ready yet.The correct trigger is
UIResponder.keyboardDidShowNotification– it fires exactly when the keyboard is on screen and ready, regardless of why it reappeared (background, navigation, window overlay, etc.).Proposed solution
Subscribe to
keyboardDidShowNotificationand callreloadInputViews()whenever the keyboard appears and the currenttextInputViewis managed by the toolbar manager.Benefits
beginEditingevent (background, navigation, modal presentation, window overlay).didBecomeActiveor arbitrary delays.Known limitation
When the user taps a text field for the first time, the sequence is:
textDidBeginEditing→ triggersreloadInputViews()viaIQTextInputViewNotification(expected).keyboardDidShow→ triggersreloadInputViews()again via the new observer.This results in a double refresh of the toolbar. In practice it's harmless (the toolbar is simply configured twice with the same state), but it's an inefficiency.
If this double call is considered critical – or if you have a better approach – please feel free to propose your own solution. I’m open to alternatives.
Testing
Fixes #15
Type of change