@@ -315,11 +315,6 @@ extension ResponsiveTextField: UIViewRepresentable {
315
315
/// first responder.
316
316
///
317
317
public func updateUIView( _ uiView: UITextField , context: Context ) {
318
- guard context. coordinator. shouldUpdateView else {
319
- context. coordinator. shouldUpdateView = true
320
- return
321
- }
322
-
323
318
uiView. isEnabled = isEnabled
324
319
uiView. isSecureTextEntry = isSecure
325
320
uiView. returnKeyType = returnKeyType
@@ -337,13 +332,22 @@ extension ResponsiveTextField: UIViewRepresentable {
337
332
default :
338
333
// If the current responder state matches the demand then
339
334
// the demand is already fulfilled so we can just reset it.
340
- context. coordinator. firstResponderDemandFulfilled ( )
335
+ resetFirstResponderDemandAfterViewUpdate ( )
336
+ }
337
+ }
338
+
339
+ fileprivate func resetFirstResponderDemandAfterViewUpdate( ) {
340
+ // Because the first responder demand will trigger a view
341
+ // update when it is set, we need to wait until the next
342
+ // runloop tick to reset it back to nil to avoid runtime
343
+ // warnings.
344
+ RunLoop . main. schedule {
345
+ firstResponderDemand? . wrappedValue = nil
341
346
}
342
347
}
343
348
344
349
public class Coordinator : NSObject , UITextFieldDelegate {
345
350
var parent : ResponsiveTextField
346
- var shouldUpdateView : Bool = true
347
351
348
352
@Binding
349
353
var text : String
@@ -353,16 +357,11 @@ extension ResponsiveTextField: UIViewRepresentable {
353
357
self . _text = textField. text
354
358
}
355
359
356
- fileprivate func firstResponderDemandFulfilled( ) {
357
- shouldUpdateView = false
358
- parent. firstResponderDemand? . wrappedValue = nil
359
- }
360
-
361
360
public func textFieldShouldBeginEditing( _ textField: UITextField ) -> Bool {
362
361
if let canBecomeFirstResponder = parent. onFirstResponderStateChanged? . canBecomeFirstResponder {
363
362
let shouldBeginEditing = canBecomeFirstResponder ( )
364
363
if !shouldBeginEditing {
365
- firstResponderDemandFulfilled ( )
364
+ parent . resetFirstResponderDemandAfterViewUpdate ( )
366
365
}
367
366
return shouldBeginEditing
368
367
}
@@ -371,14 +370,14 @@ extension ResponsiveTextField: UIViewRepresentable {
371
370
372
371
public func textFieldDidBeginEditing( _ textField: UITextField ) {
373
372
parent. onFirstResponderStateChanged ? ( true )
374
- firstResponderDemandFulfilled ( )
373
+ parent . resetFirstResponderDemandAfterViewUpdate ( )
375
374
}
376
375
377
376
public func textFieldShouldEndEditing( _ textField: UITextField ) -> Bool {
378
377
if let canResignFirstResponder = parent. onFirstResponderStateChanged? . canResignFirstResponder {
379
378
let shouldEndEditing = canResignFirstResponder ( )
380
379
if !shouldEndEditing {
381
- firstResponderDemandFulfilled ( )
380
+ parent . resetFirstResponderDemandAfterViewUpdate ( )
382
381
}
383
382
return shouldEndEditing
384
383
}
@@ -387,7 +386,7 @@ extension ResponsiveTextField: UIViewRepresentable {
387
386
388
387
public func textFieldDidEndEditing( _ textField: UITextField ) {
389
388
parent. onFirstResponderStateChanged ? ( false )
390
- firstResponderDemandFulfilled ( )
389
+ parent . resetFirstResponderDemandAfterViewUpdate ( )
391
390
}
392
391
393
392
public func textFieldShouldReturn( _ textField: UITextField ) -> Bool {
0 commit comments