Skip to content

Commit

Permalink
[ProgressView] Make indeterminate progress view example showing how t…
Browse files Browse the repository at this point in the history
…ransition looks.

PiperOrigin-RevId: 316958915
  • Loading branch information
wenyuzhang666 authored and material-automation committed Jun 17, 2020
1 parent b7f5b0d commit d5b47fc
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions components/ProgressView/examples/ProgressViewExample.m
Expand Up @@ -20,6 +20,7 @@
#import "MaterialTypographyScheme.h"

static const CGFloat MDCProgressViewAnimationDuration = 1;
static const CGFloat MDCProgressViewIndeterminateAnimationDuration = 4;

@interface ProgressViewExample : UIViewController

Expand Down Expand Up @@ -103,10 +104,10 @@ - (void)setupProgressViews {

_indeterminateProgressView = [[MDCProgressView alloc] init];
_indeterminateProgressView.translatesAutoresizingMaskIntoConstraints = NO;
_indeterminateProgressView.mode = MDCProgressViewModeIndeterminate;
_indeterminateProgressView.progressTintColor = self.colorScheme.primaryColor;
_indeterminateProgressView.trackTintColor =
[self.colorScheme.primaryColor colorWithAlphaComponent:(CGFloat)0.24];
_indeterminateProgressView.progress = 0.33f;
[self.container addSubview:_indeterminateProgressView];
}

Expand Down Expand Up @@ -294,7 +295,7 @@ - (void)didPressAnimateButton:(UIButton *)sender {
completion:^(BOOL ignored) {
sender.enabled = YES;
}];
[self animateIndeterminateProgressBarWithCountdown:4];
[self animateIndeterminateProgressBarWithCountdown:1];
}

- (void)animateStep1:(MDCProgressView *)progressView {
Expand Down Expand Up @@ -362,23 +363,25 @@ - (void)animateBackwardProgressAnimateViewWithCountdown:(NSInteger)remainingCoun
}

- (void)animateIndeterminateProgressBarWithCountdown:(NSInteger)remainingCounts {
--remainingCounts;
__weak ProgressViewExample *weakSelf = self;

if (!_indeterminateProgressView.animating) {
[_indeterminateProgressView setHidden:NO animated:YES completion:nil];
[_indeterminateProgressView setMode:MDCProgressViewModeIndeterminate
animated:YES
completion:nil];
[_indeterminateProgressView startAnimating];
}

if (remainingCounts > 0) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
(int64_t)(MDCProgressViewAnimationDuration * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
[weakSelf animateIndeterminateProgressBarWithCountdown:remainingCounts];
});
dispatch_after(
dispatch_time(DISPATCH_TIME_NOW,
(int64_t)(MDCProgressViewIndeterminateAnimationDuration * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
[weakSelf animateIndeterminateProgressBarWithCountdown:remainingCounts - 1];
});
} else {
[_indeterminateProgressView setHidden:YES animated:YES completion:nil];
[_indeterminateProgressView stopAnimating];
[_indeterminateProgressView setMode:MDCProgressViewModeDeterminate animated:YES completion:nil];
}
}

Expand Down

0 comments on commit d5b47fc

Please sign in to comment.