Skip to content

refactor(ios): drop UIApplication.sendAction keyboard dismiss for binding-driven focus#1167

Merged
datlechin merged 1 commit intomainfrom
refactor/focus-state-query-editor
May 9, 2026
Merged

refactor(ios): drop UIApplication.sendAction keyboard dismiss for binding-driven focus#1167
datlechin merged 1 commit intomainfrom
refactor/focus-state-query-editor

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

P1 #7: replace the imperative UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), ...) keyboard dismiss in QueryEditorView.executeQueryDirect with a SwiftUI @Binding<Bool> focus channel into SQLHighlightTextView.

What changes:

  • SQLHighlightTextView (UIViewRepresentable) gains an @Binding var isFocused: Bool parameter (default .constant(false) so existing call sites that don't care still compile)
  • updateUIView syncs the binding into the wrapped UITextView via becomeFirstResponder() / resignFirstResponder() only when state actually diverges
  • Coordinator gains textViewDidBeginEditing and textViewDidEndEditing to propagate user-driven focus changes back to the binding
  • QueryEditorView adds @State private var editorFocused = false, passes $editorFocused into the editor, and sets editorFocused = false before executing a query, dismissing the keyboard

Why a plain @State Bool and not @FocusState: @FocusState's projected value is FocusState<Bool>.Binding, which doesn't satisfy @Binding var isFocused: Bool. The canonical iOS pattern for UIViewRepresentable focus is parent @State Bool plus two-way sync through the representable's update method and delegate callbacks. The user-visible behavior matches @FocusState: keyboard dismisses declaratively when state flips to false.

Two resignFirstResponder() calls remain inside SQLHighlightTextView itself: one in updateUIView (sync from binding) and one in the toolbar Done button's @objc handler. Both are UIKit-internal and not the imperative SwiftUI escape hatch this PR targets.

Test plan

  • Tap into the SQL editor: keyboard appears, editorFocused becomes true (verify by adding a .onChange print if needed)
  • Tap "Run": keyboard dismisses immediately, query executes
  • Tap "Done" on the editor's input accessory toolbar: keyboard dismisses, editorFocused becomes false via textViewDidEndEditing
  • Tap into another control (e.g., switch to History tab): keyboard dismisses, focus state stays consistent
  • Switch tabs and come back: typing into the editor still works, no stuck focus

@datlechin datlechin merged commit ed2a215 into main May 9, 2026
2 checks passed
@datlechin datlechin deleted the refactor/focus-state-query-editor branch May 10, 2026 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant