react-native-blur/ios/BlurView.m

41 lines
1.2 KiB
Mathematica
Raw Normal View History

#import "BlurView.h"
2016-12-21 11:31:08 +00:00
#import "BlurAmount.h"
@implementation BlurView {
UIVisualEffectView *_visualEffectView;
UIBlurEffect * blurEffect;
}
- (void)setBlurType:(NSString *)blurType
{
if (_visualEffectView) {
[_visualEffectView removeFromSuperview];
}
2016-12-21 11:31:08 +00:00
self.clipsToBounds = true;
if ([blurType isEqual: @"xlight"]) {
blurEffect = [BlurAmount effectWithStyle:UIBlurEffectStyleExtraLight];
} else if ([blurType isEqual: @"light"]) {
blurEffect = [BlurAmount effectWithStyle:UIBlurEffectStyleLight];
} else if ([blurType isEqual: @"dark"]) {
blurEffect = [BlurAmount effectWithStyle:UIBlurEffectStyleDark];
} else {
blurEffect = [BlurAmount effectWithStyle:UIBlurEffectStyleDark];
}
dispatch_async(dispatch_get_main_queue(), ^{
_visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
_visualEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_visualEffectView.frame = self.bounds;
[self insertSubview:_visualEffectView atIndex:0];
});
}
- (void)setBlurAmount:(NSNumber *)blurAmount
{
[BlurAmount updateBlurAmount:blurAmount];
}
@end