Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/iOS/CustomViews/AutocompleteTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class AutocompleteTextField: UITextField, UITableViewDataSource, UITableViewDele
selector: #selector(keyboardWillChange(_:)),
name: UIResponder.keyboardWillChangeFrameNotification,
object: nil)
NotificationCenter.default.addObserver(
self,
selector: #selector(appWillResignActive(_:)),
name: UIApplication.willResignActiveNotification,
object: nil)

addTarget(self, action: #selector(editingChanged), for: .editingChanged)
addTarget(self, action: #selector(editingEnded), for: .editingDidEnd)
Expand Down Expand Up @@ -121,6 +126,12 @@ class AutocompleteTextField: UITextField, UITableViewDataSource, UITableViewDele
}
}

@objc func appWillResignActive(_ nsNotification: Notification) {
guard !filteredCompletions.isEmpty else { return }

clearFilteredCompletionsInternal()
}

func frameForCompletionTableView() -> CGRect {
guard let cell = superviewOfType(UITableViewCell.self),
let tableView = cell.superviewOfType(UITableView.self)
Expand Down Expand Up @@ -256,6 +267,15 @@ class AutocompleteTextField: UITextField, UITableViewDataSource, UITableViewDele

@objc private func editingEnded() {
clearFilteredCompletionsInternal()

// Defensively restore scrolling: if the overlay teardown path was
// skipped (e.g. the app resigned active while completions showed),
// the enclosing table would otherwise stay unscrollable.
if let cell = superviewOfType(UITableViewCell.self),
let tableView = cell.superviewOfType(UITableView.self)
{
tableView.isScrollEnabled = true
}
}

override func paste(_ sender: Any?) {
Expand Down
Loading