Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.

Commit 6092467

Browse files
committed
feat: add "style.backgroundBlurRadius" prop to View
The blur only affects siblings (views with the same parent) that are behind the view with "style.backgroundBlurRadius" defined.
1 parent 55f9ee2 commit 6092467

File tree

8 files changed

+68
-1
lines changed

8 files changed

+68
-1
lines changed

@types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,7 @@ export interface NativeMouseEvent {
18011801
*/
18021802
export interface ViewStyle extends FlexStyle, BorderStyle, ShadowStyleIOS, TransformsStyle {
18031803
backfaceVisibility?: "visible" | "hidden";
1804+
backgroundBlurRadius?: number;
18041805
backgroundColor?: string;
18051806
opacity?: number;
18061807
testID?: string;

Libraries/Components/View/ViewStylePropTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var ViewStylePropTypes = {
2323
...ShadowPropTypesIOS,
2424
...TransformPropTypes,
2525
backfaceVisibility: ReactPropTypes.oneOf(['visible', 'hidden']),
26+
backgroundBlurRadius: ReactPropTypes.number,
2627
backgroundColor: ColorPropType,
2728
borderColor: ColorPropType,
2829
borderTopColor: ColorPropType,

React/React.xcodeproj/project.pbxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@
515515
657734901EE8354A00A0E9EA /* RCTInspectorPackagerConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 6577348C1EE8354A00A0E9EA /* RCTInspectorPackagerConnection.h */; };
516516
657734911EE8354A00A0E9EA /* RCTInspectorPackagerConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 6577348D1EE8354A00A0E9EA /* RCTInspectorPackagerConnection.m */; };
517517
68EFE4EE1CF6EB3900A1DE13 /* RCTBundleURLProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 68EFE4ED1CF6EB3900A1DE13 /* RCTBundleURLProvider.m */; };
518+
7026D49623C26AC1003328A8 /* RCTBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 7026D49523C26AC1003328A8 /* RCTBlurFilter.m */; };
518519
702B7FF8221C88AF0027174A /* RCTWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 702B7FF6221C88AF0027174A /* RCTWindow.h */; };
519520
702B7FF9221C88AF0027174A /* RCTWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 702B7FF7221C88AF0027174A /* RCTWindow.m */; };
520521
702B7FFC221C88BB0027174A /* RCTMouseEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 702B7FFA221C88BB0027174A /* RCTMouseEvent.h */; };
@@ -1271,6 +1272,8 @@
12711272
68EFE4EC1CF6EB3000A1DE13 /* RCTBundleURLProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTBundleURLProvider.h; sourceTree = "<group>"; };
12721273
68EFE4ED1CF6EB3900A1DE13 /* RCTBundleURLProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTBundleURLProvider.m; sourceTree = "<group>"; };
12731274
6A15FB0C1BDF663500531DFB /* RCTRootViewInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTRootViewInternal.h; sourceTree = "<group>"; };
1275+
7026D49523C26AC1003328A8 /* RCTBlurFilter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RCTBlurFilter.m; sourceTree = "<group>"; };
1276+
7026D49723C26AD2003328A8 /* RCTBlurFilter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTBlurFilter.h; sourceTree = "<group>"; };
12741277
702B7FF6221C88AF0027174A /* RCTWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTWindow.h; sourceTree = "<group>"; };
12751278
702B7FF7221C88AF0027174A /* RCTWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTWindow.m; sourceTree = "<group>"; };
12761279
702B7FFA221C88BB0027174A /* RCTMouseEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTMouseEvent.h; sourceTree = "<group>"; };
@@ -1693,6 +1696,8 @@
16931696
83F15A171B7CC46900F10295 /* NSView+Private.h */,
16941697
13E067531A70F44B002CDEE1 /* NSView+React.h */,
16951698
13E067541A70F44B002CDEE1 /* NSView+React.m */,
1699+
7026D49523C26AC1003328A8 /* RCTBlurFilter.m */,
1700+
7026D49723C26AD2003328A8 /* RCTBlurFilter.h */,
16961701
);
16971702
path = Views;
16981703
sourceTree = "<group>";
@@ -2586,6 +2591,7 @@
25862591
developmentRegion = English;
25872592
hasScannedForEncodings = 0;
25882593
knownRegions = (
2594+
English,
25892595
en,
25902596
Base,
25912597
);
@@ -2768,6 +2774,7 @@
27682774
83CBBA511A601E3B00E9B192 /* RCTAssert.m in Sources */,
27692775
59EB6DBD1EBD6FC90072A5E7 /* RCTUIManagerObserverCoordinator.mm in Sources */,
27702776
13AF20451AE707F9005F5298 /* RCTSlider.m in Sources */,
2777+
7026D49623C26AC1003328A8 /* RCTBlurFilter.m in Sources */,
27712778
130443A21E3FEAA900D93A67 /* RCTFollyConvert.mm in Sources */,
27722779
58114A501AAE93D500E7D092 /* RCTAsyncLocalStorage.m in Sources */,
27732780
657734851EE834C900A0E9EA /* RCTInspectorDevServerHelper.mm in Sources */,

