@@ -33,7 +33,6 @@ public struct ResponsiveTextField {
33
33
///
34
34
/// To detect when the text field actually becomes or resigns first responder, use the
35
35
/// `.onFirstResponderChange()` callback function.
36
- ///
37
36
var firstResponderDemand : Binding < FirstResponderDemand ? > ?
38
37
39
38
/// Allows for the text field to be configured during creation.
@@ -84,6 +83,30 @@ public struct ResponsiveTextField {
84
83
/// Return `true` to allow the change or `false` to prevent the change.
85
84
var shouldChange : ( ( String , String ) -> Bool ) ?
86
85
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
+
87
110
fileprivate var shouldUpdateView : Bool = true
88
111
89
112
public init (
@@ -95,7 +118,9 @@ public struct ResponsiveTextField {
95
118
onFirstResponderStateChanged: FirstResponderStateChangeHandler ? = nil ,
96
119
handleReturn: ( ( ) -> Void ) ? = nil ,
97
120
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
99
124
) {
100
125
self . placeholder = placeholder
101
126
self . text = text
@@ -106,12 +131,8 @@ public struct ResponsiveTextField {
106
131
self . handleReturn = handleReturn
107
132
self . handleDelete = handleDelete
108
133
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
115
136
}
116
137
117
138
fileprivate mutating func firstResponderDemandFulfilled( ) {
@@ -153,10 +174,12 @@ public enum FirstResponderDemand: Equatable {
153
174
154
175
extension ResponsiveTextField : UIViewRepresentable {
155
176
public func makeUIView( context: Context ) -> UITextField {
156
- let textField = DeleteHandlingTextField ( )
177
+ let textField = _UnderlyingTextField ( )
157
178
configuration. configure ( textField)
158
179
// This stops the text field from expanding if the text overflows the frame width
159
180
textField. handleDelete = handleDelete
181
+ textField. supportedStandardEditActions = supportedStandardEditActions
182
+ textField. standardEditActionHandler = standardEditActionHandler
160
183
textField. setContentCompressionResistancePriority ( . defaultLow, for: . horizontal)
161
184
textField. placeholder = placeholder
162
185
textField. text = text. wrappedValue
@@ -256,8 +279,10 @@ extension ResponsiveTextField: UIViewRepresentable {
256
279
}
257
280
}
258
281
259
- private class DeleteHandlingTextField : UITextField {
282
+ class _UnderlyingTextField : UITextField {
260
283
var handleDelete : ( ( String ) -> Void ) ?
284
+ var supportedStandardEditActions : Set < StandardEditAction > ?
285
+ var standardEditActionHandler : StandardEditActionHandling < UITextField > ?
261
286
262
287
override func deleteBackward( ) {
263
288
handleDelete ? ( text ?? " " )
0 commit comments