WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

[BUG] sceneStoppedBeingFirstResponder() interferes with main view TextField keyboard #195

@videni

Description

@videni

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:

  1. Window.resignKey() is called (MijickPopups window loses key status)
  2. sceneStoppedBeingFirstResponder() is called
  3. makeSceneKey() is called, which interferes with the TextField's focus
  4. 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

  1. Set up PopupSceneDelegate with sceneStoppedBeingFirstResponder() calling makeSceneKey()
  2. Have a TextField in the main view (not inside any popup)
  3. Trigger the TextField to become focused (e.g., via @FocusState)
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions