react-native-blur/ios/BlurAmount.m
Eli Perkins 71b7e59a62 Refactor BlurView to use modern Objective-C syntax and paradigms
This moves to modern Objective-C practices.

Synthesized properties now use property declarations in a private
category.

UIVisualEffectViews will now only be created once, rather than on each
change of blurType.

BlurAmount uses a class property to track the currently set amount.
2017-04-10 11:19:29 -04:00

55 lines
1.1 KiB
Objective-C

#import "BlurAmount.h"
#import <objc/runtime.h>
@interface UIBlurEffect (Protected)
@property (nonatomic, readonly) id effectSettings;
@property (nonatomic, copy, class) NSNumber *localBlurAmount;
@end
@implementation BlurAmount
static NSNumber *_localBlurAmount = nil;
+ (instancetype)effectWithStyle:(UIBlurEffectStyle)style
{
id result = [super effectWithStyle:style];
object_setClass(result, self);
return result;
}
- (id)effectSettings
{
id settings = [super effectSettings];
[settings setValue:BlurAmount.localBlurAmount forKey:@"blurRadius"];
return settings;
}
- (id)copyWithZone:(NSZone*)zone
{
id result = [super copyWithZone:zone];
object_setClass(result, [self class]);
return result;
}
+ (void)setLocalBlurAmount:(NSNumber *)localBlurAmount {
if (localBlurAmount != _localBlurAmount) {
_localBlurAmount = localBlurAmount;
}
}
+ (NSNumber *)localBlurAmount {
return _localBlurAmount;
}
+ (id)updateBlurAmount:(NSNumber*)blurAmount
{
self.localBlurAmount = blurAmount;
return blurAmount;
}
@end