From 9efe297a4c613cc77678edd2397b2a538ad42dab Mon Sep 17 00:00:00 2001 From: featherless Date: Mon, 4 Dec 2017 11:14:49 -0500 Subject: [PATCH] [ProgressView] Execute the same logical paths for completion and animation. (#2564) This re-introduces logic to the non-animated paths of setProgress and setHidden that were unintentionally removed in d8919eb8a2ab64eb60968610f11f28b6eef727a5. --- components/ProgressView/src/MDCProgressView.m | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/components/ProgressView/src/MDCProgressView.m b/components/ProgressView/src/MDCProgressView.m index 153f1d6dae9..850598e7eb8 100644 --- a/components/ProgressView/src/MDCProgressView.m +++ b/components/ProgressView/src/MDCProgressView.m @@ -131,7 +131,7 @@ - (void)setProgress:(float)progress { - (void)setProgress:(float)progress animated:(BOOL)animated - completion:(void (^__nullable)(BOOL finished))completion { + completion:(void (^__nullable)(BOOL finished))userCompletion { if (progress < self.progress && self.backwardProgressAnimationMode == MDCProgressViewBackwardAnimationModeReset) { self.progress = 0; @@ -140,18 +140,21 @@ - (void)setProgress:(float)progress self.progress = progress; - if (!animated) { + void (^animations)(void) = ^{ [self updateProgressView]; + }; + void (^completion)(void) = ^{ + if (userCompletion) { + userCompletion(YES); + } + }; - } else { + if (animated) { MDMMotionTiming timing = MDCProgressViewMotionSpec.willChangeProgress; - [_animator animateWithTiming:timing animations:^{ - [self updateProgressView]; - } completion:^{ - if (completion) { - completion(YES); - } - }]; + [_animator animateWithTiming:timing animations:animations completion:completion]; + } else { + animations(); + completion(); } } @@ -162,10 +165,10 @@ - (void)setHidden:(BOOL)hidden { - (void)setHidden:(BOOL)hidden animated:(BOOL)animated - completion:(void (^__nullable)(BOOL finished))completion { + completion:(void (^__nullable)(BOOL finished))userCompletion { if (hidden == self.hidden) { - if (completion) { - completion(YES); + if (userCompletion) { + userCompletion(YES); } return; } @@ -199,23 +202,22 @@ - (void)setHidden:(BOOL)hidden }; } + void (^completion)(void) = ^{ + if (hidden) { + self.animatingHide = NO; + self.hidden = YES; + } + if (userCompletion) { + userCompletion(YES); + } + }; + if (animated) { MDMMotionTiming timing = MDCProgressViewMotionSpec.willChangeHidden; - [_animator animateWithTiming:timing animations:animations completion:^{ - if (hidden) { - self.animatingHide = NO; - self.hidden = YES; - } - if (completion) { - completion(YES); - } - }]; - + [_animator animateWithTiming:timing animations:animations completion:completion]; } else { animations(); - if (completion) { - completion(YES); - } + completion(); } }