@@ -11,7 +11,7 @@ import SwiftUI
1111/// A SwiftUI wrapper around UITextField that gives precise control over the responder state.
1212///
1313public struct ResponsiveTextField {
14- /// The text field placeholder string
14+ /// The text field placeholder string.
1515 let placeholder : String
1616
1717 /// A binding to the text state that will hold the typed text
@@ -30,8 +30,8 @@ public struct ResponsiveTextField {
3030 ///
3131 /// A wrapped value of `nil` indicates there is no demand (or any previous demand has been fulfilled).
3232 ///
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 .
3535 var firstResponderDemand : Binding < FirstResponderDemand ? > ?
3636
3737 /// Allows for the text field to be configured during creation.
@@ -55,7 +55,7 @@ public struct ResponsiveTextField {
5555 @Environment ( \. textFieldTextColor)
5656 var textColor : UIColor
5757
58- /// Sets the text field alignment - use the w `.textFieldTextAlignemnt()` modifier.
58+ /// Sets the text field alignment - use the `.textFieldTextAlignemnt()` modifier.
5959 @Environment ( \. textFieldTextAlignment)
6060 var textAlignment : NSTextAlignment
6161
@@ -158,21 +158,24 @@ public struct FirstResponderStateChangeHandler {
158158 ///
159159 /// If the responder change was triggered programatically by a `FirstResponderDemand`
160160 /// and this returns `false` the demand will still be marked as fulfilled and reset to `nil`.
161+ ///
161162 public var canBecomeFirstResponder : ( ( ) -> Bool ) ?
162163
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.
164165 ///
165166 /// This will be called when the text field's `shouldEndEditing` delegate method is
166167 /// called and provides a final opportunity to prevent the text field from resigning first responder.
167168 ///
168169 /// If the responder change was triggered programatically by a `FirstResponderDemand`
169170 /// and this returns `false` the demand will still be marked as fulfilled and reset to `nil`.
171+ ///
170172 public var canResignFirstResponder : ( ( ) -> Bool ) ?
171173
172174 /// Initialises a state change handler with a `handleStateChange` callback.
173175 ///
174176 /// Most of the time this is the only callback that you will need to provide so this initialiser
175177 /// can be called with trailing closure syntax.
178+ ///
176179 public init ( handleStateChange: @escaping ( Bool ) -> Void ) {
177180 self . handleStateChange = handleStateChange
178181 }
@@ -215,6 +218,7 @@ public struct FirstResponderStateChangeHandler {
215218 ///
216219 /// - Parameters:
217220 /// - 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.
218222 ///
219223 /// This modifier is useful when your first responder state change handler needs to perform some state
220224 /// mutation that will trigger a new view update and you are programatically triggering the first responder state
@@ -242,7 +246,9 @@ public struct FirstResponderStateChangeHandler {
242246 public func receive< S: Scheduler > ( on scheduler: S , options: S . SchedulerOptions ? = nil ) -> Self {
243247 return . init(
244248 handleStateChange: { isFirstResponder in
245- scheduler. schedule { self . handleStateChange ( isFirstResponder) }
249+ scheduler. schedule ( options: options) {
250+ self . handleStateChange ( isFirstResponder)
251+ }
246252 } ,
247253 canBecomeFirstResponder: canBecomeFirstResponder,
248254 canResignFirstResponder: canResignFirstResponder
@@ -286,11 +292,9 @@ extension ResponsiveTextField: UIViewRepresentable {
286292 public func makeUIView( context: Context ) -> UITextField {
287293 let textField = _UnderlyingTextField ( )
288294 configuration. configure ( textField)
289- // This stops the text field from expanding if the text overflows the frame width
290295 textField. handleDelete = handleDelete
291296 textField. supportedStandardEditActions = supportedStandardEditActions
292297 textField. standardEditActionHandler = standardEditActionHandler
293- textField. setContentCompressionResistancePriority ( . defaultLow, for: . horizontal)
294298 textField. placeholder = placeholder
295299 textField. text = text. wrappedValue
296300 textField. isEnabled = isEnabled
@@ -304,6 +308,8 @@ extension ResponsiveTextField: UIViewRepresentable {
304308 action: #selector( Coordinator . textFieldTextChanged ( _: ) ) ,
305309 for: . editingChanged
306310 )
311+ // This stops the text field from expanding if the text overflows the frame width
312+ textField. setContentCompressionResistancePriority ( . defaultLow, for: . horizontal)
307313 return textField
308314 }
309315
@@ -314,7 +320,7 @@ extension ResponsiveTextField: UIViewRepresentable {
314320 /// Will update the text view when the containing view triggers a body re-calculation.
315321 ///
316322 /// If the first responder state has changed, this may trigger the textfield to become or resign
317- /// first responder status .
323+ /// first responder.
318324 ///
319325 public func updateUIView( _ uiView: UITextField , context: Context ) {
320326 guard shouldUpdateView else { return }
0 commit comments