From 7675bdcf258396b8ba430c811ca47c37c47e86b7 Mon Sep 17 00:00:00 2001 From: Alexandre Iartsev Date: Tue, 21 Aug 2018 17:21:59 -0300 Subject: [PATCH 01/17] Cleanup --- .../MLCheckBox/classes/MLCheckBox.m | 347 ++++++++---------- 1 file changed, 153 insertions(+), 194 deletions(-) diff --git a/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m b/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m index 6469651..136206a 100644 --- a/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m +++ b/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m @@ -33,245 +33,204 @@ @implementation MLCheckBox - (void)commonInit { - [super commonInit]; - - // create external Layer - [self.checkBoxExternalLayer removeFromSuperlayer]; - self.checkBoxExternalLayer = [CAShapeLayer layer]; - [self.layer addSublayer:self.checkBoxExternalLayer]; - - // create external Layer - [self.checkBoxInternalLayer removeFromSuperlayer]; - self.checkBoxInternalLayer = [CAShapeLayer layer]; - [self.layer addSublayer:self.checkBoxInternalLayer]; - - // create tick layer - self.checkBoxTickLayer = [CAShapeLayer layer]; - [self.layer addSublayer:self.checkBoxTickLayer]; + [super commonInit]; + + // create external Layer + [self.checkBoxExternalLayer removeFromSuperlayer]; + self.checkBoxExternalLayer = [CAShapeLayer layer]; + [self.layer addSublayer:self.checkBoxExternalLayer]; + + // create external Layer + [self.checkBoxInternalLayer removeFromSuperlayer]; + self.checkBoxInternalLayer = [CAShapeLayer layer]; + [self.layer addSublayer:self.checkBoxInternalLayer]; + + // create tick layer + self.checkBoxTickLayer = [CAShapeLayer layer]; + [self.layer addSublayer:self.checkBoxTickLayer]; } #pragma mark - Navigation - (void)layoutSubviews { - [super layoutSubviews]; - - self.checkBoxTickLayer.frame = self.bounds; - self.checkBoxExternalLayer.frame = self.bounds; - self.checkBoxInternalLayer.frame = self.bounds; + [super layoutSubviews]; + + self.checkBoxTickLayer.frame = self.bounds; + self.checkBoxExternalLayer.frame = self.bounds; + self.checkBoxInternalLayer.frame = self.bounds; } #pragma mark - Animation + - (void)setOnBooleanWidgetAnimated:(BOOL)animated { - if (self.isBooleanWidgetOn) { - return; - } + if (self.isBooleanWidgetOn) { + return; + } + + [self fillCheckBoxExternalAnimated:animated]; + [self fillCheckBoxInternalFromColor:[UIColor ml_meli_grey] ToColor:[UIColor ml_meli_blue] FromOpacity:0 ToOpacity:1 Animated:animated]; + [self fillCheckBoxTickAnimated:animated]; +} - [self fillCheckBoxExternalAnimated:animated]; - [self fillCheckBoxInternalAnimated:animated]; - [self fillCheckBoxTickAnimated:animated]; +- (void)fillCheckBoxExternalFromColor:(UIColor *)fromColor ToColor:(UIColor *)toColor Animated:(BOOL)animated +{ + // Set circle layer bounds + self.checkBoxExternalLayer.bounds = CGRectMake(0, 0, CGRectGetHeight(self.frame), CGRectGetWidth(self.frame)); + + // Set circle layer path + UIBezierPath *externalFrame = [UIBezierPath bezierPathWithRoundedRect:self.checkBoxExternalLayer.bounds cornerRadius:kMLCheckBoxExternalCornerRadius]; + self.checkBoxExternalLayer.path = externalFrame.CGPath; + + self.checkBoxExternalLayer.fillColor = [UIColor clearColor].CGColor; + self.checkBoxExternalLayer.lineWidth = kMLCheckBoxExternalLineWidth; + + // Color animation + CABasicAnimation *colorFillAnimation = [self createColorFillAnimationFromColor:fromColor ToColor:toColor WithDuration:animated ? kMLCheckBoxAnimationDuration : kMLCheckBoxNotAnimationDuration ]; + + [self.checkBoxExternalLayer addAnimation:colorFillAnimation forKey:@"animateFill"]; + + self.checkBoxExternalLayer.strokeColor = toColor.CGColor; } - (void)fillCheckBoxExternalAnimated:(BOOL)animated { - // Set circle layer bounds - self.checkBoxExternalLayer.bounds = CGRectMake(0, 0, CGRectGetHeight(self.frame), CGRectGetWidth(self.frame)); - - // Set circle layer path - UIBezierPath *externalFrame = [UIBezierPath bezierPathWithRoundedRect:self.checkBoxExternalLayer.bounds cornerRadius:kMLCheckBoxExternalCornerRadius]; - self.checkBoxExternalLayer.path = externalFrame.CGPath; - - self.checkBoxExternalLayer.fillColor = [UIColor clearColor].CGColor; - float lineWidth = kMLCheckBoxExternalLineWidth; - - self.checkBoxExternalLayer.lineWidth = lineWidth; - - // Color animation - CABasicAnimation *colorFillAnimation = [CABasicAnimation animationWithKeyPath:@"strokeColor"]; - colorFillAnimation.beginTime = 0; - colorFillAnimation.fromValue = (id)[UIColor ml_meli_grey].CGColor; - colorFillAnimation.toValue = (id)[UIColor ml_meli_blue].CGColor; - colorFillAnimation.fillMode = kCAFillModeForwards; - colorFillAnimation.duration = animated ? kMLCheckBoxAnimationDuration : kMLCheckBoxNotAnimationDuration; - - [self.checkBoxExternalLayer addAnimation:colorFillAnimation forKey:@"animateFill"]; - - self.checkBoxExternalLayer.strokeColor = [UIColor ml_meli_blue].CGColor; + [self fillCheckBoxExternalFromColor:[UIColor ml_meli_grey] ToColor:[UIColor ml_meli_blue] Animated:animated]; } -- (void)fillCheckBoxInternalAnimated:(BOOL)animated +- (void)fillCheckBoxInternalFromColor:(UIColor *)fromColor ToColor:(UIColor *)toColor FromOpacity:(float)fromOpacity ToOpacity:(float)toOpacity Animated:(BOOL)animated { - // Set circle layer bounds - self.checkBoxInternalLayer.bounds = CGRectMake(0, 0, CGRectGetHeight(self.frame), CGRectGetWidth(self.frame)); - - // Set circle layer path - UIBezierPath *externalFrame = [UIBezierPath bezierPathWithRoundedRect:self.checkBoxExternalLayer.bounds cornerRadius:kMLCheckBoxExternalCornerRadius]; - self.checkBoxInternalLayer.path = externalFrame.CGPath; - - UIBezierPath *internalFrame = [UIBezierPath bezierPathWithRoundedRect:self.checkBoxExternalLayer.bounds cornerRadius:kMLCheckBoxExternalCornerRadius]; - - self.checkBoxInternalLayer.fillColor = [UIColor ml_meli_blue].CGColor; - float lineWidth = kMLCheckBoxExternalLineWidth; - - self.checkBoxInternalLayer.lineWidth = lineWidth; - - // Opacity animation - CABasicAnimation *opacityFillAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; - opacityFillAnimation.beginTime = 0; - opacityFillAnimation.fromValue = @0; - opacityFillAnimation.toValue = @1; - opacityFillAnimation.fillMode = kCAFillModeForwards; - - // Color animation - CABasicAnimation *colorFillAnimation = [CABasicAnimation animationWithKeyPath:@"strokeColor"]; - colorFillAnimation.beginTime = 0; - colorFillAnimation.fromValue = (id)[UIColor ml_meli_grey].CGColor; - colorFillAnimation.toValue = (id)[UIColor ml_meli_blue].CGColor; - colorFillAnimation.fillMode = kCAFillModeForwards; - - // Compaund animation - CAAnimationGroup *fillAnimation = [CAAnimationGroup animation]; - fillAnimation.duration = animated ? kMLCheckBoxAnimationDuration : kMLCheckBoxNotAnimationDuration; - [fillAnimation setAnimations:[NSArray arrayWithObjects:colorFillAnimation, opacityFillAnimation, nil]]; - - [self.checkBoxInternalLayer addAnimation:fillAnimation forKey:@"animateFill"]; - - self.checkBoxInternalLayer.strokeColor = [UIColor ml_meli_blue].CGColor; - self.checkBoxInternalLayer.path = internalFrame.CGPath; - self.checkBoxInternalLayer.opacity = 1; + // Set circle layer bounds + self.checkBoxInternalLayer.bounds = CGRectMake(0, 0, CGRectGetHeight(self.frame), CGRectGetWidth(self.frame)); + + // Set circle layer path + UIBezierPath *internalFrame = [UIBezierPath bezierPathWithRoundedRect:self.checkBoxExternalLayer.bounds cornerRadius:kMLCheckBoxExternalCornerRadius]; + self.checkBoxInternalLayer.path = internalFrame.CGPath; + + + self.checkBoxInternalLayer.fillColor = toOpacity == 0 ? [UIColor clearColor].CGColor : toColor.CGColor; + float lineWidth = kMLCheckBoxExternalLineWidth; + + self.checkBoxInternalLayer.lineWidth = lineWidth; + + // Opacity animation + CABasicAnimation *opacityFillAnimation = [self createOpacityFillAnimationFromValue:fromOpacity ToValue:toOpacity]; + + // Color animation + CABasicAnimation *colorFillAnimation = [self createColorFillAnimationFromColor:fromColor ToColor:toColor]; + + // Compaund animation + CAAnimationGroup *fillAnimation = [CAAnimationGroup animation]; + fillAnimation.duration = animated ? kMLCheckBoxAnimationDuration : kMLCheckBoxNotAnimationDuration; + [fillAnimation setAnimations:[NSArray arrayWithObjects:colorFillAnimation, opacityFillAnimation, nil]]; + + [self.checkBoxInternalLayer addAnimation:fillAnimation forKey:@"animateFill"]; + + self.checkBoxInternalLayer.strokeColor = toColor.CGColor; } - (void)fillCheckBoxTickAnimated:(BOOL)animated { - // Set circle layer bounds - self.checkBoxTickLayer.bounds = CGRectMake(0, 0, CGRectGetHeight(self.frame), CGRectGetWidth(self.frame)); - - // Set circle layer path - UIBezierPath *tickPath = [UIBezierPath bezierPath]; - - [tickPath moveToPoint:[self tickLeftPointInRect:self.bounds]]; - [tickPath addLineToPoint:[self tickBotomPointInRect:self.bounds]]; - [tickPath addLineToPoint:[self tickRightPointInRect:self.bounds]]; - - self.checkBoxTickLayer.path = tickPath.CGPath; - - self.checkBoxTickLayer.strokeColor = [UIColor ml_meli_white].CGColor; - self.checkBoxTickLayer.fillColor = [UIColor clearColor].CGColor; - float lineWidth = kMLCheckBoxTickLineWidth; - - self.checkBoxTickLayer.lineWidth = lineWidth; - - // Color animation - CABasicAnimation *pathTickAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; - pathTickAnimation.beginTime = 0; - pathTickAnimation.fromValue = @0.0; - pathTickAnimation.toValue = @1.0; - pathTickAnimation.fillMode = kCAFillModeForwards; - pathTickAnimation.duration = animated ? kMLCheckBoxAnimationDuration : kMLCheckBoxNotAnimationDuration; - - [self.checkBoxTickLayer addAnimation:pathTickAnimation forKey:@"animateFillTick"]; + // Set circle layer bounds + self.checkBoxTickLayer.bounds = CGRectMake(0, 0, CGRectGetHeight(self.frame), CGRectGetWidth(self.frame)); + + // Set circle layer path + UIBezierPath *tickPath = [UIBezierPath bezierPath]; + + [tickPath moveToPoint:[self tickLeftPointInRect:self.bounds]]; + [tickPath addLineToPoint:[self tickBotomPointInRect:self.bounds]]; + [tickPath addLineToPoint:[self tickRightPointInRect:self.bounds]]; + + self.checkBoxTickLayer.path = tickPath.CGPath; + + self.checkBoxTickLayer.strokeColor = [UIColor ml_meli_white].CGColor; + self.checkBoxTickLayer.fillColor = [UIColor clearColor].CGColor; + float lineWidth = kMLCheckBoxTickLineWidth; + + self.checkBoxTickLayer.lineWidth = lineWidth; + + // Color animation + CABasicAnimation *pathTickAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; + pathTickAnimation.fromValue = @0.0; + pathTickAnimation.toValue = @1.0; + pathTickAnimation.fillMode = kCAFillModeForwards; + pathTickAnimation.duration = animated ? kMLCheckBoxAnimationDuration : kMLCheckBoxNotAnimationDuration; + + [self.checkBoxTickLayer addAnimation:pathTickAnimation forKey:@"animateFillTick"]; } - (void)setOffBooleanWidgetAnimated:(BOOL)animated { - [self clearCheckBoxExternalAnimated:animated]; - [self clearCheckBoxInternalAnimated:animated]; + [self fillCheckBoxExternalFromColor:[UIColor ml_meli_blue] ToColor:[UIColor ml_meli_grey] Animated:animated]; + [self fillCheckBoxInternalFromColor:[UIColor ml_meli_blue] ToColor:[UIColor ml_meli_grey] FromOpacity:1 ToOpacity:0 Animated:animated]; } -- (void)clearCheckBoxExternalAnimated:(BOOL)animated +#pragma mark - Tick Positions +- (CGPoint)tickLeftPointInRect:(CGRect)rect { - // Set circle layer bounds - self.checkBoxExternalLayer.bounds = CGRectMake(0, 0, CGRectGetHeight(self.frame), CGRectGetWidth(self.frame)); - - // Set circle layer path - UIBezierPath *externalFrame = [UIBezierPath bezierPathWithRoundedRect:self.checkBoxExternalLayer.bounds cornerRadius:kMLCheckBoxExternalCornerRadius]; - - self.checkBoxExternalLayer.path = externalFrame.CGPath; - - self.checkBoxExternalLayer.fillColor = [UIColor clearColor].CGColor; - float lineWidth = kMLCheckBoxExternalLineWidth; - - self.checkBoxExternalLayer.lineWidth = lineWidth; - - // Color animation - CABasicAnimation *colorFillAnimation = [CABasicAnimation animationWithKeyPath:@"strokeColor"]; - colorFillAnimation.beginTime = 0; - colorFillAnimation.fromValue = (id)[UIColor ml_meli_blue].CGColor; - colorFillAnimation.toValue = (id)[UIColor ml_meli_grey].CGColor; - colorFillAnimation.fillMode = kCAFillModeForwards; - colorFillAnimation.duration = animated ? kMLCheckBoxAnimationDuration : kMLCheckBoxNotAnimationDuration; - - [self.checkBoxExternalLayer addAnimation:colorFillAnimation forKey:@"animateFill"]; - - self.checkBoxExternalLayer.strokeColor = [UIColor ml_meli_grey].CGColor; + CGFloat x = rect.size.width * (2.5 / 15.0); + CGFloat y = rect.size.height / 2.0; + + return CGPointMake(x, y); } -- (void)clearCheckBoxInternalAnimated:(BOOL)animated +- (CGPoint)tickBotomPointInRect:(CGRect)rect { - // Set circle layer bounds - self.checkBoxInternalLayer.bounds = CGRectMake(0, 0, CGRectGetHeight(self.frame), CGRectGetWidth(self.frame)); - - // Set circle layer path - UIBezierPath *externalFrame = [UIBezierPath bezierPathWithRoundedRect:self.checkBoxExternalLayer.bounds cornerRadius:kMLCheckBoxExternalCornerRadius]; - - UIBezierPath *internalFrame = [UIBezierPath bezierPathWithRoundedRect:self.checkBoxExternalLayer.bounds cornerRadius:kMLCheckBoxExternalCornerRadius]; - [internalFrame fill]; - - self.checkBoxInternalLayer.path = internalFrame.CGPath; - - self.checkBoxInternalLayer.fillColor = [UIColor clearColor].CGColor; - float lineWidth = kMLCheckBoxExternalLineWidth; - self.checkBoxInternalLayer.lineWidth = lineWidth; - - // Opacity animation - CABasicAnimation *opacityClearAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; - opacityClearAnimation.beginTime = 0; - opacityClearAnimation.fromValue = @1; - opacityClearAnimation.toValue = @0; - opacityClearAnimation.fillMode = kCAFillModeForwards; - - // Color animation - CABasicAnimation *colorClearAnimation = [CABasicAnimation animationWithKeyPath:@"strokeColor"]; - colorClearAnimation.beginTime = 0; - colorClearAnimation.fromValue = (id)[UIColor ml_meli_blue].CGColor; - colorClearAnimation.toValue = (id)[UIColor ml_meli_grey].CGColor; - colorClearAnimation.fillMode = kCAFillModeForwards; - - // Compaund animation - CAAnimationGroup *clearAnimation = [CAAnimationGroup animation]; - clearAnimation.duration = animated ? kMLCheckBoxAnimationDuration : kMLCheckBoxNotAnimationDuration; - [clearAnimation setAnimations:[NSArray arrayWithObjects:colorClearAnimation, opacityClearAnimation, nil]]; - - [self.checkBoxInternalLayer addAnimation:clearAnimation forKey:@"animateClear"]; + CGFloat x = rect.size.width * (1.0 / 3.0); + CGFloat y = rect.size.height * (2.0 / 3.0); + + return CGPointMake(x, y); +} - self.checkBoxInternalLayer.strokeColor = [UIColor ml_meli_grey].CGColor; - self.checkBoxInternalLayer.path = externalFrame.CGPath; - self.checkBoxInternalLayer.opacity = 0; +- (CGPoint)tickRightPointInRect:(CGRect)rect +{ + CGFloat x = rect.size.width - (rect.size.width * (2.5 / 15.0)); + CGFloat y = rect.size.height / 4.0; + + return CGPointMake(x, y); } -#pragma mark - Tick Positions -- (CGPoint)tickLeftPointInRect:(CGRect)rect +- (CABasicAnimation *)createOpacityFillAnimationFromValue:(float)fromValue ToValue:(float)toValue { - CGFloat x = rect.size.width * (2.5 / 15.0); - CGFloat y = rect.size.height / 2.0; + return [self createOpacityFillAnimationFromValue:fromValue ToValue:toValue WithDuration:0 WithFillMode:kCAFillModeForwards]; +} - return CGPointMake(x, y); +- (CABasicAnimation *)createOpacityFillAnimationFromValue:(float)fromValue ToValue:(float)toValue WithDuration:(double)duration +{ + return [self createOpacityFillAnimationFromValue:fromValue ToValue:toValue WithDuration:duration WithFillMode:kCAFillModeForwards]; } -- (CGPoint)tickBotomPointInRect:(CGRect)rect +- (CABasicAnimation *)createOpacityFillAnimationFromValue:(float)fromValue ToValue:(float)toValue WithDuration:(double)duration WithFillMode:(NSString *)fillMode { - CGFloat x = rect.size.width * (1.0 / 3.0); - CGFloat y = rect.size.height * (2.0 / 3.0); + CABasicAnimation *opacityFillAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; + opacityFillAnimation.fromValue = [NSNumber numberWithFloat:fromValue]; + opacityFillAnimation.toValue = [NSNumber numberWithFloat:toValue]; + opacityFillAnimation.duration = duration; + opacityFillAnimation.fillMode = fillMode; + + return opacityFillAnimation; +} - return CGPointMake(x, y); +- (CABasicAnimation *)createColorFillAnimationFromColor:(UIColor *)fromColor ToColor:(UIColor *)toColor WithDuration: (double)duration +{ + return [self createColorFillAnimationFromColor:fromColor ToColor:toColor WithDuration:duration WithFillMode:kCAFillModeForwards]; } -- (CGPoint)tickRightPointInRect:(CGRect)rect +- (CABasicAnimation *)createColorFillAnimationFromColor:(UIColor *)fromColor ToColor:(UIColor *)toColor { - CGFloat x = rect.size.width - (rect.size.width * (2.5 / 15.0)); - CGFloat y = rect.size.height / 4.0; + return [self createColorFillAnimationFromColor:fromColor ToColor:toColor WithDuration:0 WithFillMode:kCAFillModeForwards]; +} - return CGPointMake(x, y); +- (CABasicAnimation *)createColorFillAnimationFromColor:(UIColor *)fromColor ToColor:(UIColor *)toColor WithDuration:(double)duration WithFillMode:(NSString *)fillMode +{ + CABasicAnimation *colorFillAnimation = [CABasicAnimation animationWithKeyPath:@"strokeColor"]; + colorFillAnimation.fromValue = (id)fromColor.CGColor; + colorFillAnimation.toValue = (id)toColor.CGColor; + colorFillAnimation.duration = duration; + colorFillAnimation.fillMode = fillMode; + + return colorFillAnimation; } @end + From f7aad5ce2b0684c9c92803ab7be863031c90805c Mon Sep 17 00:00:00 2001 From: Alexandre Iartsev Date: Tue, 21 Aug 2018 17:23:48 -0300 Subject: [PATCH 02/17] setEnabled public method added --- .../MLBooleanWidget/MLCheckBox/classes/MLCheckBox.h | 2 ++ .../MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.h b/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.h index 58769c0..d9dde38 100644 --- a/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.h +++ b/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.h @@ -10,4 +10,6 @@ @interface MLCheckBox : MLBooleanWidget +- (void)setEnabled:(BOOL)enabled Animated:(BOOL)animated; + @end diff --git a/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m b/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m index 136206a..f1c6c96 100644 --- a/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m +++ b/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m @@ -60,6 +60,11 @@ - (void)layoutSubviews self.checkBoxInternalLayer.frame = self.bounds; } +#pragma mark - Public Methods +- (void)setEnabled:(BOOL)enabled Animated:(BOOL)animated +{ +} + #pragma mark - Animation - (void)setOnBooleanWidgetAnimated:(BOOL)animated From 2534d0e98e4065abfa021d1919aeecc4c63b5893 Mon Sep 17 00:00:00 2001 From: Alexandre Iartsev Date: Tue, 21 Aug 2018 17:24:36 -0300 Subject: [PATCH 03/17] setEnabled implementation --- .../MLCheckBox/classes/MLCheckBox.m | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m b/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m index f1c6c96..1c9c239 100644 --- a/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m +++ b/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m @@ -63,6 +63,30 @@ - (void)layoutSubviews #pragma mark - Public Methods - (void)setEnabled:(BOOL)enabled Animated:(BOOL)animated { + if (self.userInteractionEnabled == enabled) { + return; + } + + self.userInteractionEnabled = enabled; + if (enabled) { + if (self.isBooleanWidgetOn) { + [self fillCheckBoxExternalFromColor:[UIColor ml_meli_mid_grey] ToColor:[UIColor ml_meli_blue] Animated:animated]; + [self fillCheckBoxInternalFromColor:[UIColor ml_meli_mid_grey] ToColor:[UIColor ml_meli_blue] FromOpacity:1 ToOpacity:1 Animated:animated]; + [self fillCheckBoxTickAnimated:animated]; + } else { + [self fillCheckBoxExternalFromColor:[UIColor ml_meli_mid_grey] ToColor:[UIColor ml_meli_grey] Animated:animated]; + [self fillCheckBoxInternalFromColor:[UIColor ml_meli_mid_grey] ToColor:[UIColor ml_meli_grey] FromOpacity:0 ToOpacity:0 Animated:animated]; + } + } else { + if (self.isBooleanWidgetOn) { + [self fillCheckBoxExternalFromColor:[UIColor ml_meli_blue] ToColor:[UIColor ml_meli_mid_grey] Animated:animated]; + [self fillCheckBoxInternalFromColor:[UIColor ml_meli_blue] ToColor:[UIColor ml_meli_mid_grey] FromOpacity:1 ToOpacity:1 Animated:animated]; + [self fillCheckBoxTickAnimated:animated]; + } else { + [self fillCheckBoxExternalFromColor:[UIColor ml_meli_grey] ToColor:[UIColor ml_meli_mid_grey] Animated:animated]; + [self fillCheckBoxInternalFromColor:[UIColor ml_meli_grey] ToColor:[UIColor ml_meli_mid_grey] FromOpacity:0 ToOpacity:0 Animated:animated]; + } + } } #pragma mark - Animation From 4382f1608ae418297ed2c7d00bb4cddbb10ff960 Mon Sep 17 00:00:00 2001 From: Alexandre Iartsev Date: Tue, 21 Aug 2018 17:25:34 -0300 Subject: [PATCH 04/17] Uncrustify magic --- .../MLCheckBox/classes/MLCheckBox.m | 308 +++++++++--------- 1 file changed, 153 insertions(+), 155 deletions(-) diff --git a/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m b/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m index 1c9c239..54604e1 100644 --- a/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m +++ b/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m @@ -33,233 +33,231 @@ @implementation MLCheckBox - (void)commonInit { - [super commonInit]; - - // create external Layer - [self.checkBoxExternalLayer removeFromSuperlayer]; - self.checkBoxExternalLayer = [CAShapeLayer layer]; - [self.layer addSublayer:self.checkBoxExternalLayer]; - - // create external Layer - [self.checkBoxInternalLayer removeFromSuperlayer]; - self.checkBoxInternalLayer = [CAShapeLayer layer]; - [self.layer addSublayer:self.checkBoxInternalLayer]; - - // create tick layer - self.checkBoxTickLayer = [CAShapeLayer layer]; - [self.layer addSublayer:self.checkBoxTickLayer]; + [super commonInit]; + + // create external Layer + [self.checkBoxExternalLayer removeFromSuperlayer]; + self.checkBoxExternalLayer = [CAShapeLayer layer]; + [self.layer addSublayer:self.checkBoxExternalLayer]; + + // create external Layer + [self.checkBoxInternalLayer removeFromSuperlayer]; + self.checkBoxInternalLayer = [CAShapeLayer layer]; + [self.layer addSublayer:self.checkBoxInternalLayer]; + + // create tick layer + self.checkBoxTickLayer = [CAShapeLayer layer]; + [self.layer addSublayer:self.checkBoxTickLayer]; } #pragma mark - Navigation - (void)layoutSubviews { - [super layoutSubviews]; - - self.checkBoxTickLayer.frame = self.bounds; - self.checkBoxExternalLayer.frame = self.bounds; - self.checkBoxInternalLayer.frame = self.bounds; + [super layoutSubviews]; + + self.checkBoxTickLayer.frame = self.bounds; + self.checkBoxExternalLayer.frame = self.bounds; + self.checkBoxInternalLayer.frame = self.bounds; } #pragma mark - Public Methods - (void)setEnabled:(BOOL)enabled Animated:(BOOL)animated { - if (self.userInteractionEnabled == enabled) { - return; - } - - self.userInteractionEnabled = enabled; - if (enabled) { - if (self.isBooleanWidgetOn) { - [self fillCheckBoxExternalFromColor:[UIColor ml_meli_mid_grey] ToColor:[UIColor ml_meli_blue] Animated:animated]; - [self fillCheckBoxInternalFromColor:[UIColor ml_meli_mid_grey] ToColor:[UIColor ml_meli_blue] FromOpacity:1 ToOpacity:1 Animated:animated]; - [self fillCheckBoxTickAnimated:animated]; - } else { - [self fillCheckBoxExternalFromColor:[UIColor ml_meli_mid_grey] ToColor:[UIColor ml_meli_grey] Animated:animated]; - [self fillCheckBoxInternalFromColor:[UIColor ml_meli_mid_grey] ToColor:[UIColor ml_meli_grey] FromOpacity:0 ToOpacity:0 Animated:animated]; - } - } else { - if (self.isBooleanWidgetOn) { - [self fillCheckBoxExternalFromColor:[UIColor ml_meli_blue] ToColor:[UIColor ml_meli_mid_grey] Animated:animated]; - [self fillCheckBoxInternalFromColor:[UIColor ml_meli_blue] ToColor:[UIColor ml_meli_mid_grey] FromOpacity:1 ToOpacity:1 Animated:animated]; - [self fillCheckBoxTickAnimated:animated]; - } else { - [self fillCheckBoxExternalFromColor:[UIColor ml_meli_grey] ToColor:[UIColor ml_meli_mid_grey] Animated:animated]; - [self fillCheckBoxInternalFromColor:[UIColor ml_meli_grey] ToColor:[UIColor ml_meli_mid_grey] FromOpacity:0 ToOpacity:0 Animated:animated]; - } - } + if (self.userInteractionEnabled == enabled) { + return; + } + + self.userInteractionEnabled = enabled; + if (enabled) { + if (self.isBooleanWidgetOn) { + [self fillCheckBoxExternalFromColor:[UIColor ml_meli_mid_grey] ToColor:[UIColor ml_meli_blue] Animated:animated]; + [self fillCheckBoxInternalFromColor:[UIColor ml_meli_mid_grey] ToColor:[UIColor ml_meli_blue] FromOpacity:1 ToOpacity:1 Animated:animated]; + [self fillCheckBoxTickAnimated:animated]; + } else { + [self fillCheckBoxExternalFromColor:[UIColor ml_meli_mid_grey] ToColor:[UIColor ml_meli_grey] Animated:animated]; + [self fillCheckBoxInternalFromColor:[UIColor ml_meli_mid_grey] ToColor:[UIColor ml_meli_grey] FromOpacity:0 ToOpacity:0 Animated:animated]; + } + } else { + if (self.isBooleanWidgetOn) { + [self fillCheckBoxExternalFromColor:[UIColor ml_meli_blue] ToColor:[UIColor ml_meli_mid_grey] Animated:animated]; + [self fillCheckBoxInternalFromColor:[UIColor ml_meli_blue] ToColor:[UIColor ml_meli_mid_grey] FromOpacity:1 ToOpacity:1 Animated:animated]; + [self fillCheckBoxTickAnimated:animated]; + } else { + [self fillCheckBoxExternalFromColor:[UIColor ml_meli_grey] ToColor:[UIColor ml_meli_mid_grey] Animated:animated]; + [self fillCheckBoxInternalFromColor:[UIColor ml_meli_grey] ToColor:[UIColor ml_meli_mid_grey] FromOpacity:0 ToOpacity:0 Animated:animated]; + } + } } #pragma mark - Animation - (void)setOnBooleanWidgetAnimated:(BOOL)animated { - if (self.isBooleanWidgetOn) { - return; - } - - [self fillCheckBoxExternalAnimated:animated]; - [self fillCheckBoxInternalFromColor:[UIColor ml_meli_grey] ToColor:[UIColor ml_meli_blue] FromOpacity:0 ToOpacity:1 Animated:animated]; - [self fillCheckBoxTickAnimated:animated]; + if (self.isBooleanWidgetOn) { + return; + } + + [self fillCheckBoxExternalAnimated:animated]; + [self fillCheckBoxInternalFromColor:[UIColor ml_meli_grey] ToColor:[UIColor ml_meli_blue] FromOpacity:0 ToOpacity:1 Animated:animated]; + [self fillCheckBoxTickAnimated:animated]; } - (void)fillCheckBoxExternalFromColor:(UIColor *)fromColor ToColor:(UIColor *)toColor Animated:(BOOL)animated { - // Set circle layer bounds - self.checkBoxExternalLayer.bounds = CGRectMake(0, 0, CGRectGetHeight(self.frame), CGRectGetWidth(self.frame)); - - // Set circle layer path - UIBezierPath *externalFrame = [UIBezierPath bezierPathWithRoundedRect:self.checkBoxExternalLayer.bounds cornerRadius:kMLCheckBoxExternalCornerRadius]; - self.checkBoxExternalLayer.path = externalFrame.CGPath; - - self.checkBoxExternalLayer.fillColor = [UIColor clearColor].CGColor; - self.checkBoxExternalLayer.lineWidth = kMLCheckBoxExternalLineWidth; - - // Color animation - CABasicAnimation *colorFillAnimation = [self createColorFillAnimationFromColor:fromColor ToColor:toColor WithDuration:animated ? kMLCheckBoxAnimationDuration : kMLCheckBoxNotAnimationDuration ]; - - [self.checkBoxExternalLayer addAnimation:colorFillAnimation forKey:@"animateFill"]; - - self.checkBoxExternalLayer.strokeColor = toColor.CGColor; + // Set circle layer bounds + self.checkBoxExternalLayer.bounds = CGRectMake(0, 0, CGRectGetHeight(self.frame), CGRectGetWidth(self.frame)); + + // Set circle layer path + UIBezierPath *externalFrame = [UIBezierPath bezierPathWithRoundedRect:self.checkBoxExternalLayer.bounds cornerRadius:kMLCheckBoxExternalCornerRadius]; + self.checkBoxExternalLayer.path = externalFrame.CGPath; + + self.checkBoxExternalLayer.fillColor = [UIColor clearColor].CGColor; + self.checkBoxExternalLayer.lineWidth = kMLCheckBoxExternalLineWidth; + + // Color animation + CABasicAnimation *colorFillAnimation = [self createColorFillAnimationFromColor:fromColor ToColor:toColor WithDuration:animated ? kMLCheckBoxAnimationDuration : kMLCheckBoxNotAnimationDuration]; + + [self.checkBoxExternalLayer addAnimation:colorFillAnimation forKey:@"animateFill"]; + + self.checkBoxExternalLayer.strokeColor = toColor.CGColor; } - (void)fillCheckBoxExternalAnimated:(BOOL)animated { - [self fillCheckBoxExternalFromColor:[UIColor ml_meli_grey] ToColor:[UIColor ml_meli_blue] Animated:animated]; + [self fillCheckBoxExternalFromColor:[UIColor ml_meli_grey] ToColor:[UIColor ml_meli_blue] Animated:animated]; } - (void)fillCheckBoxInternalFromColor:(UIColor *)fromColor ToColor:(UIColor *)toColor FromOpacity:(float)fromOpacity ToOpacity:(float)toOpacity Animated:(BOOL)animated { - // Set circle layer bounds - self.checkBoxInternalLayer.bounds = CGRectMake(0, 0, CGRectGetHeight(self.frame), CGRectGetWidth(self.frame)); - - // Set circle layer path - UIBezierPath *internalFrame = [UIBezierPath bezierPathWithRoundedRect:self.checkBoxExternalLayer.bounds cornerRadius:kMLCheckBoxExternalCornerRadius]; - self.checkBoxInternalLayer.path = internalFrame.CGPath; - - - self.checkBoxInternalLayer.fillColor = toOpacity == 0 ? [UIColor clearColor].CGColor : toColor.CGColor; - float lineWidth = kMLCheckBoxExternalLineWidth; - - self.checkBoxInternalLayer.lineWidth = lineWidth; - - // Opacity animation - CABasicAnimation *opacityFillAnimation = [self createOpacityFillAnimationFromValue:fromOpacity ToValue:toOpacity]; - - // Color animation - CABasicAnimation *colorFillAnimation = [self createColorFillAnimationFromColor:fromColor ToColor:toColor]; - - // Compaund animation - CAAnimationGroup *fillAnimation = [CAAnimationGroup animation]; - fillAnimation.duration = animated ? kMLCheckBoxAnimationDuration : kMLCheckBoxNotAnimationDuration; - [fillAnimation setAnimations:[NSArray arrayWithObjects:colorFillAnimation, opacityFillAnimation, nil]]; - - [self.checkBoxInternalLayer addAnimation:fillAnimation forKey:@"animateFill"]; - - self.checkBoxInternalLayer.strokeColor = toColor.CGColor; + // Set circle layer bounds + self.checkBoxInternalLayer.bounds = CGRectMake(0, 0, CGRectGetHeight(self.frame), CGRectGetWidth(self.frame)); + + // Set circle layer path + UIBezierPath *internalFrame = [UIBezierPath bezierPathWithRoundedRect:self.checkBoxExternalLayer.bounds cornerRadius:kMLCheckBoxExternalCornerRadius]; + self.checkBoxInternalLayer.path = internalFrame.CGPath; + + self.checkBoxInternalLayer.fillColor = toOpacity == 0 ? [UIColor clearColor].CGColor : toColor.CGColor; + float lineWidth = kMLCheckBoxExternalLineWidth; + + self.checkBoxInternalLayer.lineWidth = lineWidth; + + // Opacity animation + CABasicAnimation *opacityFillAnimation = [self createOpacityFillAnimationFromValue:fromOpacity ToValue:toOpacity]; + + // Color animation + CABasicAnimation *colorFillAnimation = [self createColorFillAnimationFromColor:fromColor ToColor:toColor]; + + // Compaund animation + CAAnimationGroup *fillAnimation = [CAAnimationGroup animation]; + fillAnimation.duration = animated ? kMLCheckBoxAnimationDuration : kMLCheckBoxNotAnimationDuration; + [fillAnimation setAnimations:[NSArray arrayWithObjects:colorFillAnimation, opacityFillAnimation, nil]]; + + [self.checkBoxInternalLayer addAnimation:fillAnimation forKey:@"animateFill"]; + + self.checkBoxInternalLayer.strokeColor = toColor.CGColor; } - (void)fillCheckBoxTickAnimated:(BOOL)animated { - // Set circle layer bounds - self.checkBoxTickLayer.bounds = CGRectMake(0, 0, CGRectGetHeight(self.frame), CGRectGetWidth(self.frame)); - - // Set circle layer path - UIBezierPath *tickPath = [UIBezierPath bezierPath]; - - [tickPath moveToPoint:[self tickLeftPointInRect:self.bounds]]; - [tickPath addLineToPoint:[self tickBotomPointInRect:self.bounds]]; - [tickPath addLineToPoint:[self tickRightPointInRect:self.bounds]]; - - self.checkBoxTickLayer.path = tickPath.CGPath; - - self.checkBoxTickLayer.strokeColor = [UIColor ml_meli_white].CGColor; - self.checkBoxTickLayer.fillColor = [UIColor clearColor].CGColor; - float lineWidth = kMLCheckBoxTickLineWidth; - - self.checkBoxTickLayer.lineWidth = lineWidth; - - // Color animation - CABasicAnimation *pathTickAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; - pathTickAnimation.fromValue = @0.0; - pathTickAnimation.toValue = @1.0; - pathTickAnimation.fillMode = kCAFillModeForwards; - pathTickAnimation.duration = animated ? kMLCheckBoxAnimationDuration : kMLCheckBoxNotAnimationDuration; - - [self.checkBoxTickLayer addAnimation:pathTickAnimation forKey:@"animateFillTick"]; + // Set circle layer bounds + self.checkBoxTickLayer.bounds = CGRectMake(0, 0, CGRectGetHeight(self.frame), CGRectGetWidth(self.frame)); + + // Set circle layer path + UIBezierPath *tickPath = [UIBezierPath bezierPath]; + + [tickPath moveToPoint:[self tickLeftPointInRect:self.bounds]]; + [tickPath addLineToPoint:[self tickBotomPointInRect:self.bounds]]; + [tickPath addLineToPoint:[self tickRightPointInRect:self.bounds]]; + + self.checkBoxTickLayer.path = tickPath.CGPath; + + self.checkBoxTickLayer.strokeColor = [UIColor ml_meli_white].CGColor; + self.checkBoxTickLayer.fillColor = [UIColor clearColor].CGColor; + float lineWidth = kMLCheckBoxTickLineWidth; + + self.checkBoxTickLayer.lineWidth = lineWidth; + + // Color animation + CABasicAnimation *pathTickAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; + pathTickAnimation.fromValue = @0.0; + pathTickAnimation.toValue = @1.0; + pathTickAnimation.fillMode = kCAFillModeForwards; + pathTickAnimation.duration = animated ? kMLCheckBoxAnimationDuration : kMLCheckBoxNotAnimationDuration; + + [self.checkBoxTickLayer addAnimation:pathTickAnimation forKey:@"animateFillTick"]; } - (void)setOffBooleanWidgetAnimated:(BOOL)animated { - [self fillCheckBoxExternalFromColor:[UIColor ml_meli_blue] ToColor:[UIColor ml_meli_grey] Animated:animated]; - [self fillCheckBoxInternalFromColor:[UIColor ml_meli_blue] ToColor:[UIColor ml_meli_grey] FromOpacity:1 ToOpacity:0 Animated:animated]; + [self fillCheckBoxExternalFromColor:[UIColor ml_meli_blue] ToColor:[UIColor ml_meli_grey] Animated:animated]; + [self fillCheckBoxInternalFromColor:[UIColor ml_meli_blue] ToColor:[UIColor ml_meli_grey] FromOpacity:1 ToOpacity:0 Animated:animated]; } #pragma mark - Tick Positions - (CGPoint)tickLeftPointInRect:(CGRect)rect { - CGFloat x = rect.size.width * (2.5 / 15.0); - CGFloat y = rect.size.height / 2.0; - - return CGPointMake(x, y); + CGFloat x = rect.size.width * (2.5 / 15.0); + CGFloat y = rect.size.height / 2.0; + + return CGPointMake(x, y); } - (CGPoint)tickBotomPointInRect:(CGRect)rect { - CGFloat x = rect.size.width * (1.0 / 3.0); - CGFloat y = rect.size.height * (2.0 / 3.0); - - return CGPointMake(x, y); + CGFloat x = rect.size.width * (1.0 / 3.0); + CGFloat y = rect.size.height * (2.0 / 3.0); + + return CGPointMake(x, y); } - (CGPoint)tickRightPointInRect:(CGRect)rect { - CGFloat x = rect.size.width - (rect.size.width * (2.5 / 15.0)); - CGFloat y = rect.size.height / 4.0; - - return CGPointMake(x, y); + CGFloat x = rect.size.width - (rect.size.width * (2.5 / 15.0)); + CGFloat y = rect.size.height / 4.0; + + return CGPointMake(x, y); } - (CABasicAnimation *)createOpacityFillAnimationFromValue:(float)fromValue ToValue:(float)toValue { - return [self createOpacityFillAnimationFromValue:fromValue ToValue:toValue WithDuration:0 WithFillMode:kCAFillModeForwards]; + return [self createOpacityFillAnimationFromValue:fromValue ToValue:toValue WithDuration:0 WithFillMode:kCAFillModeForwards]; } - (CABasicAnimation *)createOpacityFillAnimationFromValue:(float)fromValue ToValue:(float)toValue WithDuration:(double)duration { - return [self createOpacityFillAnimationFromValue:fromValue ToValue:toValue WithDuration:duration WithFillMode:kCAFillModeForwards]; + return [self createOpacityFillAnimationFromValue:fromValue ToValue:toValue WithDuration:duration WithFillMode:kCAFillModeForwards]; } - (CABasicAnimation *)createOpacityFillAnimationFromValue:(float)fromValue ToValue:(float)toValue WithDuration:(double)duration WithFillMode:(NSString *)fillMode { - CABasicAnimation *opacityFillAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; - opacityFillAnimation.fromValue = [NSNumber numberWithFloat:fromValue]; - opacityFillAnimation.toValue = [NSNumber numberWithFloat:toValue]; - opacityFillAnimation.duration = duration; - opacityFillAnimation.fillMode = fillMode; - - return opacityFillAnimation; + CABasicAnimation *opacityFillAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; + opacityFillAnimation.fromValue = [NSNumber numberWithFloat:fromValue]; + opacityFillAnimation.toValue = [NSNumber numberWithFloat:toValue]; + opacityFillAnimation.duration = duration; + opacityFillAnimation.fillMode = fillMode; + + return opacityFillAnimation; } -- (CABasicAnimation *)createColorFillAnimationFromColor:(UIColor *)fromColor ToColor:(UIColor *)toColor WithDuration: (double)duration +- (CABasicAnimation *)createColorFillAnimationFromColor:(UIColor *)fromColor ToColor:(UIColor *)toColor WithDuration:(double)duration { - return [self createColorFillAnimationFromColor:fromColor ToColor:toColor WithDuration:duration WithFillMode:kCAFillModeForwards]; + return [self createColorFillAnimationFromColor:fromColor ToColor:toColor WithDuration:duration WithFillMode:kCAFillModeForwards]; } - (CABasicAnimation *)createColorFillAnimationFromColor:(UIColor *)fromColor ToColor:(UIColor *)toColor { - return [self createColorFillAnimationFromColor:fromColor ToColor:toColor WithDuration:0 WithFillMode:kCAFillModeForwards]; + return [self createColorFillAnimationFromColor:fromColor ToColor:toColor WithDuration:0 WithFillMode:kCAFillModeForwards]; } - (CABasicAnimation *)createColorFillAnimationFromColor:(UIColor *)fromColor ToColor:(UIColor *)toColor WithDuration:(double)duration WithFillMode:(NSString *)fillMode { - CABasicAnimation *colorFillAnimation = [CABasicAnimation animationWithKeyPath:@"strokeColor"]; - colorFillAnimation.fromValue = (id)fromColor.CGColor; - colorFillAnimation.toValue = (id)toColor.CGColor; - colorFillAnimation.duration = duration; - colorFillAnimation.fillMode = fillMode; - - return colorFillAnimation; + CABasicAnimation *colorFillAnimation = [CABasicAnimation animationWithKeyPath:@"strokeColor"]; + colorFillAnimation.fromValue = (id)fromColor.CGColor; + colorFillAnimation.toValue = (id)toColor.CGColor; + colorFillAnimation.duration = duration; + colorFillAnimation.fillMode = fillMode; + + return colorFillAnimation; } @end - From 0179ae7b58fc83296b1ae866f972e1e85d0af235 Mon Sep 17 00:00:00 2001 From: Alexandre Iartsev Date: Wed, 22 Aug 2018 08:38:16 -0300 Subject: [PATCH 05/17] Unchecked unselected image fix and interactivity fix. --- .../MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m b/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m index 54604e1..04d533a 100644 --- a/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m +++ b/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m @@ -93,7 +93,7 @@ - (void)setEnabled:(BOOL)enabled Animated:(BOOL)animated - (void)setOnBooleanWidgetAnimated:(BOOL)animated { - if (self.isBooleanWidgetOn) { + if (self.isBooleanWidgetOn || !self.userInteractionEnabled) { return; } @@ -189,6 +189,10 @@ - (void)fillCheckBoxTickAnimated:(BOOL)animated - (void)setOffBooleanWidgetAnimated:(BOOL)animated { + if (!self.userInteractionEnabled) { + return; + } + [self fillCheckBoxExternalFromColor:[UIColor ml_meli_blue] ToColor:[UIColor ml_meli_grey] Animated:animated]; [self fillCheckBoxInternalFromColor:[UIColor ml_meli_blue] ToColor:[UIColor ml_meli_grey] FromOpacity:1 ToOpacity:0 Animated:animated]; } From 39a75a30493bac73fadd13b5e2492f450d839df8 Mon Sep 17 00:00:00 2001 From: Alexandre Iartsev Date: Wed, 22 Aug 2018 08:56:19 -0300 Subject: [PATCH 06/17] Control MLCheckBox in test app --- .../MLBooleanWidgetViewController.m | 13 ++ .../MLBooleanWidgetViewController.xib | 142 +++++++++++------- 2 files changed, 101 insertions(+), 54 deletions(-) diff --git a/Example/MLBooleanWidget/MLBooleanWidgetViewController.m b/Example/MLBooleanWidget/MLBooleanWidgetViewController.m index 494c685..9e59192 100644 --- a/Example/MLBooleanWidget/MLBooleanWidgetViewController.m +++ b/Example/MLBooleanWidget/MLBooleanWidgetViewController.m @@ -20,6 +20,7 @@ @interface MLBooleanWidgetViewController () @property (weak, nonatomic) IBOutlet MLCheckBox *mlCheckBox1; @property (weak, nonatomic) IBOutlet MLCheckBox *mlCheckBox2; +@property (weak, nonatomic) IBOutlet MLCheckBox *mlCheckBox3; @property (weak, nonatomic) IBOutlet MLRadioButton *mlRadioButton1; @property (weak, nonatomic) IBOutlet MLRadioButton *mlRadioButton2; @@ -44,6 +45,7 @@ - (void)viewDidLoad [self setupTitle]; [self setupCheckBox]; [self setupCheckBoxLabels]; + [self setupControlCheckbox]; [self setupRadioButton]; [self setupOptionLabels]; [self setupSwitch]; @@ -60,6 +62,12 @@ - (void)setupCheckBox self.mlCheckList = [MLCheckList checkListWithCheckBoxes:@[self.mlCheckBox1, self.mlCheckBox2]]; } +- (void)setupControlCheckbox +{ + [self.mlCheckBox3 onAnimated:NO]; + self.mlCheckBox3.delegate = self; +} + - (void)setupCheckBoxLabels { [self.checkBox1Label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(checkBoxButton1DidTouch:)]]; @@ -86,6 +94,11 @@ - (void)setupSwitch - (void)booleanWidgetDidRequestChangeOfState:(MLBooleanWidget *)booleanWidget { [booleanWidget toggleAnimated:YES]; + + if (booleanWidget == self.mlCheckBox3) { + [self.mlCheckBox1 setEnabled:booleanWidget.isOn Animated:YES]; + [self.mlCheckBox2 setEnabled:booleanWidget.isOn Animated:YES]; + } } #pragma mark - Actions diff --git a/Example/MLBooleanWidget/MLBooleanWidgetViewController.xib b/Example/MLBooleanWidget/MLBooleanWidgetViewController.xib index 7c7350d..0a1a414 100644 --- a/Example/MLBooleanWidget/MLBooleanWidgetViewController.xib +++ b/Example/MLBooleanWidget/MLBooleanWidgetViewController.xib @@ -1,11 +1,14 @@ - - + + + + + - - + + @@ -14,6 +17,7 @@ + @@ -24,24 +28,24 @@ - + - + - - + + - + - + - + @@ -50,11 +54,11 @@ - + @@ -62,12 +66,12 @@ - + - + @@ -76,11 +80,11 @@ - + @@ -89,7 +93,7 @@ - + @@ -101,14 +105,14 @@ - - + @@ -125,34 +129,34 @@ - - + + - - + @@ -180,37 +184,37 @@ - - + + - - + - + - + @@ -284,7 +318,7 @@ - + From 2e87e4e86421cd7b10571d94e8aa38bf9c6c9b5b Mon Sep 17 00:00:00 2001 From: Alexandre Iartsev Date: Wed, 22 Aug 2018 08:56:55 -0300 Subject: [PATCH 07/17] Uncrustify magic --- .../MLBooleanWidgetViewController.m | 16 ++++++++-------- .../MLCheckBox/classes/MLCheckBox.m | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Example/MLBooleanWidget/MLBooleanWidgetViewController.m b/Example/MLBooleanWidget/MLBooleanWidgetViewController.m index 9e59192..7493316 100644 --- a/Example/MLBooleanWidget/MLBooleanWidgetViewController.m +++ b/Example/MLBooleanWidget/MLBooleanWidgetViewController.m @@ -45,7 +45,7 @@ - (void)viewDidLoad [self setupTitle]; [self setupCheckBox]; [self setupCheckBoxLabels]; - [self setupControlCheckbox]; + [self setupControlCheckbox]; [self setupRadioButton]; [self setupOptionLabels]; [self setupSwitch]; @@ -64,8 +64,8 @@ - (void)setupCheckBox - (void)setupControlCheckbox { - [self.mlCheckBox3 onAnimated:NO]; - self.mlCheckBox3.delegate = self; + [self.mlCheckBox3 onAnimated:NO]; + self.mlCheckBox3.delegate = self; } - (void)setupCheckBoxLabels @@ -94,11 +94,11 @@ - (void)setupSwitch - (void)booleanWidgetDidRequestChangeOfState:(MLBooleanWidget *)booleanWidget { [booleanWidget toggleAnimated:YES]; - - if (booleanWidget == self.mlCheckBox3) { - [self.mlCheckBox1 setEnabled:booleanWidget.isOn Animated:YES]; - [self.mlCheckBox2 setEnabled:booleanWidget.isOn Animated:YES]; - } + + if (booleanWidget == self.mlCheckBox3) { + [self.mlCheckBox1 setEnabled:booleanWidget.isOn Animated:YES]; + [self.mlCheckBox2 setEnabled:booleanWidget.isOn Animated:YES]; + } } #pragma mark - Actions diff --git a/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m b/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m index 04d533a..293e3df 100644 --- a/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m +++ b/LibraryComponents/MLBooleanWidget/MLCheckBox/classes/MLCheckBox.m @@ -189,10 +189,10 @@ - (void)fillCheckBoxTickAnimated:(BOOL)animated - (void)setOffBooleanWidgetAnimated:(BOOL)animated { - if (!self.userInteractionEnabled) { - return; - } - + if (!self.userInteractionEnabled) { + return; + } + [self fillCheckBoxExternalFromColor:[UIColor ml_meli_blue] ToColor:[UIColor ml_meli_grey] Animated:animated]; [self fillCheckBoxInternalFromColor:[UIColor ml_meli_blue] ToColor:[UIColor ml_meli_grey] FromOpacity:1 ToOpacity:0 Animated:animated]; } From 5afec13426314973015d40c4030d851e7002f4e9 Mon Sep 17 00:00:00 2001 From: Alexandre Iartsev Date: Wed, 22 Aug 2018 09:00:09 -0300 Subject: [PATCH 08/17] Text change so it makes sense --- Example/MLBooleanWidget/MLBooleanWidgetViewController.xib | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Example/MLBooleanWidget/MLBooleanWidgetViewController.xib b/Example/MLBooleanWidget/MLBooleanWidgetViewController.xib index 0a1a414..6f636cd 100644 --- a/Example/MLBooleanWidget/MLBooleanWidgetViewController.xib +++ b/Example/MLBooleanWidget/MLBooleanWidgetViewController.xib @@ -259,8 +259,8 @@ -