1.0.3 • Published 2 months ago

react-native-magic-tabs v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

MagicTabs for React Native

MagicTabs is a customizable, scrollable tab component for React Native applications. It allows for dynamic tab creation with extensive styling and alignment options.

Features

  • Dynamic tab creation from an array of items
  • Customizable text, button styles for both active and inactive states
  • Optional custom rendering for each tab
  • Configurable alignment of tabs within the container
  • Animated scrolling to active tab
  • Fully typed with TypeScript for easy integration into your project

Installation

Install react-native-magic-tabs using the package manager of your choice:

npm

npm install react-native-magic-tabs

yarn

yarn add react-native-magic-tabs

Expo CLI

npx expo add react-native-magic-tabs

Usage

import React from "react";
import { Dimensions, View } from "react-native";
import MagicTabs, { MagicTabsItemsProps } from "react-native-magic-tabs";

const App = () => {
  const screenWidth = Dimensions.get("window").width;
  const [activeIndex, setActiveIndex] = React.useState(6);

  const tabs: MagicTabsItemsProps[] = [
    { id: 1, name: "Tab 1" },
    { id: 2, name: "Tab 2" },
    // Add more tabs as needed
  ];

  const onPress = (index: number) => {
    console.log("Selected tab:", index);
  };

  return (
    <View style={{ flex: 1 }}>
      <MagicTabs
        items={NavigationTabs}
        onPress={onPress}
        activeIndex={activeIndex}
        style={{ marginBottom: 12 }}
        spaceBetween={8}
        animated={true}
        width={screenWidth}
        buttonStyle={{
          flex: 1,
          borderRadius: 6,
          paddingHorizontal: 12,
          paddingVertical: 7,
        }}
        activeButtonStyle={{
          flex: 1,
          borderRadius: 6,
          paddingHorizontal: 12,
          paddingVertical: 7,
        }}
        textStyle={{ fontSize: 12, fontWeight: "bold" }}
        activeTextStyle={{ fontSize: 12, fontWeight: "bold" }}
        backgroundColor={"#B02132"}
        activeBackgroundColor={"#fff"}
        textColor={"#fff"}
        activeTextColor={"#C62538"}
        height={30}
        customItem={false}
        align="center"
      />
    </View>
  );
};

export default App;

Props

Below is a table detailing the props accepted by the MagicTabs component, including their types and descriptions:

PropTypeDescription
itemsArray<MagicTabsItemsProps>Array of tab items. Each item should have an id and name.
onPress(index: number) => voidFunction called when a tab is pressed. Receives the index.
textStyleStyleProp<TextStyle>Style object for text within tabs.
activeTextStyleStyleProp<TextStyle>Style object for text within active tabs.
buttonStyleStyleProp<ViewStyle>Style object for the tab buttons.
activeButtonStyleStyleProp<ViewStyle>Style object for active tab buttons.
textColorstringColor of the text for inactive tabs.
activeTextColorstringColor of the text for active tabs.
backgroundColorstringBackground color of the tabs.
activeBackgroundColorstringBackground color of the active tab.
activeIndexnumberIndex of the initially active tab.
styleStyleProp<ViewStyle>Style object for the tab container.
contentContainerStyleStyleProp<ViewStyle>Style object for the tab scrollview container.
spaceBetweennumberSpace between individual tabs.
animatedbooleanWhether the scrolling to the active tab is animated.
widthnumberWidth of the tab container. Defaults to the device's width.
heightnumberHeight of the tab container.
ItemReact.ReactNode \| ((item: MagicTabsItemsProps) => React.ReactNode)Custom render function or component for tabs.
ItemActiveReact.ReactNode \| ((item: MagicTabsItemsProps) => React.ReactNode)Custom render function or component for active tabs.
customItembooleanEnables custom rendering for tabs.
align"center" \| "start" \| "end"Alignment of the tabs within the container.

Use these props to customize the MagicTabs component according to your application's needs.

Customizing Tabs

MagicTabs allows for extensive customization including custom render functions or components for individual tabs, adjustable spacing, alignment, and much more. Experiment with the props to create the perfect tab component for your app.

Contributing

Contributions are welcome! Please open an issue or submit a pull request with your improvements or suggestions.

License

This project is licensed under the MIT License.

1.0.3

2 months ago

1.0.2

3 months ago

1.0.1

3 months ago

1.0.0

3 months ago