From d573002be536075c275d961247c30f3d3505b5e3 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 11 Jul 2024 14:04:07 -0500 Subject: [PATCH] refactored textfield Signed-off-by: Matt Bruce --- .../TextFields/InputField/TextField.swift | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/VDS/Components/TextFields/InputField/TextField.swift b/VDS/Components/TextFields/InputField/TextField.swift index 05dc30f2..b56f3423 100644 --- a/VDS/Components/TextFields/InputField/TextField.swift +++ b/VDS/Components/TextFields/InputField/TextField.swift @@ -47,6 +47,11 @@ open class TextField: UITextField, ViewProtocol, Errorable { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- + /// Set to true to hide the blinking textField cursor. + open var hideBlinkingCaret = false + open var enableClipboardActions: Bool = true + open var onDidDeleteBackwards: (() -> Void)? + /// Key of whether or not updateView() is called in setNeedsUpdate() open var shouldUpdateView: Bool = true @@ -209,6 +214,23 @@ open class TextField: UITextField, ViewProtocol, Errorable { return success } + open override func caretRect(for position: UITextPosition) -> CGRect { + + if hideBlinkingCaret { + return .zero + } + + let caretRect = super.caretRect(for: position) + return CGRect(origin: caretRect.origin, size: CGSize(width: 1, height: caretRect.height)) + } + + open override func deleteBackward() { + super.deleteBackward() + onDidDeleteBackwards?() + } + + open override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { enableClipboardActions } + //-------------------------------------------------- // MARK: - Private Methods //--------------------------------------------------