Skip to content

Commit 62df15c

Browse files
author
Stephanie Sharp
committed
Fix animation bug with text field caret
1 parent c6e0c49 commit 62df15c

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

MaterialTextField/MFTextField.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ - (void)showPlaceholderLabelAnimated:(BOOL)animated
416416
}
417417

418418
if (animated && !self.placeholderIsAnimating) {
419-
[self setNeedsLayout];
419+
[self.superview layoutIfNeeded];
420+
420421
self.placeholderIsAnimating = YES;
421422
self.placeholderLabelTopConstraint.constant = 0;
422423

@@ -449,7 +450,8 @@ - (void)hidePlaceholderLabelAnimated:(BOOL)animated
449450
}
450451

451452
if (animated && !self.placeholderIsAnimating) {
452-
[self setNeedsLayout];
453+
[self.superview layoutIfNeeded];
454+
453455
self.placeholderIsAnimating = YES;
454456
self.placeholderLabelTopConstraint.constant = finalDistanceFromTop;
455457

@@ -522,7 +524,8 @@ - (void)showErrorLabelAnimated:(BOOL)animated
522524
[self updateErrorLabelText];
523525

524526
if (animated && !self.errorIsAnimating) {
525-
[self setNeedsLayout];
527+
[self.superview layoutIfNeeded];
528+
526529
self.errorIsAnimating = YES;
527530
self.errorLabelHeightConstraint.active = NO;
528531
self.errorLabelTopConstraint.constant = [self topPaddingForErrorLabelHidden:NO];
@@ -551,14 +554,15 @@ - (void)showErrorLabelAnimated:(BOOL)animated
551554
- (void)hideErrorLabelAnimated:(BOOL)animated
552555
{
553556
if (animated && !self.errorIsAnimating) {
554-
[self setNeedsLayout];
555557
self.errorIsAnimating = YES;
556558
[UIView animateWithDuration:MFDefaultAnimationDuration * 0.5
557559
delay:0.0
558560
options:UIViewAnimationOptionCurveEaseOut
559561
animations:^{
560562
self.errorLabel.alpha = 0.0f;
561563
} completion:^(BOOL finished) {
564+
[self.superview layoutIfNeeded];
565+
562566
self.errorLabelTopConstraint.constant = [self topPaddingForErrorLabelHidden:YES];
563567
self.errorLabelHeightConstraint.active = YES;
564568

0 commit comments

Comments
 (0)