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 called
makeSceneKey() is called, which interferes with the TextField's focus
- TextField's
@FocusState is set to true, 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
PopupSceneDelegate with sceneStoppedBeingFirstResponder() calling makeSceneKey()
- 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
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.
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
Problem
The wiki recommends overriding
sceneStoppedBeingFirstResponder()to callmakeSceneKey():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():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@FocusStateis set totrue, but keyboard doesn't appearDebug logs confirm this sequence:
Expected Behavior
Reproduction Steps
PopupSceneDelegatewithsceneStoppedBeingFirstResponder()callingmakeSceneKey()@FocusState)Related Issues
Bad document.
The document key-window-state-management is very misleading. If you call
makeKeyhere, 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.