React/Views/RCTBlurFilter.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#import <CoreImage/CoreImage.h>
2+
3+
@interface RCTBlurFilter : CIFilter
4+
5+
- (instancetype)init NS_DESIGNATED_INITIALIZER;
6+
7+
@property (nonatomic, strong) CIImage *inputImage;
8+
@property (nonatomic, assign) CGFloat inputRadius;
9+
10+
@end

React/Views/RCTBlurFilter.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#import "RCTBlurFilter.h"
2+
3+
@implementation RCTBlurFilter
4+
5+
- (instancetype)init
6+
{
7+
self = [super init];
8+
return self;
9+
}
10+
11+
- (NSArray<NSString *> *)inputKeys
12+
{
13+
return @[@"inputImage", @"inputRadius"];
14+
}
15+
16+
- (CIImage *)outputImage
17+
{
18+
// CIContext *context = [CIContext context];
19+
// CGImageRef cgImage = [context createCGImage:_inputImage fromRect:_inputImage.extent];
20+
CIImage *image = _inputImage; // [CIImage imageWithCGImage:cgImage];
21+
image = [image imageByClampingToExtent];
22+
image = [image imageByApplyingGaussianBlurWithSigma:_inputRadius];
23+
image = [image imageByCroppingToRect:_inputImage.extent];
24+
return image;
25+
}
26+
27+
@end

React/Views/RCTView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122

123123
@property (nonatomic, assign) CATransform3D transform;
124124
@property (nonatomic, copy) NSColor *backgroundColor;
125+
@property (nonatomic, assign) CGFloat backgroundBlurRadius;
125126

126127
@property (nonatomic, copy) RCTDirectEventBlock onDragEnter;
127128
@property (nonatomic, copy) RCTDirectEventBlock onDragLeave;

React/Views/RCTView.m

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
*/
77

88
#import "RCTView.h"
9+
#import <CoreImage/CIFilterBuiltins.h>
910

1011
#import "RCTAutoInsetsProtocol.h"
12+
#import "RCTBlurFilter.h"
1113
#import "RCTBorderDrawing.h"
1214
#import "RCTConvert.h"
1315
#import "RCTLog.h"
@@ -101,6 +103,7 @@ - (NSView *)react_findClipView
101103
@implementation RCTView
102104
{
103105
NSColor *_backgroundColor;
106+
CIFilter *_backgroundBlur;
104107
}
105108

106109
- (instancetype)initWithFrame:(CGRect)frame
@@ -281,7 +284,7 @@ - (NSString *)description
281284
NSString *superDescription = super.description;
282285
NSRange semicolonRange = [superDescription rangeOfString:@";"];
283286
NSString *replacement = [NSString stringWithFormat:@"; reactTag: %@;", self.reactTag];
284-
287+
285288
if ([superDescription length] > 0 && semicolonRange.length > 0) {
286289
return [superDescription stringByReplacingCharactersInRange:semicolonRange withString:replacement];
287290
}
@@ -458,6 +461,22 @@ - (void)setBackgroundColor:(NSColor *)backgroundColor
458461
[self.layer setNeedsDisplay];
459462
}
460463

464+
- (void)setBackgroundBlurRadius:(CGFloat)blurRadius
465+
{
466+
_backgroundBlurRadius = blurRadius;
467+
468+
if (_backgroundBlur == nil) {
469+
_backgroundBlur = [RCTBlurFilter new];
470+
_backgroundBlur.name = @"blur";
471+
472+
[self ensureLayerExists];
473+
self.backgroundFilters = @[_backgroundBlur];
474+
}
475+
476+
[self.layer setValue:@(blurRadius)
477+
forKeyPath:@"backgroundFilters.blur.inputRadius"];
478+
}
479+
461480
#pragma mark - Rendering
462481

463482
- (void)reactSetFrame:(CGRect)frame

React/Views/RCTViewManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ - (RCTShadowView *)shadowView
102102
// RCT_REMAP_VIEW_PROPERTY(onMagicTap, reactAccessibilityElement.onMagicTap, RCTDirectEventBlock)
103103
RCT_REMAP_VIEW_PROPERTY(testID, reactAccessibilityElement.accessibilityIdentifier, NSString)
104104

105+
RCT_EXPORT_VIEW_PROPERTY(backgroundBlurRadius, CGFloat)
105106
RCT_EXPORT_VIEW_PROPERTY(backgroundColor, NSColor)
106107
RCT_REMAP_LAYER_PROPERTY(backfaceVisibility, doubleSided, css_backface_visibility_t)
107108
RCT_EXPORT_LAYER_PROPERTY(opacity, float)

0 commit comments

Comments
 (0)