diff --git a/submodules/LegacyComponents/LegacyImages.xcassets/Camera/Flash.imageset/Contents.json b/submodules/LegacyComponents/LegacyImages.xcassets/Camera/Flash.imageset/Contents.json new file mode 100644 index 0000000000..2ddf28fc77 --- /dev/null +++ b/submodules/LegacyComponents/LegacyImages.xcassets/Camera/Flash.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "filename" : "ic_cam_flashon (1).pdf", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/submodules/LegacyComponents/LegacyImages.xcassets/Camera/Flash.imageset/ic_cam_flashon (1).pdf b/submodules/LegacyComponents/LegacyImages.xcassets/Camera/Flash.imageset/ic_cam_flashon (1).pdf new file mode 100644 index 0000000000..0cd45d0c0e Binary files /dev/null and b/submodules/LegacyComponents/LegacyImages.xcassets/Camera/Flash.imageset/ic_cam_flashon (1).pdf differ diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGCameraFlashControl.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGCameraFlashControl.h index b914fd8eef..50b3dff6d0 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGCameraFlashControl.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGCameraFlashControl.h @@ -6,15 +6,13 @@ @property (nonatomic, assign) PGCameraFlashMode mode; @property (nonatomic, assign) UIInterfaceOrientation interfaceOrientation; -@property (nonatomic, copy) void(^becameActive)(void); @property (nonatomic, copy) void(^modeChanged)(PGCameraFlashMode mode); - (void)setFlashUnavailable:(bool)unavailable; +- (void)setFlashActive:(bool)active; - (void)setHidden:(bool)hidden animated:(bool)animated; -- (void)dismissAnimated:(bool)animated; - @end extern const CGFloat TGCameraFlashControlHeight; diff --git a/submodules/LegacyComponents/Sources/TGCameraController.m b/submodules/LegacyComponents/Sources/TGCameraController.m index dbd9ba9d0c..0eff7be645 100644 --- a/submodules/LegacyComponents/Sources/TGCameraController.m +++ b/submodules/LegacyComponents/Sources/TGCameraController.m @@ -712,8 +712,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus TGDispatchOnMainThread(^ { - if (!strongSelf->_camera.isRecordingVideo) - [strongSelf->_interfaceView setFlashActive:active]; + [strongSelf->_interfaceView setFlashActive:active]; }); }; diff --git a/submodules/LegacyComponents/Sources/TGCameraFlashControl.m b/submodules/LegacyComponents/Sources/TGCameraFlashControl.m index 743e5db3be..4f7e1f2c96 100644 --- a/submodules/LegacyComponents/Sources/TGCameraFlashControl.m +++ b/submodules/LegacyComponents/Sources/TGCameraFlashControl.m @@ -2,21 +2,118 @@ #import "LegacyComponentsInternal.h" +#import "TGImageUtils.h" + #import "UIControl+HitTestEdgeInsets.h" #import "TGCameraInterfaceAssets.h" #import +#import "POPBasicAnimation.h" + const CGFloat TGCameraFlashControlHeight = 44.0f; +@interface TGCameraFlashIcon: UIView +{ + bool _active; + CGFloat _progress; + bool _on; +} +@end + +@implementation TGCameraFlashIcon + +- (instancetype)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; + if (self != nil) { + self.contentMode = UIViewContentModeRedraw; + } + return self; +} + +- (void)setOn:(bool)on animated:(bool)animated { + _on = on; + if (animated) { + POPBasicAnimation *animation = [POPBasicAnimation animation]; + animation.property = [POPAnimatableProperty propertyWithName:@"progress" initializer:^(POPMutableAnimatableProperty *prop) + { + prop.readBlock = ^(TGCameraFlashIcon *view, CGFloat values[]) + { + if (view != nil) { + values[0] = view->_progress; + } + }; + + prop.writeBlock = ^(TGCameraFlashIcon *view, const CGFloat values[]) + { + view->_progress = values[0]; + [view setNeedsDisplay]; + }; + + prop.threshold = 0.03f; + }]; + animation.fromValue = @(_progress); + animation.toValue = @(on ? 1.0 : 0.0); + animation.duration = 0.2; + animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; + [self pop_addAnimation:animation forKey:@"progress"]; + } else { + _progress = on ? 1.0 : 0.0; + [self setNeedsDisplay]; + } +} + +- (void)setActive:(bool)active { + _active = active; + [self setNeedsDisplay]; +} + +- (void)drawRect:(CGRect)__unused rect +{ + CGContextRef context = UIGraphicsGetCurrentContext(); + CGRect bounds = CGRectMake(0, 0, rect.size.width, rect.size.height); + + CGContextClearRect(context, bounds); + + UIImage *iconImage = [UIImage imageNamed:@"Camera/Flash"]; + + if (_active && _on) { + CGContextSetFillColorWithColor(context, [TGCameraInterfaceAssets accentColor].CGColor); + CGContextFillEllipseInRect(context, CGRectInset(bounds, 2.5, 2.5)); + + [TGTintedImage(iconImage, [UIColor blackColor]) drawInRect:CGRectMake(0, 0, 30, 30)]; + } else { + CGContextSetLineWidth(context, 1.0); + CGContextSetStrokeColorWithColor(context, [UIColor colorWithWhite:1.0 alpha:0.5].CGColor); + CGContextStrokeEllipseInRect(context, CGRectInset(bounds, 3.0, 3.0)); + + [TGTintedImage(iconImage, [UIColor whiteColor]) drawInRect:CGRectMake(0, 0, 30, 30)]; + } + + CGFloat lineProgress = 1.0 - _progress; + + if (lineProgress > 0.0) { + CGMutablePathRef path = CGPathCreateMutable(); + CGPathMoveToPoint(path, NULL, 5, 5); + CGPathAddLineToPoint(path, NULL, 5 + (bounds.size.width - 10.0) * lineProgress, 5 + (bounds.size.height - 10.0) * lineProgress); + + CGPathRef strokedPath = CGPathCreateCopyByStrokingPath(path, NULL, 2.0f, kCGLineCapRound, kCGLineJoinMiter, 10); + CGContextAddPath(context, strokedPath); + CGPathRelease(strokedPath); + CGPathRelease(path); + + CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor); + CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor); + CGContextDrawPath(context, kCGPathFillStroke); + } +} + +@end + @interface TGCameraFlashControl () { - UIButton *_flashIconView; - UIButton *_autoButton; - UIButton *_onButton; - UIButton *_offButton; - - bool _active; + TGCameraFlashIcon *_icon; + UIButton *_button; } @end @@ -27,23 +124,22 @@ const CGFloat TGCameraFlashControlHeight = 44.0f; self = [super initWithFrame:frame]; if (self != nil) { + self.mode = PGCameraFlashModeOff; + self.hitTestEdgeInsets = UIEdgeInsetsMake(-10, -10, -10, -10); - _flashIconView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)]; - _flashIconView.adjustsImageWhenHighlighted = false; - _flashIconView.contentMode = UIViewContentModeCenter; - _flashIconView.exclusiveTouch = true; - _flashIconView.hitTestEdgeInsets = UIEdgeInsetsMake(0, -10, 0, -10); - _flashIconView.tag = -1; - [_flashIconView setImage:[UIImage imageNamed:@"Camera/FlashOff"] forState:UIControlStateNormal]; - [_flashIconView addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; - [self addSubview:_flashIconView]; - - [UIView performWithoutAnimation:^ - { - self.mode = PGCameraFlashModeOff; - [self setActive:false animated:false]; - }]; + _icon = [[TGCameraFlashIcon alloc] initWithFrame:CGRectMake(7, 7, 30, 30)]; + _icon.userInteractionEnabled = false; + [self addSubview:_icon]; + + _button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)]; + _button.adjustsImageWhenHighlighted = false; + _button.contentMode = UIViewContentModeCenter; + _button.exclusiveTouch = true; + _button.hitTestEdgeInsets = UIEdgeInsetsMake(0, -10, 0, -10); + _button.tag = -1; + [_button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; + [self addSubview:_button]; } return self; } @@ -61,11 +157,11 @@ const CGFloat TGCameraFlashControlHeight = 44.0f; - (void)buttonPressed:(UIButton *)sender { if (_mode == PGCameraFlashModeOff) { - self.mode = PGCameraFlashModeOn; - [_flashIconView setImage:[UIImage imageNamed:@"Camera/FlashOn"] forState:UIControlStateNormal]; + self.mode = PGCameraFlashModeAuto; + [_icon setOn:true animated:true]; } else { self.mode = PGCameraFlashModeOff; - [_flashIconView setImage:[UIImage imageNamed:@"Camera/FlashOff"] forState:UIControlStateNormal]; + [_icon setOn:false animated:true]; } if (self.modeChanged != nil) @@ -75,35 +171,24 @@ const CGFloat TGCameraFlashControlHeight = 44.0f; - (void)setFlashUnavailable:(bool)unavailable { self.userInteractionEnabled = !unavailable; - [self setActive:false animated:false]; + self.alpha = unavailable ? 0.4 : 1.0; } -- (void)setActive:(bool)active animated:(bool)animated +- (void)setFlashActive:(bool)active { - return; + [_icon setActive:active]; } - (void)setMode:(PGCameraFlashMode)mode { _mode = mode; - - [self setActive:false animated:_active]; -} - -- (void)dismissAnimated:(bool)animated -{ - if (animated && _active) - [self setActive:false animated:animated]; - else - [self setActive:false animated:false]; + [_icon setOn:mode == PGCameraFlashModeAuto animated:true]; } - (void)setHidden:(BOOL)hidden { self.alpha = hidden ? 0.0f : 1.0f; super.hidden = hidden; - - [self setActive:false animated:false]; } - (void)setHidden:(bool)hidden animated:(bool)animated @@ -123,16 +208,12 @@ const CGFloat TGCameraFlashControlHeight = 44.0f; if (finished) self.hidden = hidden; - - [self setActive:false animated:false]; }]; } else { self.alpha = hidden ? 0.0f : 1.0f; super.hidden = hidden; - - [self setActive:false animated:false]; } } diff --git a/submodules/LegacyComponents/Sources/TGCameraMainPhoneView.m b/submodules/LegacyComponents/Sources/TGCameraMainPhoneView.m index df82cfcfd5..0613a78ee8 100644 --- a/submodules/LegacyComponents/Sources/TGCameraMainPhoneView.m +++ b/submodules/LegacyComponents/Sources/TGCameraMainPhoneView.m @@ -440,13 +440,6 @@ #pragma mark - Actions -- (void)shutterButtonReleased -{ - [super shutterButtonReleased]; - - [_flashControl dismissAnimated:true]; -} - - (void)updateForCameraModeChangeWithPreviousMode:(PGCameraMode)previousMode { [super updateForCameraModeChangeWithPreviousMode:previousMode]; @@ -490,7 +483,6 @@ [self _attachControlsToTopPanel]; [self _layoutTopPanelSubviewsForInterfaceOrientation:orientation]; - [_flashControl dismissAnimated:false]; [UIView animateWithDuration:0.2f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^ { @@ -512,7 +504,7 @@ - (void)setFlashActive:(bool)active { - [_flashActiveView setActive:active animated:true]; + [_flashControl setFlashActive:active]; } - (void)setFlashUnavailable:(bool)unavailable @@ -522,9 +514,6 @@ - (void)setHasFlash:(bool)hasFlash { - if (!hasFlash) - [_flashActiveView setActive:false animated:true]; - [_flashControl setHidden:!hasFlash animated:true]; } @@ -676,8 +665,6 @@ } else { - [_flashControl dismissAnimated:false]; - _flipButton.transform = CGAffineTransformMakeRotation(TGRotationForInterfaceOrientation(orientation)); _flashControl.transform = CGAffineTransformMakeRotation(TGRotationForInterfaceOrientation(orientation)); _zoomModeView.interfaceOrientation = orientation;