Commit 95595ce3 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Update RadialProgressView to draw progress track.

Progress track used to be a part of download state icon. Now that state
icon is programatically drawn the track should be a part of
RadialProgressView.

Bug: 820178
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I4b20faa6fbbc622de2763b962cc40539b22d24fc
Reviewed-on: https://chromium-review.googlesource.com/966936
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543910}
parent e8c6f424
......@@ -478,7 +478,8 @@ NSString* GetSizeString(long long size_in_bytes) {
_progressView = [[RadialProgressView alloc] initWithFrame:CGRectZero];
_progressView.translatesAutoresizingMaskIntoConstraints = NO;
_progressView.lineWidth = 2;
_progressView.tintColor = [MDCPalette bluePalette].tint600;
_progressView.progressTintColor = [MDCPalette bluePalette].tint600;
_progressView.trackTintColor = [MDCPalette greyPalette].tint300;
[self updateProgressView];
}
return _progressView;
......
......@@ -17,6 +17,11 @@
// The line width used when stroking the progress arc.
@property(nonatomic) CGFloat lineWidth;
@property(nonatomic, nullable) UIColor* progressTintColor;
// Track is drawn underneath the progress.
@property(nonatomic, nullable) UIColor* trackTintColor;
@end
#endif // IOS_CHROME_BROWSER_UI_DOWNLOAD_RADIAL_PROGRESS_VIEW_H_
......@@ -13,14 +13,22 @@
#endif
@interface RadialProgressView ()
// CALayer that backs this view up.
@property(nonatomic, readonly) CAShapeLayer* shapeLayer;
// CALayer that backs this view up. Serves as progress track.
@property(nonatomic, readonly) CAShapeLayer* trackLayer;
// CALayer added as a sublayer for self.layer. Serves as progress.
@property(nonatomic, readonly) CAShapeLayer* progressLayer;
@end
@implementation RadialProgressView
@synthesize progress = _progress;
@synthesize lineWidth = _lineWidth;
@synthesize progressTintColor = _progressTintColor;
@synthesize trackTintColor = _trackTintColor;
@synthesize progressLayer = _progressLayer;
#pragma mark - UIView overrides
......@@ -28,37 +36,62 @@
return [CAShapeLayer class];
}
- (void)setBounds:(CGRect)bounds {
[super setBounds:bounds];
// progressPathWithEndAngle: relies on self.bounds and must be updated here.
// Track starts at 12 o'clock and ends at 12 o'clock.
self.trackLayer.path =
[self progressPathWithEndAngle:M_PI * 2 - M_PI_2].CGPath;
}
- (void)willMoveToSuperview:(UIView*)newSuperview {
if (newSuperview) {
self.shapeLayer.fillColor = [UIColor clearColor].CGColor;
self.shapeLayer.strokeColor = self.tintColor.CGColor;
self.shapeLayer.lineWidth = self.lineWidth;
if (newSuperview && !self.progressLayer.superlayer) {
self.trackLayer.fillColor = [UIColor clearColor].CGColor;
self.trackLayer.strokeColor = self.trackTintColor.CGColor;
self.trackLayer.lineWidth = self.lineWidth;
[self.trackLayer addSublayer:self.progressLayer];
}
}
#pragma mark - Public
- (void)setProgress:(float)progress {
if (_progress == progress)
return;
if (_progress != progress) {
_progress = progress;
self.progressLayer.path =
[self progressPathWithEndAngle:M_PI * 2 * progress - M_PI_2].CGPath;
}
}
#pragma mark - Private
_progress = progress;
// Returns Bezier path for drawing radial progress or track. Start angle is
// always 12 o'clock.
- (UIBezierPath*)progressPathWithEndAngle:(CGFloat)endAngleInRadians {
CGPoint center =
CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
CGFloat radius = CGRectGetWidth(self.bounds) / 2 - 1;
UIBezierPath* path =
[UIBezierPath bezierPathWithArcCenter:center
radius:radius
startAngle:0 - M_PI_2 // 12 o'clock
endAngle:M_PI * 2 * progress - M_PI_2
clockwise:YES];
self.shapeLayer.path = path.CGPath;
CGFloat radius = CGRectGetWidth(self.bounds) / 2 - self.lineWidth;
return [UIBezierPath bezierPathWithArcCenter:center
radius:radius
startAngle:-M_PI_2
endAngle:endAngleInRadians
clockwise:YES];
}
#pragma mark - Private
- (CAShapeLayer*)shapeLayer {
- (CAShapeLayer*)trackLayer {
return base::mac::ObjCCastStrict<CAShapeLayer>(self.layer);
}
- (CAShapeLayer*)progressLayer {
if (!_progressLayer) {
_progressLayer = [CAShapeLayer layer];
_progressLayer.fillColor = [UIColor clearColor].CGColor;
_progressLayer.strokeColor = self.progressTintColor.CGColor;
_progressLayer.lineWidth = self.lineWidth;
}
return _progressLayer;
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment