Skip to content

Commit

Permalink
[ProgressView] Execute the same logical paths for completion and anim…
Browse files Browse the repository at this point in the history
…ation. (#2564)

This re-introduces logic to the non-animated paths of setProgress and setHidden that were unintentionally removed in d8919eb.
  • Loading branch information
jverkoey committed Dec 4, 2017
1 parent c369526 commit 9efe297
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions components/ProgressView/src/MDCProgressView.m
Expand Up @@ -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;
Expand All @@ -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();
}
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
}
}

Expand Down

0 comments on commit 9efe297

Please sign in to comment.