Skip to content

Commit fd1d745

Browse files
committed
New BlurAmount class, adjusted required propType
1 parent 8380fd4 commit fd1d745

File tree

4 files changed

+62
-10
lines changed

4 files changed

+62
-10
lines changed

ios/BlurAmount.m

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#import <UIKit/UIKit.h>
2+
#import <objc/runtime.h>
3+
4+
@interface UIBlurEffect (Protected)
5+
@property (nonatomic, readonly) id effectSettings;
6+
@end
7+
8+
@interface BlurAmount : UIBlurEffect
9+
@property (nonatomic, copy) NSNumber *blurAmount;
10+
@end
11+
12+
@implementation BlurAmount
13+
14+
NSNumber *localBlurAmount;
15+
16+
+ (instancetype)effectWithStyle:(UIBlurEffectStyle)style
17+
{
18+
id result = [super effectWithStyle:style];
19+
object_setClass(result, self);
20+
21+
return result;
22+
}
23+
24+
- (id)effectSettings
25+
{
26+
id settings = [super effectSettings];
27+
[settings setValue:@localBlurAmount forKey:@"blurRadius"];
28+
return settings;
29+
}
30+
31+
- (id)copyWithZone:(NSZone*)zone
32+
{
33+
id result = [super copyWithZone:zone];
34+
object_setClass(result, [self class]);
35+
return result;
36+
}
37+
38+
+ (id)updateBlurAmount:(NSNumber*)blurAmount
39+
{
40+
localBlurAmount = blurAmount;
41+
return blurAmount;
42+
}
43+
44+
@end

ios/BlurView.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
@interface BlurView : UIView
44

55
@property (nonatomic, copy) NSString *blurType;
6+
@property (nonatomic, copy) NSNumber *blurAmount;
67

7-
@end
8+
@end

ios/BlurView.m

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#import "BlurView.h"
2+
#import "BlurAmount.m"
3+
24

35
@implementation BlurView {
46
UIVisualEffectView *_visualEffectView;
7+
BlurView *blurEffect;
58
}
69

710
- (void)setBlurType:(NSString *)blurType
@@ -10,25 +13,28 @@ - (void)setBlurType:(NSString *)blurType
1013
[_visualEffectView removeFromSuperview];
1114
}
1215

13-
UIBlurEffect *blurEffect;
14-
1516
if ([blurType isEqual: @"xlight"]) {
16-
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
17+
blurEffect = [BlurAmount effectWithStyle:UIBlurEffectStyleExtraLight];
1718
} else if ([blurType isEqual: @"light"]) {
18-
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
19+
blurEffect = [BlurAmount effectWithStyle:UIBlurEffectStyleLight];
1920
} else if ([blurType isEqual: @"dark"]) {
20-
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
21+
blurEffect = [BlurAmount effectWithStyle:UIBlurEffectStyleDark];
2122
} else {
22-
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
23+
blurEffect = [BlurAmount effectWithStyle:UIBlurEffectStyleDark];
2324
}
2425

25-
_visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
2626
}
2727

28-
-(void)layoutSubviews
28+
- (void)setBlurAmount:(NSNumber *)blurAmount
2929
{
30-
[super layoutSubviews];
30+
blurEffect = [BlurAmount updateBlurAmount:blurAmount];
31+
}
3132

33+
34+
- (void)layoutSubviews
35+
{
36+
[super layoutSubviews];
37+
_visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
3238
_visualEffectView.frame = self.bounds;
3339
[self insertSubview:_visualEffectView atIndex:0];
3440
}

src/BlurView.ios.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class BlurView extends Component {
1717

1818
BlurView.propTypes = {
1919
blurType: PropTypes.string,
20+
blurAmount: PropTypes.number,
2021
};
2122

2223
const NativeBlurView = requireNativeComponent('BlurView', BlurView);

0 commit comments

Comments
 (0)