@@ -33,7 +33,6 @@ public struct ResponsiveTextField {
3333 ///
3434 /// To detect when the text field actually becomes or resigns first responder, use the
3535 /// `.onFirstResponderChange()` callback function.
36- ///
3736 var firstResponderDemand : Binding < FirstResponderDemand ? > ?
3837
3938 /// Allows for the text field to be configured during creation.
@@ -84,6 +83,30 @@ public struct ResponsiveTextField {
8483 /// Return `true` to allow the change or `false` to prevent the change.
8584 var shouldChange : ( ( String , String ) -> Bool ) ?
8685
86+ /// A list of supported standard editing actions.
87+ ///
88+ /// When set, this will override the default standard edit actions for a `UITextField`. Leave
89+ /// set to `nil` if you only want to support the default actions.
90+ ///
91+ /// You can use this property and `standardEditActionHandler` to support both the
92+ /// range of standard editing actions and how each editing action should be handled.
93+ ///
94+ /// If you exclude an edit action from this list, any corresponding action handler set in
95+ /// any provided `standardEditActionHandler` will not be called.
96+ var supportedStandardEditActions : Set < StandardEditAction > ?
97+
98+ /// Can be set to provide custom standard editing action behaviour.
99+ ///
100+ /// When `nil`, all standard editing actions will result in the default `UITextField` behaviour.
101+ ///
102+ /// When set, any overridden actions will be called and if the action handler returns `true`, the
103+ /// default `UITextField` behaviour will also be called. If the action handler returns `false`,
104+ /// the default behaviour will not be called.
105+ ///
106+ /// If the provided type does not implement a particular editing action, the default `UITextField`
107+ /// behaviour will be called.
108+ var standardEditActionHandler : StandardEditActionHandling < UITextField > ?
109+
87110 fileprivate var shouldUpdateView : Bool = true
88111
89112 public init (
@@ -95,7 +118,9 @@ public struct ResponsiveTextField {
95118 onFirstResponderStateChanged: FirstResponderStateChangeHandler ? = nil ,
96119 handleReturn: ( ( ) -> Void ) ? = nil ,
97120 handleDelete: ( ( String ) -> Void ) ? = nil ,
98- shouldChange: ( ( String , String ) -> Bool ) ? = nil
121+ shouldChange: ( ( String , String ) -> Bool ) ? = nil ,
122+ supportedStandardEditActions: Set < StandardEditAction > ? = nil ,
123+ standardEditActionHandler: StandardEditActionHandling < UITextField > ? = nil
99124 ) {
100125 self . placeholder = placeholder
101126 self . text = text
@@ -106,12 +131,8 @@ public struct ResponsiveTextField {
106131 self . handleReturn = handleReturn
107132 self . handleDelete = handleDelete
108133 self . shouldChange = shouldChange
109- }
110-
111- fileprivate mutating func skippingViewUpdates( _ callback: ( ) -> Void ) {
112- shouldUpdateView = false
113- callback ( )
114- shouldUpdateView = true
134+ self . supportedStandardEditActions = supportedStandardEditActions
135+ self . standardEditActionHandler = standardEditActionHandler
115136 }
116137
117138 fileprivate mutating func firstResponderDemandFulfilled( ) {
@@ -153,10 +174,12 @@ public enum FirstResponderDemand: Equatable {
153174
154175extension ResponsiveTextField : UIViewRepresentable {
155176 public func makeUIView( context: Context ) -> UITextField {
156- let textField = DeleteHandlingTextField ( )
177+ let textField = _UnderlyingTextField ( )
157178 configuration. configure ( textField)
158179 // This stops the text field from expanding if the text overflows the frame width
159180 textField. handleDelete = handleDelete
181+ textField. supportedStandardEditActions = supportedStandardEditActions
182+ textField. standardEditActionHandler = standardEditActionHandler
160183 textField. setContentCompressionResistancePriority ( . defaultLow, for: . horizontal)
161184 textField. placeholder = placeholder
162185 textField. text = text. wrappedValue
@@ -256,8 +279,10 @@ extension ResponsiveTextField: UIViewRepresentable {
256279 }
257280}
258281
259- private class DeleteHandlingTextField : UITextField {
282+ class _UnderlyingTextField : UITextField {
260283 var handleDelete : ( ( String ) -> Void ) ?
284+ var supportedStandardEditActions : Set < StandardEditAction > ?
285+ var standardEditActionHandler : StandardEditActionHandling < UITextField > ?
261286
262287 override func deleteBackward( ) {
263288 handleDelete ? ( text ?? " " )
0 commit comments