Skip to content

Commit

Permalink
[ProgressView] Remove setMode:animated:completion API.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 317304615
  • Loading branch information
Wenyu Zhang authored and material-automation committed Jun 19, 2020
1 parent 0ec073f commit 00a6cab
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 99 deletions.
6 changes: 1 addition & 5 deletions components/ProgressView/examples/ProgressViewExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ - (void)setupProgressViews {
_backwardProgressAnimateView.progress = (float)0.33;

_indeterminateProgressView = [[MDCProgressView alloc] init];
_indeterminateProgressView.mode = MDCProgressViewModeIndeterminate;
_indeterminateProgressView.translatesAutoresizingMaskIntoConstraints = NO;
_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 @@ -366,9 +366,6 @@ - (void)animateIndeterminateProgressBarWithCountdown:(NSInteger)remainingCounts
__weak ProgressViewExample *weakSelf = self;

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

Expand All @@ -381,7 +378,6 @@ - (void)animateIndeterminateProgressBarWithCountdown:(NSInteger)remainingCounts
});
} else {
[_indeterminateProgressView stopAnimating];
[_indeterminateProgressView setMode:MDCProgressViewModeDeterminate animated:YES completion:nil];
}
}

Expand Down
10 changes: 0 additions & 10 deletions components/ProgressView/src/MDCProgressView.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,6 @@ IB_DESIGNABLE
animated:(BOOL)animated
completion:(void (^__nullable)(BOOL finished))completion;

/**
Changes the Determinate state, optionally animating the change.
@param mode The mode to change the progress view to.
@param animated Whether the change should be animated.
@param completion The completion block executed at the end of the animation.
*/
- (void)setMode:(MDCProgressViewMode)mode
animated:(BOOL)animated
completion:(void (^__nullable)(BOOL finished))completion;

/**
Start the progress bar's indeterminate animation.
*/
Expand Down
84 changes: 0 additions & 84 deletions components/ProgressView/src/MDCProgressView.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@
@interface MDCProgressView ()
@property(nonatomic, strong) MDCProgressGradientView *progressView;
@property(nonatomic, strong) UIView *trackView;
@property(nonatomic, strong) UIView *transitionView;
@property(nonatomic) BOOL animatingHide;
// A UIProgressView to return the same format for the accessibility value. For example, when
// progress is 0.497, it reports "fifty per cent".
@property(nonatomic, readonly) UIProgressView *accessibilityProgressView;
@property(nonatomic) CFTimeInterval indeterminateAnimationStartTime;

@end

Expand Down Expand Up @@ -84,11 +82,6 @@ - (void)commonMDCProgressViewInit {
_trackView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self addSubview:_trackView];

_transitionView =
[[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGRectGetHeight(self.bounds))];
_transitionView.backgroundColor = MDCProgressViewDefaultTintColor();
[self addSubview:_transitionView];

CGFloat barWidth = [self indeterminateLoadingBarWidth];
CGRect progressBarFrame = CGRectMake(-barWidth, 0, barWidth, CGRectGetHeight(self.bounds));

Expand Down Expand Up @@ -157,7 +150,6 @@ - (UIColor *)trackTintColor {

- (void)setTrackTintColor:(UIColor *)trackTintColor {
self.trackView.backgroundColor = trackTintColor;
self.transitionView.backgroundColor = _progressTintColor;
}

- (void)setMode:(MDCProgressViewMode)mode {
Expand All @@ -173,80 +165,6 @@ - (void)setMode:(MDCProgressViewMode)mode {
}
}

- (void)setMode:(MDCProgressViewMode)mode
animated:(BOOL)animated
completion:(void (^__nullable)(BOOL finished))completion {
if (_mode == mode) {
if (completion) {
completion(YES);
}
return;
}
_mode = mode;

if (!animated) {
if (_mode == MDCProgressViewModeIndeterminate) {
self.progressView.frame = CGRectMake(0, 0, 0, CGRectGetHeight(self.bounds));
}
// Update the transition without an animation.
[self updateProgressView];
if (completion) {
completion(YES);
}
}

// Change from indeterminate to determinate.
if (_mode == MDCProgressViewModeDeterminate) {
// If the indeterminate view wasn't animating, just animate the determinate bar in.
if (!_animating) {
[self setProgress:_progress animated:animated completion:completion];
if (completion) {
completion(YES);
}
return;
}

// Transition from the indeterminate to the determinate bar.
CFTimeInterval stopTime = [self.progressView.layer convertTime:CACurrentMediaTime()
fromLayer:nil];
CFTimeInterval timeDiff = stopTime - _indeterminateAnimationStartTime;

CGFloat percentage = timeDiff / kAnimationDuration - floor(timeDiff / kAnimationDuration);
CGFloat xPosition =
(CGRectGetWidth(self.bounds) + [self indeterminateLoadingBarWidth]) * percentage -
[self indeterminateLoadingBarWidth];

[self.progressView.layer removeAllAnimations];
CGRect progressBarStartFrame =
CGRectMake(xPosition, 0, [self indeterminateLoadingBarWidth], CGRectGetHeight(self.bounds));
self.progressView.frame = progressBarStartFrame;

[UIView animateWithDuration:[[self class] animationDuration]
delay:0
options:[[self class] animationOptions]
animations:^{
[self updateProgressView];
}
completion:completion];
} else {
// Change from determinate to indeterminate.
CGRect zeroFrame = CGRectMake(0, 0, 0, CGRectGetHeight(self.bounds));
// Animate the transition from progress to indeterminate.
CGRect transitionViewFrame =
CGRectMake(0, 0, CGRectGetWidth(self.bounds) * _progress, CGRectGetHeight(self.bounds));
self.transitionView.frame = transitionViewFrame;
[self layoutIfNeeded];

[UIView animateWithDuration:[[self class] animationDuration]
delay:0
options:[[self class] animationOptions]
animations:^{
self.transitionView.frame = zeroFrame;
}
completion:completion];
}
}

- (void)setCornerRadius:(CGFloat)cornerRadius {
_cornerRadius = cornerRadius;

Expand Down Expand Up @@ -502,8 +420,6 @@ - (void)startAnimatingBar {
animation.duration = kAnimationDuration;
animation.repeatCount = HUGE_VALF;
[self.progressView.layer addAnimation:animation forKey:@"position"];
_indeterminateAnimationStartTime = [self.progressView.layer convertTime:CACurrentMediaTime()
fromLayer:nil];
}

- (CGFloat)indeterminateLoadingBarWidth {
Expand Down

0 comments on commit 00a6cab

Please sign in to comment.