@@ -11,7 +11,7 @@ import SwiftUI
11
11
/// A SwiftUI wrapper around UITextField that gives precise control over the responder state.
12
12
///
13
13
public struct ResponsiveTextField {
14
- /// The text field placeholder string
14
+ /// The text field placeholder string.
15
15
let placeholder : String
16
16
17
17
/// A binding to the text state that will hold the typed text
@@ -30,8 +30,8 @@ public struct ResponsiveTextField {
30
30
///
31
31
/// A wrapped value of `nil` indicates there is no demand (or any previous demand has been fulfilled).
32
32
///
33
- /// To detect when the text field actually becomes or resigns first responder, use the
34
- /// `.onFirstResponderChange()` callback function .
33
+ /// To detect when the text field actually becomes or resigns first responder, pass in a `onFirstResponderStateChanged`
34
+ /// handler .
35
35
var firstResponderDemand : Binding < FirstResponderDemand ? > ?
36
36
37
37
/// Allows for the text field to be configured during creation.
@@ -55,7 +55,7 @@ public struct ResponsiveTextField {
55
55
@Environment ( \. textFieldTextColor)
56
56
var textColor : UIColor
57
57
58
- /// Sets the text field alignment - use the w `.textFieldTextAlignemnt()` modifier.
58
+ /// Sets the text field alignment - use the `.textFieldTextAlignemnt()` modifier.
59
59
@Environment ( \. textFieldTextAlignment)
60
60
var textAlignment : NSTextAlignment
61
61
@@ -158,21 +158,24 @@ public struct FirstResponderStateChangeHandler {
158
158
///
159
159
/// If the responder change was triggered programatically by a `FirstResponderDemand`
160
160
/// and this returns `false` the demand will still be marked as fulfilled and reset to `nil`.
161
+ ///
161
162
public var canBecomeFirstResponder : ( ( ) -> Bool ) ?
162
163
163
- /// Allows fine-grained control over if the text field should become the first responder.
164
+ /// Allows fine-grained control over if the text field should resign the first responder.
164
165
///
165
166
/// This will be called when the text field's `shouldEndEditing` delegate method is
166
167
/// called and provides a final opportunity to prevent the text field from resigning first responder.
167
168
///
168
169
/// If the responder change was triggered programatically by a `FirstResponderDemand`
169
170
/// and this returns `false` the demand will still be marked as fulfilled and reset to `nil`.
171
+ ///
170
172
public var canResignFirstResponder : ( ( ) -> Bool ) ?
171
173
172
174
/// Initialises a state change handler with a `handleStateChange` callback.
173
175
///
174
176
/// Most of the time this is the only callback that you will need to provide so this initialiser
175
177
/// can be called with trailing closure syntax.
178
+ ///
176
179
public init ( handleStateChange: @escaping ( Bool ) -> Void ) {
177
180
self . handleStateChange = handleStateChange
178
181
}
@@ -215,6 +218,7 @@ public struct FirstResponderStateChangeHandler {
215
218
///
216
219
/// - Parameters:
217
220
/// - scheduler: The scheduler to schedule the callback on when the first responder state changes.
221
+ /// - options: Options to be passed to the scheduler when scheduling.
218
222
///
219
223
/// This modifier is useful when your first responder state change handler needs to perform some state
220
224
/// mutation that will trigger a new view update and you are programatically triggering the first responder state
@@ -242,7 +246,9 @@ public struct FirstResponderStateChangeHandler {
242
246
public func receive< S: Scheduler > ( on scheduler: S , options: S . SchedulerOptions ? = nil ) -> Self {
243
247
return . init(
244
248
handleStateChange: { isFirstResponder in
245
- scheduler. schedule { self . handleStateChange ( isFirstResponder) }
249
+ scheduler. schedule ( options: options) {
250
+ self . handleStateChange ( isFirstResponder)
251
+ }
246
252
} ,
247
253
canBecomeFirstResponder: canBecomeFirstResponder,
248
254
canResignFirstResponder: canResignFirstResponder
@@ -286,11 +292,9 @@ extension ResponsiveTextField: UIViewRepresentable {
286
292
public func makeUIView( context: Context ) -> UITextField {
287
293
let textField = _UnderlyingTextField ( )
288
294
configuration. configure ( textField)
289
- // This stops the text field from expanding if the text overflows the frame width
290
295
textField. handleDelete = handleDelete
291
296
textField. supportedStandardEditActions = supportedStandardEditActions
292
297
textField. standardEditActionHandler = standardEditActionHandler
293
- textField. setContentCompressionResistancePriority ( . defaultLow, for: . horizontal)
294
298
textField. placeholder = placeholder
295
299
textField. text = text. wrappedValue
296
300
textField. isEnabled = isEnabled
@@ -304,6 +308,8 @@ extension ResponsiveTextField: UIViewRepresentable {
304
308
action: #selector( Coordinator . textFieldTextChanged ( _: ) ) ,
305
309
for: . editingChanged
306
310
)
311
+ // This stops the text field from expanding if the text overflows the frame width
312
+ textField. setContentCompressionResistancePriority ( . defaultLow, for: . horizontal)
307
313
return textField
308
314
}
309
315
@@ -314,7 +320,7 @@ extension ResponsiveTextField: UIViewRepresentable {
314
320
/// Will update the text view when the containing view triggers a body re-calculation.
315
321
///
316
322
/// If the first responder state has changed, this may trigger the textfield to become or resign
317
- /// first responder status .
323
+ /// first responder.
318
324
///
319
325
public func updateUIView( _ uiView: UITextField , context: Context ) {
320
326
guard shouldUpdateView else { return }
0 commit comments