From eb2c2f842eeb8bd33fc3ede3ea6f6474ff2f6123 Mon Sep 17 00:00:00 2001 From: Frank Wang Date: Thu, 15 Aug 2024 09:32:16 -0700 Subject: [PATCH] [GM3/UIKit/ProgressIndicator] Fix the issue where the progress is not updated when `progress` is set after init and the determinant stop mark has been enabled. PiperOrigin-RevId: 663334572 --- components/ProgressView/src/MDCProgressView.m | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/components/ProgressView/src/MDCProgressView.m b/components/ProgressView/src/MDCProgressView.m index 6bbefc602a0..befc7bbbbb9 100644 --- a/components/ProgressView/src/MDCProgressView.m +++ b/components/ProgressView/src/MDCProgressView.m @@ -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; } @@ -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; } @@ -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: // --- // ) ( @@ -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; }