|
| 1 | +#import <QuartzCore/QuartzCore.h> |
| 2 | +#import <React/RCTViewManager.h> |
| 3 | +#import <UIKit/UIKit.h> |
| 4 | + |
| 5 | +@interface LinkCodeGradientMaskView : UIView |
| 6 | +@end |
| 7 | + |
| 8 | +@implementation LinkCodeGradientMaskView |
| 9 | + |
| 10 | ++ (Class)layerClass |
| 11 | +{ |
| 12 | + return CAGradientLayer.class; |
| 13 | +} |
| 14 | + |
| 15 | +- (instancetype)initWithFrame:(CGRect)frame |
| 16 | +{ |
| 17 | + self = [super initWithFrame:frame]; |
| 18 | + if (self) { |
| 19 | + CAGradientLayer *gradient = (CAGradientLayer *)self.layer; |
| 20 | + gradient.colors = @[ |
| 21 | + (id)UIColor.whiteColor.CGColor, |
| 22 | + (id)UIColor.whiteColor.CGColor, |
| 23 | + (id)UIColor.clearColor.CGColor |
| 24 | + ]; |
| 25 | + gradient.locations = @[ @0, @0.82, @1 ]; |
| 26 | + gradient.startPoint = CGPointMake(0.5, 0); |
| 27 | + gradient.endPoint = CGPointMake(0.5, 1); |
| 28 | + self.userInteractionEnabled = NO; |
| 29 | + } |
| 30 | + return self; |
| 31 | +} |
| 32 | + |
| 33 | +@end |
| 34 | + |
| 35 | +@interface LinkCodeNavigationBarBackdropView : UIView |
| 36 | +@property(nonatomic, strong) UIVisualEffectView *blurView; |
| 37 | +@property(nonatomic, strong) LinkCodeGradientMaskView *gradientMask; |
| 38 | +@property(nonatomic, assign) CGSize maskSize; |
| 39 | +@end |
| 40 | + |
| 41 | +@implementation LinkCodeNavigationBarBackdropView |
| 42 | + |
| 43 | +- (instancetype)initWithFrame:(CGRect)frame |
| 44 | +{ |
| 45 | + self = [super initWithFrame:frame]; |
| 46 | + if (self) { |
| 47 | + UIBlurEffect *effect = |
| 48 | + [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemChromeMaterial]; |
| 49 | + _blurView = [[UIVisualEffectView alloc] initWithEffect:effect]; |
| 50 | + _gradientMask = [[LinkCodeGradientMaskView alloc] initWithFrame:CGRectZero]; |
| 51 | + _maskSize = CGSizeZero; |
| 52 | + |
| 53 | + self.userInteractionEnabled = NO; |
| 54 | + _blurView.userInteractionEnabled = NO; |
| 55 | + _blurView.maskView = _gradientMask; |
| 56 | + [self addSubview:_blurView]; |
| 57 | + } |
| 58 | + return self; |
| 59 | +} |
| 60 | + |
| 61 | +- (void)layoutSubviews |
| 62 | +{ |
| 63 | + [super layoutSubviews]; |
| 64 | + |
| 65 | + self.blurView.frame = self.bounds; |
| 66 | + if (CGSizeEqualToSize(self.maskSize, self.bounds.size)) { |
| 67 | + return; |
| 68 | + } |
| 69 | + |
| 70 | + self.maskSize = self.bounds.size; |
| 71 | + self.gradientMask.frame = self.blurView.bounds; |
| 72 | + self.blurView.maskView = nil; |
| 73 | + self.blurView.maskView = self.gradientMask; |
| 74 | +} |
| 75 | + |
| 76 | +@end |
| 77 | + |
| 78 | +@interface LinkCodeNavigationBarBackdropViewManager : RCTViewManager |
| 79 | +@end |
| 80 | + |
| 81 | +@implementation LinkCodeNavigationBarBackdropViewManager |
| 82 | + |
| 83 | +RCT_EXPORT_MODULE(LinkCodeNavigationBarBackdrop) |
| 84 | + |
| 85 | ++ (BOOL)requiresMainQueueSetup |
| 86 | +{ |
| 87 | + return YES; |
| 88 | +} |
| 89 | + |
| 90 | +- (UIView *)view |
| 91 | +{ |
| 92 | + return [[LinkCodeNavigationBarBackdropView alloc] initWithFrame:CGRectZero]; |
| 93 | +} |
| 94 | + |
| 95 | +@end |
0 commit comments