From 31051b573965b1498fa29b2906da8d1855c39cf0 Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Fri, 9 Sep 2016 11:04:16 +0300 Subject: [PATCH] [ios] Updated circular progress to support custom coloring. --- .../CircularProgress/MWMCircularProgress.h | 3 +++ .../CircularProgress/MWMCircularProgress.mm | 10 ++++++++ .../MWMCircularProgressView.h | 2 ++ .../MWMCircularProgressView.mm | 25 +++++++++++++------ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/iphone/Maps/Classes/CustomViews/CircularProgress/MWMCircularProgress.h b/iphone/Maps/Classes/CustomViews/CircularProgress/MWMCircularProgress.h index 8f867df2aa..89ea922e86 100644 --- a/iphone/Maps/Classes/CustomViews/CircularProgress/MWMCircularProgress.h +++ b/iphone/Maps/Classes/CustomViews/CircularProgress/MWMCircularProgress.h @@ -1,4 +1,5 @@ #import "MWMButton.h" +#import "UIImageView+Coloring.h" #include "std/vector.hpp" @@ -30,6 +31,8 @@ using MWMCircularProgressStateVec = vector; @property (nonatomic) MWMCircularProgressState state; @property (weak, nonatomic) id _Nullable delegate; +- (void)setSpinnerColoring:(MWMImageColoring)coloring; +- (void)setSpinnerBackgroundColor:(nonnull UIColor *)backgroundColor; - (void)setImage:(nonnull UIImage *)image forStates:(MWMCircularProgressStateVec const &)states; - (void)setColor:(nonnull UIColor *)color forStates:(MWMCircularProgressStateVec const &)states; - (void)setColoring:(MWMButtonColoring)coloring forStates:(MWMCircularProgressStateVec const &)states; diff --git a/iphone/Maps/Classes/CustomViews/CircularProgress/MWMCircularProgress.mm b/iphone/Maps/Classes/CustomViews/CircularProgress/MWMCircularProgress.mm index 7ac10c64bf..0304799b06 100644 --- a/iphone/Maps/Classes/CustomViews/CircularProgress/MWMCircularProgress.mm +++ b/iphone/Maps/Classes/CustomViews/CircularProgress/MWMCircularProgress.mm @@ -72,6 +72,16 @@ UINib * const progressViewNib = [UINib nibWithNibName:@"MWMCircularProgress" bun self.nextProgressToAnimate = nil; } +- (void)setSpinnerColoring:(MWMImageColoring)coloring +{ + [self.rootView setSpinnerColoring:coloring]; +} + +- (void)setSpinnerBackgroundColor:(nonnull UIColor *)backgroundColor +{ + [self.rootView setSpinnerBackgroundColor:backgroundColor]; +} + - (void)setImage:(nonnull UIImage *)image forStates:(MWMCircularProgressStateVec const &)states { for (auto const & state : states) diff --git a/iphone/Maps/Classes/CustomViews/CircularProgress/MWMCircularProgressView.h b/iphone/Maps/Classes/CustomViews/CircularProgress/MWMCircularProgressView.h index 3f9b2e3ff4..70c24e0680 100644 --- a/iphone/Maps/Classes/CustomViews/CircularProgress/MWMCircularProgressView.h +++ b/iphone/Maps/Classes/CustomViews/CircularProgress/MWMCircularProgressView.h @@ -10,6 +10,8 @@ - (nonnull instancetype)initWithFrame:(CGRect)frame __attribute__((unavailable("initWithFrame is not available"))); - (nonnull instancetype)init __attribute__((unavailable("init is not available"))); +- (void)setSpinnerColoring:(MWMImageColoring)coloring; +- (void)setSpinnerBackgroundColor:(nonnull UIColor *)backgroundColor; - (void)setImage:(nonnull UIImage *)image forState:(MWMCircularProgressState)state; - (void)setColor:(nonnull UIColor *)color forState:(MWMCircularProgressState)state; - (void)setColoring:(MWMButtonColoring)coloring forState:(MWMCircularProgressState)state; diff --git a/iphone/Maps/Classes/CustomViews/CircularProgress/MWMCircularProgressView.mm b/iphone/Maps/Classes/CustomViews/CircularProgress/MWMCircularProgressView.mm index 06b1e30bb4..d88d9f1abd 100644 --- a/iphone/Maps/Classes/CustomViews/CircularProgress/MWMCircularProgressView.mm +++ b/iphone/Maps/Classes/CustomViews/CircularProgress/MWMCircularProgressView.mm @@ -19,7 +19,7 @@ static inline CGFloat angleWithProgress(CGFloat progress) @property (nonatomic) CAShapeLayer * backgroundLayer; @property (nonatomic) CAShapeLayer * progressLayer; -@property (nonatomic, readonly) CGColorRef backgroundLayerColor; +@property (nonatomic) UIColor * spinnerBackgroundColor; @property (nonatomic, readonly) CGColorRef progressLayerColor; @property (nonatomic) NSMutableDictionary * images; @@ -59,9 +59,11 @@ static inline CGFloat angleWithProgress(CGFloat progress) - (void)setupColors { self.colors = [NSMutableDictionary dictionary]; - self.spinner.mwm_coloring = MWMImageColoringGray; - UIColor * progressColor = [UIColor linkBlue]; + UIColor * progressColor = [_spinnerBackgroundColor isEqual:[UIColor clearColor]] + ? [UIColor whiteColor] + : [UIColor linkBlue]; UIColor * clearColor = [UIColor clearColor]; + [self setSpinnerColoring:MWMImageColoringGray]; [self setColor:clearColor forState:MWMCircularProgressStateNormal]; [self setColor:clearColor forState:MWMCircularProgressStateSelected]; [self setColor:progressColor forState:MWMCircularProgressStateProgress]; @@ -97,6 +99,11 @@ static inline CGFloat angleWithProgress(CGFloat progress) [self.layer addSublayer:self.progressLayer]; } +- (void)setSpinnerColoring:(MWMImageColoring)coloring +{ + self.spinner.mwm_coloring = coloring; +} + - (void)setImage:(nonnull UIImage *)image forState:(MWMCircularProgressState)state { self.images[@(state)] = image; @@ -123,7 +130,7 @@ static inline CGFloat angleWithProgress(CGFloat progress) return; self.backgroundLayer.fillColor = self.progressLayer.fillColor = UIColor.clearColor.CGColor; self.backgroundLayer.lineWidth = self.progressLayer.lineWidth = kLineWidth; - self.backgroundLayer.strokeColor = self.backgroundLayerColor; + self.backgroundLayer.strokeColor = self.spinnerBackgroundColor.CGColor; self.progressLayer.strokeColor = self.progressLayerColor; CGRect rect = CGRectInset(self.bounds, kLineWidth, kLineWidth); self.backgroundLayer.path = [UIBezierPath bezierPathWithOvalInRect:rect].CGPath; @@ -160,7 +167,7 @@ static inline CGFloat angleWithProgress(CGFloat progress) } NSUInteger const animationImagesCount = 12; NSMutableArray * animationImages = [NSMutableArray arrayWithCapacity:animationImagesCount]; - NSString * postfix = ([UIColor isNightMode] && !self.isInvertColor) || (![UIColor isNightMode] && self.isInvertColor) ? @"dark" : @"light"; + NSString * postfix = ([UIColor isNightMode] && !self.isInvertColor) || (![UIColor isNightMode] && self.isInvertColor) || _spinnerBackgroundColor ? @"dark" : @"light"; for (NSUInteger i = 0; i < animationImagesCount; ++i) animationImages[i] = [UIImage imageNamed:[NSString stringWithFormat:@"Spinner_%@_%@", @(i+1), postfix]]; @@ -207,14 +214,16 @@ static inline CGFloat angleWithProgress(CGFloat progress) [self refreshProgress]; } -- (CGColorRef)backgroundLayerColor +- (UIColor *)spinnerBackgroundColor { + if (_spinnerBackgroundColor) + return _spinnerBackgroundColor; switch (self.state) { case MWMCircularProgressStateProgress: - return [UIColor pressBackground].CGColor; + return [UIColor pressBackground]; default: - return [UIColor clearColor].CGColor; + return [UIColor clearColor]; } }