Skip to content

Commit

Permalink
feat: add a tabBarBadgeStyle option to customize the badge
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Nov 9, 2020
1 parent dbe961b commit 6ac4d40
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/bottom-tabs/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ export type BottomTabNavigationOptions = {
*/
tabBarBadge?: number | string;

/**
* Custom style for the tab bar badge.
* You can specify a background color or text color here.
*/
tabBarBadgeStyle?: StyleProp<TextStyle>;

/**
* Accessibility label for the tab button. This is read by the screen reader when the user taps the tab.
* It's recommended to set this if you don't have a label for the tab.
Expand Down
1 change: 1 addition & 0 deletions packages/bottom-tabs/src/views/BottomTabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ export default function BottomTabBar({
button={options.tabBarButton}
icon={options.tabBarIcon}
badge={options.tabBarBadge}
badgeStyle={options.tabBarBadgeStyle}
label={label}
showLabel={showLabel}
labelStyle={labelStyle}
Expand Down
6 changes: 6 additions & 0 deletions packages/bottom-tabs/src/views/BottomTabItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type Props = {
* Text to show in a badge on the tab icon.
*/
badge?: number | string;
/**
* Custom style for the badge.
*/
badgeStyle?: StyleProp<TextStyle>;
/**
* URL to use for the link to the tab.
*/
Expand Down Expand Up @@ -122,6 +126,7 @@ export default function BottomTabBarItem({
label,
icon,
badge,
badgeStyle,
to,
button = ({
children,
Expand Down Expand Up @@ -235,6 +240,7 @@ export default function BottomTabBarItem({
route={route}
horizontal={horizontal}
badge={badge}
badgeStyle={badgeStyle}
activeOpacity={activeOpacity}
inactiveOpacity={inactiveOpacity}
activeTintColor={activeTintColor}
Expand Down
11 changes: 10 additions & 1 deletion packages/bottom-tabs/src/views/TabBarIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import React from 'react';
import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
import {
View,
StyleSheet,
StyleProp,
TextStyle,
ViewStyle,
} from 'react-native';
import type { Route } from '@react-navigation/native';
import Badge from './Badge';

type Props = {
route: Route<string>;
horizontal: boolean;
badge?: string | number;
badgeStyle?: StyleProp<TextStyle>;
activeOpacity: number;
inactiveOpacity: number;
activeTintColor: string;
Expand All @@ -22,6 +29,7 @@ type Props = {
export default function TabBarIcon({
horizontal,
badge,
badgeStyle,
activeOpacity,
inactiveOpacity,
activeTintColor,
Expand Down Expand Up @@ -56,6 +64,7 @@ export default function TabBarIcon({
style={[
styles.badge,
horizontal ? styles.badgeHorizontal : styles.badgeVertical,
badgeStyle,
]}
size={(size * 3) / 4}
>
Expand Down

0 comments on commit 6ac4d40

Please sign in to comment.