Skip to content

Commit bb49e27

Browse files
committed
Add support for blurEffect (#3)
1 parent 896c2c6 commit bb49e27

File tree

6 files changed

+129
-1
lines changed

6 files changed

+129
-1
lines changed

apps/src/tests/TestBottomTabs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function LayoutView(props: PropsWithChildren<ViewProps>) {
1616
function App() {
1717
return (
1818
<View style={{ flex: 1 }}>
19-
<BottomTabs tabBarBackgroundColor={'yellow'}>
19+
<BottomTabs tabBarBackgroundColor={'rgba(255, 255, 0, 0.5)'} tabBarBlurEffect={'dark'}>
2020
<BottomTabsScreen>
2121
<LayoutView style={{ backgroundColor: 'lightgreen' }}>
2222
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>

ios/bottom-tabs/RNSBottomTabsHostComponentView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#import <React/RCTViewComponentView.h>
22
#import "RNSBottomTabsHostComponentViewManager.h"
3+
#import "RNSEnums.h"
34
#import "RNSScreenContainer.h"
45

56
NS_ASSUME_NONNULL_BEGIN
@@ -18,6 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
1819
// TODO: Extract all props to single struct / use codegened struct
1920

2021
@property (nonatomic, strong, readonly, nullable) UIColor *tabBarBackgroundColor;
22+
@property (nonatomic, readonly) RNSBlurEffectStyle tabBarBlurEffect;
2123

2224
@end
2325

ios/bottom-tabs/RNSBottomTabsHostComponentView.mm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#import <react/renderer/components/rnscreens/Props.h>
77
#import <react/renderer/components/rnscreens/RCTComponentViewHelpers.h>
88
#import "RNSBottomTabsScreenComponentView.h"
9+
#import "RNSConversions.h"
10+
#import "RNSConvert.h"
911
#import "RNSDefines.h"
1012
#import "RNSTabBarController.h"
1113

@@ -47,7 +49,16 @@ - (void)initState
4749
- (nullable UITabBarAppearance *)makeTabBarAppearance
4850
{
4951
UITabBarAppearance *newAppearance = [[UITabBarAppearance alloc] init];
52+
5053
newAppearance.backgroundColor = _tabBarBackgroundColor;
54+
55+
if (_tabBarBlurEffect != RNSBlurEffectStyleNone) {
56+
newAppearance.backgroundEffect =
57+
[UIBlurEffect effectWithStyle:[RNSConvert tryConvertRNSBlurEffectStyleToUIBlurEffectStyle:_tabBarBlurEffect]];
58+
} else {
59+
newAppearance.backgroundEffect = nil;
60+
}
61+
5162
return newAppearance;
5263
}
5364

@@ -142,6 +153,12 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props
142153
_tabBarBackgroundColor = RCTUIColorFromSharedColor(newComponentProps.tabBarBackgroundColor);
143154
}
144155

156+
if (newComponentProps.tabBarBlurEffect != oldComponentProps.tabBarBlurEffect) {
157+
_needsTabBarAppearanceUpdate = YES;
158+
_tabBarBlurEffect =
159+
rnscreens::conversion::RNSBlurEffectStyleFromRNSBottomTabsTabBarBlurEffect(newComponentProps.tabBarBlurEffect);
160+
}
161+
145162
// Super call updates _props pointer. We should NOT update it before calling super.
146163
[super updateProps:props oldProps:oldProps];
147164
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#import "RNSConversions.h"
2+
3+
namespace rnscreens::conversion {
4+
5+
RNSBlurEffectStyle RNSBlurEffectStyleFromRNSBottomTabsTabBarBlurEffect(
6+
facebook::react::RNSBottomTabsTabBarBlurEffect blurEffect)
7+
{
8+
using enum facebook::react::RNSBottomTabsTabBarBlurEffect;
9+
#if !TARGET_OS_TV
10+
switch (blurEffect) {
11+
case None:
12+
return RNSBlurEffectStyleNone;
13+
case ExtraLight:
14+
return RNSBlurEffectStyleExtraLight;
15+
case Light:
16+
return RNSBlurEffectStyleLight;
17+
case Dark:
18+
return RNSBlurEffectStyleDark;
19+
case Regular:
20+
return RNSBlurEffectStyleRegular;
21+
case Prominent:
22+
return RNSBlurEffectStyleProminent;
23+
case SystemUltraThinMaterial:
24+
return RNSBlurEffectStyleSystemUltraThinMaterial;
25+
case SystemThinMaterial:
26+
return RNSBlurEffectStyleSystemThinMaterial;
27+
case SystemMaterial:
28+
return RNSBlurEffectStyleSystemMaterial;
29+
case SystemThickMaterial:
30+
return RNSBlurEffectStyleSystemThickMaterial;
31+
case SystemChromeMaterial:
32+
return RNSBlurEffectStyleSystemChromeMaterial;
33+
case SystemUltraThinMaterialLight:
34+
return RNSBlurEffectStyleSystemUltraThinMaterialLight;
35+
case SystemThinMaterialLight:
36+
return RNSBlurEffectStyleSystemThinMaterialLight;
37+
case SystemMaterialLight:
38+
return RNSBlurEffectStyleSystemMaterialLight;
39+
case SystemThickMaterialLight:
40+
return RNSBlurEffectStyleSystemThickMaterialLight;
41+
case SystemChromeMaterialLight:
42+
return RNSBlurEffectStyleSystemChromeMaterialLight;
43+
case SystemUltraThinMaterialDark:
44+
return RNSBlurEffectStyleSystemUltraThinMaterialDark;
45+
case SystemThinMaterialDark:
46+
return RNSBlurEffectStyleSystemThinMaterialDark;
47+
case SystemMaterialDark:
48+
return RNSBlurEffectStyleSystemMaterialDark;
49+
case SystemThickMaterialDark:
50+
return RNSBlurEffectStyleSystemThickMaterialDark;
51+
case SystemChromeMaterialDark:
52+
return RNSBlurEffectStyleSystemChromeMaterialDark;
53+
}
54+
#endif
55+
56+
switch (blurEffect) {
57+
case None:
58+
return RNSBlurEffectStyleNone;
59+
case Light:
60+
return RNSBlurEffectStyleLight;
61+
case Dark:
62+
return RNSBlurEffectStyleDark;
63+
case Regular:
64+
return RNSBlurEffectStyleRegular;
65+
case Prominent:
66+
return RNSBlurEffectStyleProminent;
67+
case ExtraLight:
68+
default:
69+
return RNSBlurEffectStyleNone;
70+
}
71+
}
72+
73+
}; // namespace rnscreens::conversion

ios/conversion/RNSConversions.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#import <react/renderer/components/rnscreens/Props.h>
4+
#import "RNSEnums.h"
5+
6+
namespace rnscreens::conversion {
7+
8+
RNSBlurEffectStyle RNSBlurEffectStyleFromRNSBottomTabsTabBarBlurEffect(
9+
facebook::react::RNSBottomTabsTabBarBlurEffect blurEffect);
10+
11+
};

src/fabric/BottomTabsNativeComponent.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
44
import type { ColorValue, ViewProps } from 'react-native';
5+
import { WithDefault } from 'react-native/Libraries/Types/CodegenTypes';
56

67
// TODO: Report issue on RN repo, that nesting color value inside a struct does not work.
78
// Generated code is ok, but the value is not passed down correctly - whatever color is set
@@ -10,9 +11,33 @@ type TabBarAppearance = Readonly<{
1011
backgroundColor?: ColorValue;
1112
}>;
1213

14+
type BlurEffect =
15+
| 'none'
16+
| 'extraLight'
17+
| 'light'
18+
| 'dark'
19+
| 'regular'
20+
| 'prominent'
21+
| 'systemUltraThinMaterial'
22+
| 'systemThinMaterial'
23+
| 'systemMaterial'
24+
| 'systemThickMaterial'
25+
| 'systemChromeMaterial'
26+
| 'systemUltraThinMaterialLight'
27+
| 'systemThinMaterialLight'
28+
| 'systemMaterialLight'
29+
| 'systemThickMaterialLight'
30+
| 'systemChromeMaterialLight'
31+
| 'systemUltraThinMaterialDark'
32+
| 'systemThinMaterialDark'
33+
| 'systemMaterialDark'
34+
| 'systemThickMaterialDark'
35+
| 'systemChromeMaterialDark';
36+
1337
export interface NativeProps extends ViewProps {
1438
tabBarAppearance?: TabBarAppearance;
1539
tabBarBackgroundColor?: ColorValue;
40+
tabBarBlurEffect?: WithDefault<BlurEffect, 'none'>;
1641
}
1742

1843
export default codegenNativeComponent<NativeProps>('RNSBottomTabs', {});

0 commit comments

Comments
 (0)