Skip to content

Commit 1f5db7b

Browse files
feat(iOS): Added translucent property for iOS (#62)
* feat: added example for translucent * fix: empty setter for android and ios code prettier * fix: pr comments resovled
1 parent 8947d4e commit 1f5db7b

File tree

9 files changed

+44
-0
lines changed

9 files changed

+44
-0
lines changed

android/src/main/java/com/rcttabview/RCTTabViewViewManager.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ class RCTTabViewViewManager :
7676
}
7777
}
7878

79+
@ReactProp(name = "translucent")
80+
fun setTranslucentview(view: ReactBottomNavigationView, translucent: Boolean?) {
81+
}
82+
7983
public override fun createViewInstance(context: ThemedReactContext): ReactBottomNavigationView {
8084
eventDispatcher = context.getNativeModule(UIManagerModule::class.java)!!.eventDispatcher
8185
val view = ReactBottomNavigationView(context)

docs/docs/docs/guides/usage-with-react-navigation.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ Whether to disable page animations between tabs.
6565

6666
Describes the appearance attributes for the tabBar to use when an observable scroll view is scrolled to the bottom.
6767

68+
#### `translucent` <Badge text="iOS" type="info" />
69+
70+
A Boolean value that indicates whether the tab bar is translucent.
71+
6872
Available options:
6973

7074
- `default` - uses default background and shadow values.

example/src/App.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ const FourTabsTransparentScrollEdgeAppearance = () => {
3939
return <FourTabs scrollEdgeAppearance="transparent" />;
4040
};
4141

42+
const FourTabsTranslucent = () => {
43+
return <FourTabs translucent={false} />;
44+
};
45+
4246
const examples = [
4347
{ component: ThreeTabs, name: 'Three Tabs' },
4448
{ component: FourTabs, name: 'Four Tabs' },
@@ -58,6 +62,10 @@ const examples = [
5862
component: FourTabsTransparentScrollEdgeAppearance,
5963
name: 'Four Tabs - Transparent scroll edge appearance',
6064
},
65+
{
66+
component: FourTabsTranslucent,
67+
name: 'Four Tabs - Translucent tab bar',
68+
},
6169
{ component: NativeBottomTabs, name: 'Native Bottom Tabs' },
6270
{ component: JSBottomTabs, name: 'JS Bottom Tabs' },
6371
{

example/src/Examples/FourTabs.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ interface Props {
1010
ignoresTopSafeArea?: boolean;
1111
disablePageAnimations?: boolean;
1212
scrollEdgeAppearance?: 'default' | 'opaque' | 'transparent';
13+
translucent?: boolean;
1314
rippleColor?: ColorValue;
1415
}
1516

1617
export default function FourTabs({
1718
ignoresTopSafeArea = false,
1819
disablePageAnimations = false,
1920
scrollEdgeAppearance = 'default',
21+
translucent = true,
2022
rippleColor,
2123
}: Props) {
2224
const [index, setIndex] = useState(0);
@@ -62,6 +64,7 @@ export default function FourTabs({
6264
navigationState={{ index, routes }}
6365
onIndexChange={setIndex}
6466
renderScene={renderScene}
67+
translucent={translucent}
6568
rippleColor={rippleColor}
6669
/>
6770
);

ios/RCTTabViewViewManager.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ - (UIView *)view
3232
RCT_EXPORT_VIEW_PROPERTY(ignoresTopSafeArea, BOOL)
3333
RCT_EXPORT_VIEW_PROPERTY(disablePageAnimations, BOOL)
3434
RCT_EXPORT_VIEW_PROPERTY(scrollEdgeAppearance, NSString)
35+
RCT_EXPORT_VIEW_PROPERTY(translucent, BOOL)
3536

3637
@end

ios/TabViewImpl.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class TabViewProps: ObservableObject {
1515
@Published var ignoresTopSafeArea: Bool?
1616
@Published var disablePageAnimations: Bool = false
1717
@Published var scrollEdgeAppearance: String?
18+
@Published var translucent: Bool = true
1819
}
1920

2021
/**
@@ -62,6 +63,7 @@ struct TabViewImpl: View {
6263
}
6364
}
6465
.getSidebarAdaptable(enabled: props.sidebarAdaptable ?? false)
66+
.tabBarTranslucent(props.translucent)
6567
.onChange(of: props.selectedPage ?? "") { newValue in
6668
if (props.disablePageAnimations) {
6769
UIView.setAnimationsEnabled(false)
@@ -155,6 +157,17 @@ extension View {
155157
.ignoresSafeArea(.container, edges: .horizontal)
156158
.ignoresSafeArea(.container, edges: .bottom)
157159
.frame(idealWidth: frame.width, idealHeight: frame.height)
160+
}
158161
}
162+
163+
@ViewBuilder
164+
func tabBarTranslucent(_ translucent: Bool) -> some View {
165+
self
166+
.onAppear {
167+
UITabBar.appearance().isTranslucent = translucent
168+
}
169+
.onChange(of: translucent) { newValue in
170+
UITabBar.appearance().isTranslucent = newValue
171+
}
159172
}
160173
}

ios/TabViewProvider.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ struct TabData: Codable {
6464
props.scrollEdgeAppearance = scrollEdgeAppearance as? String
6565
}
6666
}
67+
68+
@objc var translucent: Bool = true {
69+
didSet {
70+
props.translucent = translucent
71+
}
72+
}
6773

6874
@objc var items: NSArray? {
6975
didSet {

src/TabView.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ interface Props<Route extends BaseRoute> {
8585
focused: boolean;
8686
}) => ImageSource | undefined;
8787

88+
/**
89+
* A Boolean value that indicates whether the tab bar is translucent. (iOS only)
90+
*/
91+
translucent?: boolean;
8892
rippleColor?: ColorValue;
8993
}
9094

src/TabViewNativeComponent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface TabViewProps extends ViewProps {
2323
labeled?: boolean;
2424
sidebarAdaptable?: boolean;
2525
scrollEdgeAppearance?: string;
26+
translucent?: boolean;
2627
rippleColor?: ProcessedColorValue | null;
2728
}
2829

0 commit comments

Comments
 (0)