mirror of
https://github.com/status-im/react-native-blur.git
synced 2025-01-12 09:34:16 +00:00
10858e396b
Also changed VibrancyView to be a subclass of BlurView.
67 lines
1.6 KiB
Objective-C
67 lines
1.6 KiB
Objective-C
#import "BlurView.h"
|
|
#import "BlurEffectWithAmount.h"
|
|
|
|
@interface BlurView ()
|
|
|
|
@end
|
|
|
|
@implementation BlurView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
if (self = [super initWithFrame:frame]) {
|
|
self.blurEffectView = [[UIVisualEffectView alloc] init];
|
|
self.blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
self.blurEffectView.frame = frame;
|
|
|
|
self.blurAmount = @10;
|
|
self.blurType = @"dark";
|
|
[self updateBlurEffect];
|
|
|
|
self.clipsToBounds = true;
|
|
|
|
[self addSubview:self.blurEffectView];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (void)layoutSubviews
|
|
{
|
|
[super layoutSubviews];
|
|
self.blurEffectView.frame = self.bounds;
|
|
}
|
|
|
|
- (void)setBlurType:(NSString *)blurType
|
|
{
|
|
if (blurType && ![self.blurType isEqual:blurType]) {
|
|
_blurType = blurType;
|
|
[self updateBlurEffect];
|
|
}
|
|
}
|
|
|
|
- (void)setBlurAmount:(NSNumber *)blurAmount
|
|
{
|
|
if (blurAmount && ![self.blurAmount isEqualToNumber:blurAmount]) {
|
|
_blurAmount = blurAmount;
|
|
[self updateBlurEffect];
|
|
}
|
|
}
|
|
|
|
|
|
- (UIBlurEffectStyle)blurEffectStyle
|
|
{
|
|
if ([self.blurType isEqual: @"xlight"]) return UIBlurEffectStyleExtraLight;
|
|
if ([self.blurType isEqual: @"light"]) return UIBlurEffectStyleLight;
|
|
if ([self.blurType isEqual: @"dark"]) return UIBlurEffectStyleDark;
|
|
return UIBlurEffectStyleDark;
|
|
}
|
|
|
|
- (void)updateBlurEffect
|
|
{
|
|
UIBlurEffectStyle style = [self blurEffectStyle];
|
|
self.blurEffect = [BlurEffectWithAmount effectWithStyle:style andBlurAmount:self.blurAmount];
|
|
self.blurEffectView.effect = self.blurEffect;
|
|
}
|
|
|
|
@end
|