-
-
Save sturdysturge/01a74e03b9aba35ae47aad4fd3a6604a to your computer and use it in GitHub Desktop.
CustomTextFieldCoordinator First Responder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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