New BlurAmount class, adjusted required propType
This commit is contained in:
parent
8380fd4b89
commit
fd1d7452fa
|
@ -0,0 +1,44 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import <objc/runtime.h>
|
||||
|
||||
@interface UIBlurEffect (Protected)
|
||||
@property (nonatomic, readonly) id effectSettings;
|
||||
@end
|
||||
|
||||
@interface BlurAmount : UIBlurEffect
|
||||
@property (nonatomic, copy) NSNumber *blurAmount;
|
||||
@end
|
||||
|
||||
@implementation BlurAmount
|
||||
|
||||
NSNumber *localBlurAmount;
|
||||
|
||||
+ (instancetype)effectWithStyle:(UIBlurEffectStyle)style
|
||||
{
|
||||
id result = [super effectWithStyle:style];
|
||||
object_setClass(result, self);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (id)effectSettings
|
||||
{
|
||||
id settings = [super effectSettings];
|
||||
[settings setValue:@localBlurAmount forKey:@"blurRadius"];
|
||||
return settings;
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone*)zone
|
||||
{
|
||||
id result = [super copyWithZone:zone];
|
||||
object_setClass(result, [self class]);
|
||||
return result;
|
||||
}
|
||||
|
||||
+ (id)updateBlurAmount:(NSNumber*)blurAmount
|
||||
{
|
||||
localBlurAmount = blurAmount;
|
||||
return blurAmount;
|
||||
}
|
||||
|
||||
@end
|
|
@ -3,5 +3,6 @@
|
|||
@interface BlurView : UIView
|
||||
|
||||
@property (nonatomic, copy) NSString *blurType;
|
||||
@property (nonatomic, copy) NSNumber *blurAmount;
|
||||
|
||||
@end
|
||||
@end
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
#import "BlurView.h"
|
||||
#import "BlurAmount.m"
|
||||
|
||||
|
||||
@implementation BlurView {
|
||||
UIVisualEffectView *_visualEffectView;
|
||||
BlurView *blurEffect;
|
||||
}
|
||||
|
||||
- (void)setBlurType:(NSString *)blurType
|
||||
|
@ -10,25 +13,28 @@
|
|||
[_visualEffectView removeFromSuperview];
|
||||
}
|
||||
|
||||
UIBlurEffect *blurEffect;
|
||||
|
||||
if ([blurType isEqual: @"xlight"]) {
|
||||
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
|
||||
blurEffect = [BlurAmount effectWithStyle:UIBlurEffectStyleExtraLight];
|
||||
} else if ([blurType isEqual: @"light"]) {
|
||||
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
|
||||
blurEffect = [BlurAmount effectWithStyle:UIBlurEffectStyleLight];
|
||||
} else if ([blurType isEqual: @"dark"]) {
|
||||
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
|
||||
blurEffect = [BlurAmount effectWithStyle:UIBlurEffectStyleDark];
|
||||
} else {
|
||||
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
|
||||
blurEffect = [BlurAmount effectWithStyle:UIBlurEffectStyleDark];
|
||||
}
|
||||
|
||||
_visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
|
||||
}
|
||||
|
||||
-(void)layoutSubviews
|
||||
- (void)setBlurAmount:(NSNumber *)blurAmount
|
||||
{
|
||||
blurEffect = [BlurAmount updateBlurAmount:blurAmount];
|
||||
}
|
||||
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
[super layoutSubviews];
|
||||
|
||||
_visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
|
||||
_visualEffectView.frame = self.bounds;
|
||||
[self insertSubview:_visualEffectView atIndex:0];
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ class BlurView extends Component {
|
|||
|
||||
BlurView.propTypes = {
|
||||
blurType: PropTypes.string,
|
||||
blurAmount: PropTypes.number,
|
||||
};
|
||||
|
||||
const NativeBlurView = requireNativeComponent('BlurView', BlurView);
|
||||
|
|
Loading…
Reference in New Issue