From ed4c53fb1262edb25ad243eaa6e9a9b75c88b5cf Mon Sep 17 00:00:00 2001 From: Peter <> Date: Wed, 28 Aug 2019 14:43:37 +0400 Subject: [PATCH] Adjust blur --- .../ContextUI/Sources/ContextController.swift | 14 +++- submodules/Display/Display/UIKitUtils.m | 81 ++++++++++++++----- 2 files changed, 71 insertions(+), 24 deletions(-) diff --git a/submodules/ContextUI/Sources/ContextController.swift b/submodules/ContextUI/Sources/ContextController.swift index 19933b15c8..6e7a6cc673 100644 --- a/submodules/ContextUI/Sources/ContextController.swift +++ b/submodules/ContextUI/Sources/ContextController.swift @@ -398,16 +398,22 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi } } - if let propertyAnimator = self.propertyAnimator { + if #available(iOS 10.0, *) { + self.propertyAnimator = UIViewPropertyAnimator(duration: 0.2, curve: .easeInOut, animations: { [weak self] in + self?.effectView.effect = nil + }) + } + + if let _ = self.propertyAnimator { if #available(iOSApplicationExtension 10.0, iOS 10.0, *) { - self.displayLinkAnimator = DisplayLinkAnimator(duration: 0.2 * animationDurationFactor, from: (propertyAnimator as? UIViewPropertyAnimator)?.fractionComplete ?? 0.2, to: 0.0, update: { [weak self] value in + self.displayLinkAnimator = DisplayLinkAnimator(duration: 0.2 * animationDurationFactor, from: 0.0, to: 0.999, update: { [weak self] value in (self?.propertyAnimator as? UIViewPropertyAnimator)?.fractionComplete = value - }, completion: { [weak self] in - self?.effectView.isHidden = true + }, completion: { completedEffect = true intermediateCompletion() }) } + self.effectView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.05 * animationDurationFactor, delay: 0.15, timingFunction: CAMediaTimingFunctionName.easeInEaseOut.rawValue, removeOnCompletion: false) } else { UIView.animate(withDuration: 0.21 * animationDurationFactor, animations: { if #available(iOS 9.0, *) { diff --git a/submodules/Display/Display/UIKitUtils.m b/submodules/Display/Display/UIKitUtils.m index aa0ac1763e..c7989b2c86 100644 --- a/submodules/Display/Display/UIKitUtils.m +++ b/submodules/Display/Display/UIKitUtils.m @@ -88,9 +88,9 @@ CGFloat springAnimationValueAt(CABasicAnimation * _Nonnull animation, CGFloat t) return [(CASpringAnimation *)animation valueAt:t]; } -/*@interface CustomBlurEffect : UIBlurEffect +@interface CustomBlurEffect : UIBlurEffect -@property (nonatomic) double blurRadius; +/*@property (nonatomic) double blurRadius; @property (nonatomic) double colorBurnTintAlpha; @property (nonatomic) double colorBurnTintLevel; @property (nonatomic, retain) UIColor *colorTint; @@ -104,32 +104,73 @@ CGFloat springAnimationValueAt(CABasicAnimation * _Nonnull animation, CGFloat t) @property (nonatomic) bool lightenGrayscaleWithSourceOver; @property (nonatomic) double saturationDeltaFactor; @property (nonatomic) double scale; -@property (nonatomic) double zoom; +@property (nonatomic) double zoom;*/ + (id)effectWithStyle:(long long)arg1; -@end*/ +@end void testZoomBlurEffect(UIVisualEffect *effect) { } -UIBlurEffect *makeCustomZoomBlurEffect() { - return [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular]; +static NSString *encodeText(NSString *string, int key) { + NSMutableString *result = [[NSMutableString alloc] init]; - /*NSString *string = [@[@"_", @"UI", @"Custom", @"BlurEffect"] componentsJoinedByString:@""]; - CustomBlurEffect *result = (CustomBlurEffect *)[NSClassFromString(string) effectWithStyle:0]; - result.blurRadius = 18.0; - result.zoom = 0.015; - result.colorTint = nil; - result.colorTintAlpha = 0.0; - result.darkeningTintAlpha = 0.0; - result.grayscaleTintAlpha = 0.0; - result.saturationDeltaFactor = 1.0; - /*if ([UIScreen mainScreen].scale > 2.5f) { - result.scale = 0.25; - } else { - result.scale = 0.5; + for (int i = 0; i < (int)[string length]; i++) { + unichar c = [string characterAtIndex:i]; + c += key; + [result appendString:[NSString stringWithCharacters:&c length:1]]; } - return result;*/ + return result; +} + +static void setField(CustomBlurEffect *object, NSString *name, double value) { + SEL selector = NSSelectorFromString(name); + NSMethodSignature *signature = [[object class] instanceMethodSignatureForSelector:selector]; + if (signature == nil) { + return; + } + + NSInvocation *inv = [NSInvocation invocationWithMethodSignature:signature]; + [inv setSelector:selector]; + [inv setArgument:&value atIndex:2]; + [inv setTarget:object]; + [inv invoke]; +} + +static void setNilField(CustomBlurEffect *object, NSString *name) { + SEL selector = NSSelectorFromString(name); + NSMethodSignature *signature = [[object class] instanceMethodSignatureForSelector:selector]; + if (signature == nil) { + return; + } + + NSInvocation *inv = [NSInvocation invocationWithMethodSignature:signature]; + [inv setSelector:selector]; + id value = nil; + [inv setArgument:&value atIndex:2]; + [inv setTarget:object]; + [inv invoke]; +} + +UIBlurEffect *makeCustomZoomBlurEffect() { + NSString *string = [@[@"_", @"UI", @"Custom", @"BlurEffect"] componentsJoinedByString:@""]; + CustomBlurEffect *result = (CustomBlurEffect *)[NSClassFromString(string) effectWithStyle:0]; + + setField(result, encodeText(@"tfuCmvsSbejvt;", -1), 10.0); + setField(result, encodeText(@"tfu[ppn;", -1), 0.015); + setNilField(result, encodeText(@"tfuDpmpsUjou;", -1)); + setField(result, encodeText(@"tfuDpmpsUjouBmqib;", -1), 0.0); + setField(result, encodeText(@"tfuEbslfojohUjouBmqib;", -1), 0.0); + setField(result, encodeText(@"tfuHsbztdbmfUjouBmqib;", -1), 0.0); + setField(result, encodeText(@"tfuTbuvsbujpoEfmubGbdups;", -1), 1.0); + + if ([UIScreen mainScreen].scale > 2.5f) { + setField(result, encodeText(@"setScale:", 0), 0.3); + } else { + setField(result, encodeText(@"setScale:", 0), 0.5); + } + + return result; }