UNPKG

1.76 kBPlain TextView Raw
1// Copyright 2015-present 650 Industries. All rights reserved.
2
3#import <EXBlur/EXBlurView.h>
4
5@implementation EXBlurView
6
7- (void)applyStyle
8{
9 self.clipsToBounds = true;
10 if ([_tint isEqual: @"light"]) {
11 _blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
12 } else if ([_tint isEqual: @"default"]) {
13 _blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
14 } else if ([_tint isEqual: @"dark"]) {
15 _blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
16 }
17
18 __weak typeof(self) weakSelf = self;
19 dispatch_async(dispatch_get_main_queue(), ^{
20 __typeof(self) strongSelf = weakSelf;
21
22 if (strongSelf) {
23 UIVisualEffectView *blockVisualEffectView = strongSelf.visualEffectView;
24
25 if (blockVisualEffectView) {
26 [blockVisualEffectView removeFromSuperview];
27 [blockVisualEffectView setEffect:strongSelf.blurEffect];
28 } else {
29 [strongSelf setVisualEffectView:[[UIVisualEffectView alloc] initWithEffect:strongSelf.blurEffect]];
30 blockVisualEffectView = strongSelf.visualEffectView;
31 [[strongSelf visualEffectView] setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
32 }
33
34 blockVisualEffectView.alpha = [strongSelf.intensity floatValue] / 100.0;
35 blockVisualEffectView.frame = strongSelf.bounds;
36 [strongSelf insertSubview:strongSelf.visualEffectView atIndex:0];
37 }
38 });
39}
40
41- (void)didSetProps:(NSArray<NSString *> *)changedProps {
42 if ([changedProps containsObject:@"tint"] || [changedProps containsObject:@"intensity"]) {
43 [self applyStyle];
44 }
45}
46
47- (void)setTint:(NSString *)tint
48{
49 _tint = tint;
50}
51
52- (void)setIntensity:(NSNumber *)intensity
53{
54 _intensity = intensity;
55}
56
57@end