Skip to main content

AnimatedLineTabs

Basic usage

PageSwiperSample.tsx
import { PageSwiper, Page } from 'react-native-awesome-swiper';

const Basic = () => {
const [activeIndex, setActiveIndex] = useState(3);

const { top } = useSafeAreaInsets();

const ref = useRef<FlatList<Page>>(null);

const pages: Page[] = [
{ label: 'pink', Component: SamplePage },
{ label: 'purple', Component: SamplePage },
{ label: 'green', Component: SamplePage },
{ label: 'yellow', Component: SamplePage },
{ label: 'gray', Component: SamplePage },
{ label: 'black', Component: SamplePage },
{ label: 'skyblue', Component: SamplePage },
];

return (
<PageSwiper.Provider>
<PageSwiper.AnimatedLineTabs
pages={pages}
activeIndex={activeIndex}
topInset={top}
/>
<PageSwiper.PageFlatList
ref={ref}
pages={pages}
onActivePageIndexChange={setActiveIndex}
initialScrollIndex={activeIndex}
/>
</PageSwiper.Provider>
);
};

PageFlatList uses FlatList API and AnimatedLineTabs uses ScrollView

pages

page data T should extend Page type

TypeDefaultRequired
T []undefinedYES
interface PageProps {
label: string;
index: number;
}

interface Page {
label: string;
Component: React.FunctionComponent<PageProps>;
}

activeIndex

activeIndex is used to automatically scroll to active item

TypeDefaultRequired
string#ccccccNO

onPress

onPress function when tab pressed see scrollPageConfig for detail

TypeDefaultRequired
(index: number) => voidundefinedNO

viewOffset

left offset when auto scroll

TypeDefaultRequired
numberundefinedNO

lineThickness

underline height in px

TypeDefaultRequired
number4NO

lineColor

undeline hex color

TypeDefaultRequired
string#000000NO

topInset

top inset for safearea

TypeDefaultRequired
number0NO

textStyle

text style for tab label. for more customization use renderTab

TypeDefaultRequired
StyleProp<TextStyle>undefinedNO

tabStyle

tab style. for more customization use renderTab

TypeDefaultRequired
StyleProp<ViewStyle>undefinedNO

backgroundColor

backgroundColor of tab scroll view

TypeDefaultRequired
string#ffffffNO

activeTextColor

active text color

TypeDefaultRequired
string#000000NO

inactiveTextColor

inactive text color

TypeDefaultRequired
string#888888NO

renderTab

custom render function to fully customize tab

TypeDefaultRequired
(label: string, index: number) => ReactElementundefinedNO

scrollPageConfig

scroll configuration when tab pressed

TypeDefaultRequired
{ animated?: boolean; scrollOnPress?: boolean }undefinedNO