Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-scrollable-tabstring

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-scrollable-tabstring

a scrollable list with animated horizontal tab when scrolling

  • 0.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18
decreased by-35.71%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

A ScrollView-like component with animated horizontal tab when scrolling

Get started

Installation

Install the dependency.

$ npm install react-native-scrollable-tabstring
$ yarn add react-native-scrollable-tabstring

Usage

Start using the components or try it on Snack here.

import ScrollableTabString from 'react-native-scrollable-tabstring';
//Standard scrollable tab
<ScrollableTabString
    onPressTab={() => yourCustomOnPressIfNeeded}
    dataTabs={yourTabNamesList}
    dataSections={yourDataSectionList}
    renderSection={(item) => yourCustomSectionItemRender} 
    renderTabName={(item) => yourCustomSectionTabName}
    selectedTabStyle={{
        ...your custom styles when a Tab is scrolled to or tapped
    }}
    unselectedTabStyle={{
        ...your custom styles when a Tab is normal
    }}
/>

Component Detail

This component currently support tab list for horizontal side and vertical section list. Both of which are Flatlist

PropertyTypeRequiredDefaultDescription
dataTabsArrayYes[]A tab list to represent
dataSectionsArrayYes[]A Section list to represent
isParentBooleanNofalseSwitch to true if you want to support more sections following by a parent tab, see detail here
headerTransitionWhenScrollBooleanNotrueAnimation at tab header when section scrolling
tabPositionStringNotopTab list position arrangement, top and bottom
renderSectionItemFuncYesFunction to render Section Item
renderTabNameItemFuncYesFunction to render Tab Item, equal to renderItem in Flatlist
customTabNamesPropsObjectNoFlatlist Props, avoid props like renderItem, data, ref, onScroll as may result some issues
customSectionPropsObjectNoScrollView Props
onPressTabFuncNoCustom function when pressing on a tab
onScrollSectionFuncNoCustom function when section scrolling
selectedTabStyleObjectNo{ borderBottomColor: 'black', borderBottomWidth: 1, }Custom style when a tab is selected
unselectedTabStyleObjectNo{ backgroundColor: 'white', alignItems: 'center', justifyContent: 'center', }Custom style when a tab is unselected

Example

Scrollable tab

Display a basic scrollable tab

Note: Length of `dataTabs` and `dataSections` must equal, otherwise may result in incorrect scrolling order
   const tabNames = [{
    title: 'Tab 1',
},
...................
{
    title: 'Tab 6',
}];

const dataSections = [
    {
        name: 'Section 1',
        data: [..........]
    },
    ...............
    {
        name: 'Section 6',
        data: [..........]

    },
];

render () {
    return (
        <ScrollableTabString
            dataTabs={tabNames}
            dataSections={dataSections}
            renderSection={(item) => (
                <View>
                    <Text>{item.name}</Text>
                    {
                        item.data.map((i) => (
                            <Text key={i.id} style={{ padding: 20 }}>{i.name}</Text>
                        ))
                    }
                </View>
            )}
            renderTabName={(item) => (
                <TouchableOpacity>
                    <Text style={{ padding: 10 }}>
                        {item.title}
                    </Text>
                </TouchableOpacity>
            )}
            selectedTabStyle={{
                borderColor: Colors.brown_grey,
                borderRadius: 10,
                borderWidth: 1,
                margin: 10
            }}
            unselectedTabStyle={{
                backgroundColor: Colors.white,
                alignItems: 'center',
                justifyContent: 'center',
            }}
        />
    )
};

Scrollable tab with parent tab

Scrollable tab with parent tab and children section follow

Use this if you want to support more sections following on a tab.

Add index key to parent tab and sections (start from 0). For example Tab 1 has 2 children section follow. They are Section 1 and Section 2 -> index of Tab 1, Section 1 and 2 are 0

Note: Index of both parent and children section must equivalent and those sections must be adjacent.
const tabNames = [{
    title: 'Tab 1',
    index: 0
}
.....
, {
    title: 'Tab 6',
    index: 5
}];

const dataSections = [
    {
        name: 'Section 1',
        index: 0,
        data: [..........]
    },
    {
        name: 'Section 2',
        index: 0,
        data: [..........]
    },
    {
        name: 'Section 3',
        index: 1,
        data: [..........]
    },
    {
        name: 'Section 4',
        index: 1,
        data: [..........]
    },
    {
        name: 'Section 5',
        index: 2,
        data: [..........]
    },
    {
        name: 'Section 6',
        index: 2,
        data: [..........]
    },
    {
        name: 'Section 7',
        index: 3,
        data: [..........]
    },
    {
        name: 'Section 8',
        index: 4,
        data: [..........]
    },
];

const ScrollableTabStringDemo = () => (
    <ScrollableTabString
        isParent //remember to add this
        dataTabs={tabNames}
        dataSections={dataSections}
        renderSection={(item) => (
            <View>
                <Text>{item.name}</Text>
                {
                    item.data.map((i) => (
                        <Text key={i.id} style={{ padding: 20 }}>{i.name}</Text>
                    ))
                }
            </View>
        )}
        renderTabName={(item) => (
            <TouchableOpacity>
                <Text style={{ padding: 10 }}>
                    {item.title}
                </Text>
            </TouchableOpacity>
        )}
        selectedTabStyle={{
            borderColor: Colors.brown_grey,
            borderRadius: 10,
            borderWidth: 1,
            margin: 10
        }}
        unselectedTabStyle={{
            backgroundColor: Colors.white,
            alignItems: 'center',
            justifyContent: 'center',
        }}
    />
);

Limitation

This component allows you to customize some Flatlist props on Tab Name and ScrollView props as well. However, you should avoid some of properties like onScroll, renderItem, CellRendererComponent, horizontal as may result some issues.

Furthermore, this component doesn't support on load more yet due to heavily calculated, still working on this :p

Contributing

All contributions are welcome! Please open an issue if you get stuck and bugs, or a PR if you have any feature idea, improvements and bug fixing. I'm very appreciate !

License

MIT

Keywords

FAQs

Package last updated on 15 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc