@sbaiahmed1/react-native-blur 0.2.0 → 0.3.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +271 -16
  2. package/ReactNativeBlur.podspec +2 -1
  3. package/android/app/build/generated/source/codegen/java/com/facebook/react/viewmanagers/ReactNativeBlurViewManagerDelegate.java +38 -0
  4. package/android/app/build/generated/source/codegen/java/com/facebook/react/viewmanagers/ReactNativeBlurViewManagerInterface.java +20 -0
  5. package/android/app/build/generated/source/codegen/java/com/facebook/react/viewmanagers/ReactNativeGlassViewManagerDelegate.java +38 -0
  6. package/android/app/build/generated/source/codegen/java/com/facebook/react/viewmanagers/ReactNativeGlassViewManagerInterface.java +20 -0
  7. package/android/app/build/generated/source/codegen/jni/CMakeLists.txt +36 -0
  8. package/android/app/build/generated/source/codegen/jni/ReactNativeBlurViewSpec-generated.cpp +22 -0
  9. package/android/app/build/generated/source/codegen/jni/ReactNativeBlurViewSpec.h +24 -0
  10. package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/ComponentDescriptors.cpp +23 -0
  11. package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/ComponentDescriptors.h +25 -0
  12. package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/EventEmitters.cpp +17 -0
  13. package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/EventEmitters.h +30 -0
  14. package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/Props.cpp +36 -0
  15. package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/Props.h +91 -0
  16. package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/ReactNativeBlurViewSpecJSI-generated.cpp +17 -0
  17. package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/ReactNativeBlurViewSpecJSI.h +19 -0
  18. package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/ShadowNodes.cpp +18 -0
  19. package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/ShadowNodes.h +43 -0
  20. package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/States.cpp +16 -0
  21. package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/States.h +41 -0
  22. package/android/src/main/java/com/sbaiahmed1/reactnativeblur/ReactNativeBlurView.kt +164 -39
  23. package/android/src/main/java/com/sbaiahmed1/reactnativeblur/ReactNativeBlurViewManager.kt +20 -0
  24. package/ios/ReactNativeBlurView.mm +190 -238
  25. package/ios/ReactNativeBlurView.swift +309 -0
  26. package/ios/ReactNativeBlurViewManager.h +5 -0
  27. package/ios/ReactNativeBlurViewManager.m +165 -0
  28. package/lib/module/BlurView.js +14 -2
  29. package/lib/module/BlurView.js.map +1 -1
  30. package/lib/module/ReactNativeBlurViewNativeComponent.ts +9 -3
  31. package/lib/typescript/src/BlurView.d.ts +30 -1
  32. package/lib/typescript/src/BlurView.d.ts.map +1 -1
  33. package/lib/typescript/src/ReactNativeBlurViewNativeComponent.d.ts +8 -3
  34. package/lib/typescript/src/ReactNativeBlurViewNativeComponent.d.ts.map +1 -1
  35. package/package.json +2 -2
  36. package/src/BlurView.tsx +48 -3
  37. package/src/ReactNativeBlurViewNativeComponent.ts +9 -3
  38. package/ios/ReactNativeBlurViewManager.mm +0 -23
@@ -6,98 +6,169 @@
6
6
  #import <react/renderer/components/ReactNativeBlurViewSpec/RCTComponentViewHelpers.h>
7
7
 
8
8
  #import "RCTFabricComponentsPlugins.h"
9
+ #import "ReactNativeBlur-Swift.h" // Swift bridging header
9
10
 
10
11
  using namespace facebook::react;
11
12
 
12
13
  @interface ReactNativeBlurView () <RCTReactNativeBlurViewViewProtocol>
13
-
14
14
  @end
15
15
 
16
16
  @implementation ReactNativeBlurView {
17
- UIVisualEffectView * _blurView;
18
- UIView * _fallbackView;
19
- }
20
-
21
- + (ComponentDescriptorProvider)componentDescriptorProvider
22
- {
23
- return concreteComponentDescriptorProvider<ReactNativeBlurViewComponentDescriptor>();
17
+ AdvancedBlurView *_advancedBlurView;
18
+ Props::Shared _props;
24
19
  }
25
20
 
26
- - (instancetype)initWithFrame:(CGRect)frame
27
- {
28
- if (self = [super initWithFrame:frame]) {
29
- static const auto defaultProps = std::make_shared<const ReactNativeBlurViewProps>();
30
- _props = defaultProps;
31
-
32
- [self setupBlurView];
21
+ + (UIColor *)colorFromString:(NSString *)colorString {
22
+ // Input validation
23
+ if (!colorString || [colorString isEqualToString:@""] || colorString.length == 0) {
24
+ return [UIColor clearColor]; // Default color
33
25
  }
34
26
 
35
- return self;
36
- }
37
-
38
- - (void)setupBlurView
39
- {
40
- // Create blur effect
41
- UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
42
- _blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
43
- _blurView.frame = self.bounds;
44
- _blurView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
27
+ // Prevent excessively long strings that could cause performance issues
28
+ if (colorString.length > 50) {
29
+ NSLog(@"[ReactNativeBlurView] Warning: Color string too long, using default clear color");
30
+ return [UIColor clearColor];
31
+ }
32
+
33
+ // Handle common color names
34
+ NSDictionary *colorMap = @{
35
+ @"red": [UIColor redColor],
36
+ @"blue": [UIColor blueColor],
37
+ @"green": [UIColor greenColor],
38
+ @"yellow": [UIColor yellowColor],
39
+ @"orange": [UIColor orangeColor],
40
+ @"purple": [UIColor purpleColor],
41
+ @"black": [UIColor blackColor],
42
+ @"white": [UIColor whiteColor],
43
+ @"gray": [UIColor grayColor],
44
+ @"clear": [UIColor clearColor],
45
+ @"transparent": [UIColor clearColor]
46
+ };
47
+
48
+ UIColor *namedColor = colorMap[colorString.lowercaseString];
49
+ if (namedColor) {
50
+ return namedColor;
51
+ }
45
52
 
46
- // Create fallback view for reduced transparency
47
- _fallbackView = [[UIView alloc] init];
48
- _fallbackView.frame = self.bounds;
49
- _fallbackView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
50
- _fallbackView.backgroundColor = [UIColor colorWithWhite:0.8 alpha:0.8];
51
- _fallbackView.hidden = YES;
53
+ // Handle hex colors (e.g., "#FF0000", "FF0000", "#FF00FF00", "FF00FF00")
54
+ NSString *hexString = colorString;
55
+ if ([hexString hasPrefix:@"#"]) {
56
+ if (hexString.length < 2) {
57
+ NSLog(@"[ReactNativeBlurView] Warning: Invalid hex color format '%@', using default clear color", colorString);
58
+ return [UIColor clearColor];
59
+ }
60
+ hexString = [hexString substringFromIndex:1];
61
+ }
52
62
 
53
- // Insert blur views at index 0 to avoid interfering with React's child view management
54
- [self insertSubview:_blurView atIndex:0];
55
- [self insertSubview:_fallbackView atIndex:0];
63
+ // Validate hex string contains only valid hex characters
64
+ NSCharacterSet *hexCharacterSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789ABCDEFabcdef"];
65
+ NSCharacterSet *invalidCharacters = [hexCharacterSet invertedSet];
66
+ if ([hexString rangeOfCharacterFromSet:invalidCharacters].location != NSNotFound) {
67
+ NSLog(@"[ReactNativeBlurView] Warning: Invalid hex color format '%@', contains non-hex characters", colorString);
68
+ return [UIColor clearColor];
69
+ }
56
70
 
57
- // Check for reduced transparency
58
- [self updateForReducedTransparency];
71
+ // Handle 6-character hex (RGB)
72
+ if (hexString.length == 6) {
73
+ unsigned int hexValue;
74
+ NSScanner *scanner = [NSScanner scannerWithString:hexString];
75
+ if ([scanner scanHexInt:&hexValue] && [scanner isAtEnd]) {
76
+ return [UIColor colorWithRed:((hexValue & 0xFF0000) >> 16) / 255.0
77
+ green:((hexValue & 0x00FF00) >> 8) / 255.0
78
+ blue:(hexValue & 0x0000FF) / 255.0
79
+ alpha:1.0];
80
+ }
81
+ }
82
+ // Handle 8-character hex (RGBA)
83
+ else if (hexString.length == 8) {
84
+ unsigned long long hexValue;
85
+ NSScanner *scanner = [NSScanner scannerWithString:hexString];
86
+ if ([scanner scanHexLongLong:&hexValue] && [scanner isAtEnd]) {
87
+ return [UIColor colorWithRed:((hexValue & 0xFF000000) >> 24) / 255.0
88
+ green:((hexValue & 0x00FF0000) >> 16) / 255.0
89
+ blue:((hexValue & 0x0000FF00) >> 8) / 255.0
90
+ alpha:(hexValue & 0x000000FF) / 255.0];
91
+ }
92
+ }
93
+ // Handle 3-character hex (RGB shorthand)
94
+ else if (hexString.length == 3) {
95
+ unsigned int hexValue;
96
+ NSScanner *scanner = [NSScanner scannerWithString:hexString];
97
+ if ([scanner scanHexInt:&hexValue] && [scanner isAtEnd]) {
98
+ // Expand 3-digit hex to 6-digit (e.g., "F0A" -> "FF00AA")
99
+ unsigned int r = (hexValue & 0xF00) >> 8;
100
+ unsigned int g = (hexValue & 0x0F0) >> 4;
101
+ unsigned int b = (hexValue & 0x00F);
102
+
103
+ return [UIColor colorWithRed:(r | (r << 4)) / 255.0
104
+ green:(g | (g << 4)) / 255.0
105
+ blue:(b | (b << 4)) / 255.0
106
+ alpha:1.0];
107
+ }
108
+ }
109
+ else {
110
+ NSLog(@"[ReactNativeBlurView] Warning: Unsupported hex color length (%lu) for '%@', expected 3, 6, or 8 characters",
111
+ (unsigned long)hexString.length, colorString);
112
+ }
59
113
 
60
- // Listen for accessibility changes
61
- [[NSNotificationCenter defaultCenter] addObserver:self
62
- selector:@selector(updateForReducedTransparency)
63
- name:UIAccessibilityReduceTransparencyStatusDidChangeNotification
64
- object:nil];
114
+ NSLog(@"[ReactNativeBlurView] Warning: Could not parse color '%@', using default clear color", colorString);
115
+ return [UIColor clearColor]; // Fallback to clear
65
116
  }
66
117
 
67
- - (void)updateForReducedTransparency
118
+
119
+
120
+ + (ComponentDescriptorProvider)componentDescriptorProvider
68
121
  {
69
- BOOL reduceTransparency = UIAccessibilityIsReduceTransparencyEnabled();
70
- _blurView.hidden = reduceTransparency;
71
- _fallbackView.hidden = !reduceTransparency;
122
+ return concreteComponentDescriptorProvider<ReactNativeBlurViewComponentDescriptor>();
72
123
  }
73
124
 
74
- - (UIBlurEffectStyle)blurEffectStyleFromString:(NSString *)blurType
125
+ - (instancetype)initWithFrame:(CGRect)frame
75
126
  {
76
- if ([blurType isEqualToString:@"xlight"]) {
77
- return UIBlurEffectStyleExtraLight;
78
- } else if ([blurType isEqualToString:@"light"]) {
79
- return UIBlurEffectStyleLight;
80
- } else if ([blurType isEqualToString:@"dark"]) {
81
- return UIBlurEffectStyleDark;
82
- } else if ([blurType isEqualToString:@"extraDark"]) {
83
- return UIBlurEffectStyleSystemThickMaterialDark;
84
- } else if ([blurType isEqualToString:@"regular"]) {
85
- return UIBlurEffectStyleRegular;
86
- } else if ([blurType isEqualToString:@"prominent"]) {
87
- return UIBlurEffectStyleProminent;
88
- } else if ([blurType isEqualToString:@"systemUltraThinMaterial"]) {
89
- return UIBlurEffectStyleSystemUltraThinMaterial;
90
- } else if ([blurType isEqualToString:@"systemThinMaterial"]) {
91
- return UIBlurEffectStyleSystemThinMaterial;
92
- } else if ([blurType isEqualToString:@"systemMaterial"]) {
93
- return UIBlurEffectStyleSystemMaterial;
94
- } else if ([blurType isEqualToString:@"systemThickMaterial"]) {
95
- return UIBlurEffectStyleSystemThickMaterial;
96
- } else if ([blurType isEqualToString:@"systemChromeMaterial"]) {
97
- return UIBlurEffectStyleSystemChromeMaterial;
127
+ if (self = [super initWithFrame:frame]) {
128
+ static const auto defaultProps = std::make_shared<const ReactNativeBlurViewProps>();
129
+ _props = defaultProps;
130
+
131
+ const auto &bvProps = *std::static_pointer_cast<const ReactNativeBlurViewProps>(defaultProps);
132
+
133
+ _advancedBlurView = [ReactNativeBlurViewHelper createBlurViewWithFrame:frame];
134
+
135
+ // Set initial glassTintColor from default props
136
+ NSString *defaultGlassTintColorString = [[NSString alloc] initWithUTF8String:bvProps.glassTintColor.c_str()];
137
+ UIColor *defaultGlassTintColor = [ReactNativeBlurView colorFromString:defaultGlassTintColorString];
138
+ [ReactNativeBlurViewHelper updateBlurView:_advancedBlurView withGlassTintColor:defaultGlassTintColor];
139
+
140
+ // Set initial glassOpacity from default props
141
+ [ReactNativeBlurViewHelper updateBlurView:_advancedBlurView withGlassOpacity:bvProps.glassOpacity];
142
+
143
+ // Set initial blurAmount from default props
144
+ [ReactNativeBlurViewHelper updateBlurView:_advancedBlurView withBlurAmount:bvProps.blurAmount];
145
+
146
+ // Set initial blurType from default props
147
+ if (bvProps.blurType != facebook::react::ReactNativeBlurViewBlurType::Xlight) {
148
+ NSString *blurTypeString = [[NSString alloc] initWithUTF8String:toString(bvProps.blurType).c_str()];
149
+ [ReactNativeBlurViewHelper updateBlurView:_advancedBlurView withBlurType:blurTypeString];
150
+ }
151
+
152
+ // Set initial glassType from default props
153
+ if (bvProps.glassType != facebook::react::ReactNativeBlurViewGlassType::Clear) {
154
+ NSString *glassTypeString = [[NSString alloc] initWithUTF8String:toString(bvProps.glassType).c_str()];
155
+ [ReactNativeBlurViewHelper updateBlurView:_advancedBlurView withGlassType:glassTypeString];
156
+ }
157
+
158
+ // Set initial type from default props
159
+ NSString *blurTypeString = [[NSString alloc] initWithUTF8String:toString(bvProps.type).c_str()];
160
+ [ReactNativeBlurViewHelper updateBlurView:_advancedBlurView withType:blurTypeString];
161
+
162
+ // Set initial reducedTransparencyFallbackColor from default props
163
+ if (!bvProps.reducedTransparencyFallbackColor.empty()) {
164
+ NSString *fallbackColorString = [[NSString alloc] initWithUTF8String:bvProps.reducedTransparencyFallbackColor.c_str()];
165
+ UIColor *fallbackColor = [ReactNativeBlurView colorFromString:fallbackColorString];
166
+ [ReactNativeBlurViewHelper updateBlurView:_advancedBlurView withReducedTransparencyFallbackColor:fallbackColor];
167
+ }
168
+
169
+ [self addSubview:_advancedBlurView];
98
170
  }
99
-
100
- return UIBlurEffectStyleLight; // Default
171
+ return self;
101
172
  }
102
173
 
103
174
  - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
@@ -105,106 +176,71 @@ using namespace facebook::react;
105
176
  const auto &oldViewProps = *std::static_pointer_cast<ReactNativeBlurViewProps const>(_props);
106
177
  const auto &newViewProps = *std::static_pointer_cast<ReactNativeBlurViewProps const>(props);
107
178
 
108
- // Update blur type
109
- if (oldViewProps.blurType != newViewProps.blurType) {
110
- std::string blurTypeStr = toString(newViewProps.blurType);
111
- NSString *blurTypeString = [[NSString alloc] initWithUTF8String:blurTypeStr.c_str()];
112
- UIBlurEffectStyle blurStyle = [self blurEffectStyleFromString:blurTypeString];
113
- UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:blurStyle];
114
- _blurView.effect = blurEffect;
179
+ // Update glassTintColor if it has changed
180
+ if (oldViewProps.glassTintColor != newViewProps.glassTintColor) {
181
+ if (!newViewProps.glassTintColor.empty()) {
182
+ NSString *glassTintColorString = [[NSString alloc] initWithUTF8String:newViewProps.glassTintColor.c_str()];
183
+ UIColor *newGlassTintColor = [ReactNativeBlurView colorFromString:glassTintColorString];
184
+ [ReactNativeBlurViewHelper updateBlurView:_advancedBlurView withGlassTintColor:newGlassTintColor];
185
+ }
186
+ }
187
+
188
+ // Update glassOpacity if it has changed
189
+ if (oldViewProps.glassOpacity != newViewProps.glassOpacity) {
190
+ [ReactNativeBlurViewHelper updateBlurView:_advancedBlurView withGlassOpacity:newViewProps.glassOpacity];
115
191
  }
116
192
 
117
- // Update blur amount (create custom blur effect)
193
+ // Update blurAmount if it has changed
118
194
  if (oldViewProps.blurAmount != newViewProps.blurAmount) {
119
- [self updateBlurEffectWithAmount:newViewProps.blurAmount];
195
+ [ReactNativeBlurViewHelper updateBlurView:_advancedBlurView withBlurAmount:newViewProps.blurAmount];
120
196
  }
121
197
 
122
- // Update fallback color
123
- if (oldViewProps.reducedTransparencyFallbackColor != newViewProps.reducedTransparencyFallbackColor) {
124
- if (!newViewProps.reducedTransparencyFallbackColor.empty()) {
125
- NSString *colorString = [[NSString alloc] initWithUTF8String:newViewProps.reducedTransparencyFallbackColor.c_str()];
126
- _fallbackView.backgroundColor = [self hexStringToColor:colorString];
198
+ // Update blurType if it has changed
199
+ if (oldViewProps.blurType != newViewProps.blurType) {
200
+ if (newViewProps.blurType != facebook::react::ReactNativeBlurViewBlurType::Xlight) {
201
+ NSString *blurTypeString = [[NSString alloc] initWithUTF8String:toString(newViewProps.blurType).c_str()];
202
+ [ReactNativeBlurViewHelper updateBlurView:_advancedBlurView withBlurType:blurTypeString];
127
203
  }
128
204
  }
129
205
 
130
- [super updateProps:props oldProps:oldProps];
131
- }
132
-
133
- - (void)updateBlurEffectWithAmount:(double)amount
134
- {
135
- // For amounts 0-30: Use alpha blending with UIVisualEffectView
136
- // For amounts 30+: Create custom blur effect with Core Image
137
-
138
- if (amount <= 30.0) {
139
- // Use standard UIVisualEffectView with alpha
140
- CGFloat alpha = amount / 30.0; // Scale to 0-1 for low amounts
141
- _blurView.alpha = alpha;
142
-
143
- // Remove any custom blur layer
144
- [self.layer.sublayers enumerateObjectsUsingBlock:^(CALayer *layer, NSUInteger idx, BOOL *stop) {
145
- if ([layer.name isEqualToString:@"customBlur"]) {
146
- [layer removeFromSuperlayer];
147
- }
148
- }];
149
- } else {
150
- // Use full opacity for the base blur
151
- _blurView.alpha = 1.0;
152
-
153
- // Add custom blur overlay for enhanced effect
154
- [self addCustomBlurOverlayWithIntensity:(amount - 30.0) / 70.0]; // Scale 30-100 to 0-1
155
- }
156
- }
157
-
158
- - (void)addCustomBlurOverlayWithIntensity:(CGFloat)intensity
159
- {
160
- // Remove existing custom blur layer
161
- [self.layer.sublayers enumerateObjectsUsingBlock:^(CALayer *layer, NSUInteger idx, BOOL *stop) {
162
- if ([layer.name isEqualToString:@"customBlur"]) {
163
- [layer removeFromSuperlayer];
206
+ // Update glassType if it has changed
207
+ if (oldViewProps.glassType != newViewProps.glassType) {
208
+ if (newViewProps.glassType != facebook::react::ReactNativeBlurViewGlassType::Clear) {
209
+ NSString *glassTypeString = [[NSString alloc] initWithUTF8String:toString(newViewProps.glassType).c_str()];
210
+ [ReactNativeBlurViewHelper updateBlurView:_advancedBlurView withGlassType:glassTypeString];
164
211
  }
165
- }];
166
-
167
- // Create a semi-transparent overlay that simulates additional blur
168
- CALayer *blurOverlay = [CALayer layer];
169
- blurOverlay.name = @"customBlur";
170
- blurOverlay.frame = self.bounds;
171
-
172
- // Create a gradient effect that simulates depth
173
- CAGradientLayer *gradientLayer = [CAGradientLayer layer];
174
- gradientLayer.frame = self.bounds;
212
+ }
175
213
 
176
- // Adjust colors based on blur type
177
- UIColor *overlayColor;
178
- if ([self.blurType isEqualToString:@"dark"] || [self.blurType isEqualToString:@"extraDark"]) {
179
- overlayColor = [UIColor colorWithWhite:0.0 alpha:intensity * 0.3];
180
- } else {
181
- overlayColor = [UIColor colorWithWhite:1.0 alpha:intensity * 0.2];
214
+ // Update type if it has changed
215
+ if (oldViewProps.type != newViewProps.type) {
216
+ NSString *blurTypeString = [[NSString alloc] initWithUTF8String:toString(newViewProps.type).c_str()];
217
+ [ReactNativeBlurViewHelper updateBlurView:_advancedBlurView withType:blurTypeString];
182
218
  }
183
219
 
184
- gradientLayer.colors = @[
185
- (id)[overlayColor colorWithAlphaComponent:intensity * 0.1].CGColor,
186
- (id)[overlayColor colorWithAlphaComponent:intensity * 0.3].CGColor,
187
- (id)[overlayColor colorWithAlphaComponent:intensity * 0.1].CGColor
188
- ];
220
+ // Update reducedTransparencyFallbackColor if it has changed
221
+ if (oldViewProps.reducedTransparencyFallbackColor != newViewProps.reducedTransparencyFallbackColor) {
222
+ if (!newViewProps.reducedTransparencyFallbackColor.empty()) {
223
+ NSString *fallbackColorString = [[NSString alloc] initWithUTF8String:newViewProps.reducedTransparencyFallbackColor.c_str()];
224
+ UIColor *fallbackColor = [ReactNativeBlurView colorFromString:fallbackColorString];
225
+ [ReactNativeBlurViewHelper updateBlurView:_advancedBlurView withReducedTransparencyFallbackColor:fallbackColor];
226
+ }
227
+ }
189
228
 
190
- gradientLayer.locations = @[@0.0, @0.5, @1.0];
229
+ // Store the new props
230
+ _props = props;
191
231
 
192
- [blurOverlay addSublayer:gradientLayer];
193
- [self.layer addSublayer:blurOverlay];
232
+ [super updateProps:props oldProps:oldProps];
194
233
  }
195
234
 
196
- - (NSString *)blurType
235
+ - (void)layoutSubviews
197
236
  {
198
- const auto &props = *std::static_pointer_cast<ReactNativeBlurViewProps const>(_props);
199
- std::string blurTypeStr = toString(props.blurType);
200
- return [[NSString alloc] initWithUTF8String:blurTypeStr.c_str()];
237
+ [super layoutSubviews];
238
+ _advancedBlurView.frame = self.bounds;
201
239
  }
202
240
 
203
241
  - (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
204
242
  {
205
- // Always insert React subviews after the blur views (which are at indices 0 and 1)
206
- NSInteger adjustedIndex = index + 2;
207
- [self insertSubview:childComponentView atIndex:adjustedIndex];
243
+ [_advancedBlurView addSubview:childComponentView];
208
244
  }
209
245
 
210
246
  - (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
@@ -212,100 +248,16 @@ using namespace facebook::react;
212
248
  [childComponentView removeFromSuperview];
213
249
  }
214
250
 
215
- - (void)layoutSubviews
216
- {
217
- [super layoutSubviews];
218
-
219
- // Ensure blur view and fallback view cover the entire bounds
220
- if (_blurView) {
221
- _blurView.frame = self.bounds;
222
- }
223
- if (_fallbackView) {
224
- _fallbackView.frame = self.bounds;
225
- }
226
-
227
- // Keep blur views at the back without using sendSubviewToBack to avoid index conflicts
228
- if (_blurView && _blurView.superview == self) {
229
- // Move to index 0 if not already there
230
- NSInteger currentIndex = [self.subviews indexOfObject:_blurView];
231
- if (currentIndex != 0 && currentIndex != NSNotFound) {
232
- [_blurView removeFromSuperview];
233
- [self insertSubview:_blurView atIndex:0];
234
- }
235
- }
236
- if (_fallbackView && _fallbackView.superview == self) {
237
- // Move to index 1 if not already there (after blur view)
238
- NSInteger currentIndex = [self.subviews indexOfObject:_fallbackView];
239
- if (currentIndex != 1 && currentIndex != NSNotFound) {
240
- [_fallbackView removeFromSuperview];
241
- [self insertSubview:_fallbackView atIndex:1];
242
- }
243
- }
244
- }
245
-
246
251
  - (void)dealloc
247
252
  {
248
- [[NSNotificationCenter defaultCenter] removeObserver:self];
249
-
250
- // Clean up blur views
251
- if (_blurView) {
252
- [_blurView removeFromSuperview];
253
- _blurView = nil;
254
- }
255
- if (_fallbackView) {
256
- [_fallbackView removeFromSuperview];
257
- _fallbackView = nil;
258
- }
259
- }
260
-
261
- Class<RCTComponentViewProtocol> ReactNativeBlurViewCls(void)
262
- {
263
- return ReactNativeBlurView.class;
264
- }
265
-
266
- // Legacy compatibility methods for Old Architecture
267
- - (void)setBlurAmount:(NSNumber *)blurAmount
268
- {
269
- if (blurAmount) {
270
- [self updateBlurEffectWithAmount:[blurAmount doubleValue]];
271
- }
253
+ [_advancedBlurView removeFromSuperview];
254
+ _advancedBlurView = nil;
272
255
  }
273
256
 
274
- - (void)setBlurType:(NSString *)blurType
275
- {
276
- if (blurType) {
277
- UIBlurEffectStyle blurStyle = [self blurEffectStyleFromString:blurType];
278
- UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:blurStyle];
279
- _blurView.effect = blurEffect;
280
- }
281
- }
282
-
283
- - (void)setReducedTransparencyFallbackColor:(NSString *)color
284
- {
285
- if (color && color.length > 0) {
286
- _fallbackView.backgroundColor = [self hexStringToColor:color];
287
- }
288
- }
257
+ @end
289
258
 
290
- - (UIColor *)hexStringToColor:(NSString *)stringToConvert
259
+ Class<RCTComponentViewProtocol> BlurryViewCls(void)
291
260
  {
292
- if (!stringToConvert || stringToConvert.length == 0) {
293
- return [UIColor clearColor];
294
- }
295
-
296
- NSString *noHashString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""];
297
- NSScanner *stringScanner = [NSScanner scannerWithString:noHashString];
298
-
299
- unsigned hex;
300
- if (![stringScanner scanHexInt:&hex]) {
301
- return [UIColor clearColor];
302
- }
303
-
304
- int r = (hex >> 16) & 0xFF;
305
- int g = (hex >> 8) & 0xFF;
306
- int b = (hex) & 0xFF;
307
-
308
- return [UIColor colorWithRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f];
261
+ return ReactNativeBlurView.class;
309
262
  }
310
263
 
311
- @end