-
-
Notifications
You must be signed in to change notification settings - Fork 93
Description
Description
When implementing sceneStoppedBeingFirstResponder() as documented in the wiki for keyboard focus in popups, it causes the main view's TextField (outside of any popup) to lose keyboard focus.
Environment
- MijickPopups version: 4.0.5
- iOS version: 18.x / 26.x
- Xcode version: 16.x
Problem
The wiki recommends overriding sceneStoppedBeingFirstResponder() to call makeSceneKey():
override func sceneStoppedBeingFirstResponder() {
makeSceneKey()
}This fixes keyboard issues inside popups (as described in issue #187), but it causes a new problem: TextFields in the main view (not inside any popup) fail to show the keyboard automatically.
Root Cause Analysis
Through debugging, I found the issue in Window.resignKey():
override func resignKey() {
super.resignKey()
scene?.sceneStoppedBeingFirstResponder()
}When a TextField in the main view tries to become first responder:
Window.resignKey()is called (MijickPopups window loses key status)sceneStoppedBeingFirstResponder()is calledmakeSceneKey()is called, which interferes with the TextField's focus- TextField's
@FocusStateis set totrue, but keyboard doesn't appear
Debug logs confirm this sequence:
🔴 [MijickPopups] Window.resignKey() called
🔴 [MijickPopups] PopupStack count: 0 // No popup is showing!
🟡 [SceneDelegate] sceneStoppedBeingFirstResponder() called
🟡 [SceneDelegate] calling makeSceneKey()
🟢 [SearchField] onAppear, setting isFocused = true
🟢 [SearchField] isFocused changed to: true // But keyboard doesn't show
Expected Behavior
- Main view TextFields should show keyboard automatically when focused
- Popup TextFields should also show keyboard automatically when focused
- Both scenarios should work without interfering with each other
Reproduction Steps
- Set up
PopupSceneDelegatewithsceneStoppedBeingFirstResponder()callingmakeSceneKey() - Have a TextField in the main view (not inside any popup)
- Trigger the TextField to become focused (e.g., via
@FocusState) - Observe that the keyboard doesn't appear
Related Issues
- [BUG] Keyboard not display automatically when set @FocusState #187 - [BUG] Keyboard not display automatically when set @focusstate
- When in editing mode, dismissing popups will cause the keyboard to disappear. #169 - When in editing mode, dismissing popups will cause the keyboard to disappear
Bad document.
The document key-window-state-management is very misleading. If you call makeKey here, an input field not in the popup UIWindow will not have its key window set. Then, your input field will never get focused to show the keyboard. It took me 1 day to figure it out.