Skip to content

Commit

Permalink
[GM3/UIKit/ProgressIndicator] Fix the issue where the progress is not…
Browse files Browse the repository at this point in the history
… updated when `progress` is set after init and the determinant stop mark has been enabled.

PiperOrigin-RevId: 663334572
  • Loading branch information
loading-google authored and material-automation committed Aug 15, 2024
1 parent eb0edee commit eb2c2f8
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions components/ProgressView/src/MDCProgressView.m
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,12 @@ - (void)setEnableDeterminateStopMark:(BOOL)enableDeterminateStopMark {
}

- (void)setProgress:(float)progress {
if (progress > 1)
if (progress > 1) {
progress = 1;
if (progress < 0)
}
if (progress < 0) {
progress = 0;
}
if (!_enableDeterminateStopMark) {
_progress = progress;
}
Expand Down Expand Up @@ -788,15 +790,7 @@ - (CAShapeLayer *)makeDeterminateProgressBarLayer {
determinateProgressBarLayer.lineCap = kCALineCapButt;
determinateProgressBarLayer.frame = CGRectMake(0, 0, 0, self.bounds.size.height);
determinateProgressBarLayer.fillColor = _progressTintColor.CGColor;

CGRect pathRect = CGRectMake(0, 0, 0, self.bounds.size.height);

if (determinateProgressBarLayer.cornerRadius > 0) {
determinateProgressBarLayer.path =
[UIBezierPath bezierPathWithRoundedRect:pathRect cornerRadius:_cornerRadius].CGPath;
} else {
determinateProgressBarLayer.path = [UIBezierPath bezierPathWithRect:pathRect].CGPath;
}
determinateProgressBarLayer.path = [self makeToPathForBarWithProgress:_progress].CGPath;

return determinateProgressBarLayer;
}
Expand All @@ -808,6 +802,8 @@ - (UIBezierPath *)makeToPathForGapWithProgress:(CGFloat)progress {
CGFloat x = (progress == 0) ? rect.origin.x - MDCProgressViewGapWidth - 3 : rect.origin.x - 3;
CGFloat y = rect.origin.y - 1;

// TODO(b/358368816): Fix the bug where the gap does not take into account changes in height.

// Draws a square shape with concave sides that looks like this:
// ---
// ) (
Expand Down Expand Up @@ -841,14 +837,15 @@ - (UIBezierPath *)makeToPathForGapWithProgress:(CGFloat)progress {

- (UIBezierPath *)makeToPathForBarWithProgress:(CGFloat)progress {
CGFloat cornerRadiusOffset = (_cornerRadius > 0 ? _cornerRadius / 2 : 0);
CGRect rect = CGRectMake(0, 0, self.bounds.size.width * progress - cornerRadiusOffset,
self.bounds.size.height);
CGSize size = self.bounds.size;
UIBezierPath *path;

CGRect pathRect = CGRectMake(0, 0, size.width * progress - cornerRadiusOffset, size.height);

if (_cornerRadius > 0) {
path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:_cornerRadius];
path = [UIBezierPath bezierPathWithRoundedRect:pathRect cornerRadius:_cornerRadius];
} else {
path = [UIBezierPath bezierPathWithRect:rect];
path = [UIBezierPath bezierPathWithRect:pathRect];
}
return path;
}
Expand Down

0 comments on commit eb2c2f8

Please sign in to comment.