Skip to content

Commit

Permalink
Merge pull request #57 from JPStrydom/main
Browse files Browse the repository at this point in the history
feat: add support for styling the tab label.
  • Loading branch information
RichardLindhout committed Aug 14, 2023
2 parents 6e30d53 + 09883ed commit fd75a3a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Swiper.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function SwiperNative(props: SwiperProps) {
showLeadingSpace,
disableSwipe,
tabHeaderStyle,
tabLabelStyle,
} = props;
const { index, goTo } = React.useContext(TabsContext);
const indexRef = React.useRef<number>(index || 0);
Expand Down Expand Up @@ -77,6 +78,7 @@ function SwiperNative(props: SwiperProps) {
uppercase,
mode,
tabHeaderStyle,
tabLabelStyle,
};
return (
<>
Expand Down
2 changes: 2 additions & 0 deletions src/Swiper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function Swiper(props: SwiperProps) {
uppercase,
mode,
tabHeaderStyle,
tabLabelStyle,
} = props;

const index = useTabIndex();
Expand All @@ -39,6 +40,7 @@ function Swiper(props: SwiperProps) {
uppercase,
mode,
tabHeaderStyle,
tabLabelStyle,
};

return (
Expand Down
5 changes: 4 additions & 1 deletion src/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import type { ViewStyle } from 'react-native';
import type { ViewStyle, TextStyle } from 'react-native';
import { withTheme } from 'react-native-paper';
import Swiper from './Swiper';
import type { MD3LightTheme } from 'react-native-paper';
Expand All @@ -17,6 +17,7 @@ function Tabs({
showLeadingSpace = true,
disableSwipe = false,
tabHeaderStyle,
tabLabelStyle,
...rest
}: {
children: any;
Expand All @@ -30,6 +31,7 @@ function Tabs({
mode?: Mode;
disableSwipe?: boolean;
tabHeaderStyle?: ViewStyle | undefined;
tabLabelStyle?: TextStyle | undefined;
}) {
const children = React.Children.toArray(rest.children).filter(Boolean);

Expand All @@ -45,6 +47,7 @@ function Tabs({
mode={mode}
disableSwipe={disableSwipe}
tabHeaderStyle={tabHeaderStyle}
tabLabelStyle={tabLabelStyle}
>
{children}
</Swiper>
Expand Down
2 changes: 2 additions & 0 deletions src/TabsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function TabsHeader({
uppercase,
mode,
tabHeaderStyle,
tabLabelStyle,
children,
}: SwiperRenderProps) {
const { index, goTo } = React.useContext(TabsContext);
Expand Down Expand Up @@ -214,6 +215,7 @@ export default function TabsHeader({
iconPosition={iconPosition}
showTextLabel={showTextLabel}
mode={mode}
tabLabelStyle={tabLabelStyle}
/>
))}
<Animated.View
Expand Down
5 changes: 4 additions & 1 deletion src/TabsHeaderItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { Animated, StyleSheet, View, Platform } from 'react-native';
import type { LayoutChangeEvent, TextProps } from 'react-native';
import type { LayoutChangeEvent, TextProps, TextStyle } from 'react-native';
import { Badge, Text, TouchableRipple } from 'react-native-paper';
import type { MD3LightTheme } from 'react-native-paper';
import type { ReactElement } from 'react';
Expand Down Expand Up @@ -30,6 +30,7 @@ export default function TabsHeaderItem({
mode,
iconPosition,
showTextLabel,
tabLabelStyle,
}: {
tab: ReactElement<TabScreenProps>;
tabIndex: number;
Expand All @@ -46,6 +47,7 @@ export default function TabsHeaderItem({
iconPosition?: IconPosition;
showTextLabel?: boolean;
mode: Mode;
tabLabelStyle?: TextStyle | undefined;
}) {
const baseColor = theme.colors.primary;
const rippleColor = React.useMemo(
Expand Down Expand Up @@ -151,6 +153,7 @@ export default function TabsHeaderItem({
styles.text,
iconPosition === 'top' && styles.textTop,
{ ...theme.fonts.titleSmall, color, opacity },
tabLabelStyle,
]}
>
{uppercase && !theme.isV3
Expand Down
2 changes: 2 additions & 0 deletions src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface SwiperRenderProps {
uppercase: boolean;
mode: Mode;
tabHeaderStyle: ViewStyle | undefined;
tabLabelStyle: TextStyle | undefined;
}

export interface SwiperProps {
Expand All @@ -40,6 +41,7 @@ export interface SwiperProps {
mode: Mode;
disableSwipe?: boolean;
tabHeaderStyle: ViewStyle | undefined;
tabLabelStyle: TextStyle | undefined;
}

export interface OffsetScrollArgs {
Expand Down

0 comments on commit fd75a3a

Please sign in to comment.