Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CustomTextFieldCoordinator First Responder
import UIKit
import SwiftUI
class CustomTextFieldCoordinator: NSObject, UITextFieldDelegate {
@Binding var text: String
@Binding var isResponder: Bool
init(text: Binding<String>, isResponder : Binding<Bool>) {
self._text = text
self._isResponder = isResponder
}
func setResponder(_ isResponder: Bool) {
DispatchQueue.main.async { self.isResponder = isResponder }
}
func textFieldDidChangeSelection(_ textField: UITextField) { text = textField.text ?? "" }
func textFieldDidBeginEditing(_ textField: UITextField) { setResponder(true) }
func textFieldDidEndEditing(_ textField: UITextField) { setResponder(false) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment