Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Last active December 30, 2020 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/01a74e03b9aba35ae47aad4fd3a6604a to your computer and use it in GitHub Desktop.
Save sturdysturge/01a74e03b9aba35ae47aad4fd3a6604a to your computer and use it in GitHub Desktop.
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