Code Monkey home page Code Monkey logo

react-native-dynamic-tab-view's Introduction

npm version

Features

  • Easy to use and easy to read code
  • React-Native Javascript library built on top of FlatList.

Usecases

  • Dynamic tab data that can be populated by code (typically tabs are determined by an API call)
  • Ability to select any index (and just the zeroth index) as the default index.

How to use

Simply install by running yarn add react-native-dynamic-tab-view

Use it by

import DynamicTabView from 'react-native-dynamic-tab-view';
 <DynamicTabView
        data={dataSource}
        renderTab={renderTab}
        onChangeTab={onChangeTab}
        defaultIndex={defaultIndex}
        containerStyle={styles.container}
        activeTabStyle={styles.activeTabStyle}
        headerBackgroundColor={'white'}
        headerUnderlayColor={'blue'}
      />

Here data is of the format

[
   { title: 'Tab1', key: 'item1' },
   { title: 'Tab2', key: 'item2' },
   { title: 'Tab3', key: 'item3' },
]

title sets the tab title key is used internally by React. It can be any unique string

Important Props

  • data data to tell the number of tabs and set the layout
  • renderTab method to render individual tab. It should return a valid React Component
  • onChangeTab callback that will be invoked when a user changes tab
  • defaultIndex index of the tab that will be selected by default.
  • containerStyle style for the dynamic tab view container
  • headerBackgroundColor background color for header
  • headerUnderlayColor Color for header underlay
  • headerTextStyle style for header text
  • swipeToPage Enable the swipe gesture for moving between tabs. Default true.

Run the Example project

  1. cd Example
  2. npm install
  3. react-native run-android or react-native run-ios

or try expo: Dynamic Tab View Example

FAQs

Why are you building another TabView library?

At present, there are two tabView libraries that are out there

  • react-native-scrollable-tab-view
  • react-native-tab-view I have used both of them and I had multitude of issues with them.
  • react-native-scrollable-tab-view
    • Doesn't have proper maintainence. Last update was back in October. There are lot of open PRs.
    • Code is bloated and I tried fixing issues, but couldn't navigate my way through
    • Uses different code for Android and iOS and therefore I had issues like some view works with Android well and not with iOS and viceverca
  • react-native-tab-view
    • Uses different code for Android and iOS
    • Couldn't get default page selected working with this.
    • Built and works well for static views (dynamic tabs doesn't work very well with Android)

How's react-native-dynamic-tab-view different?

  • Uses same code for Android and iOS
  • More importantly, uses FlatList for creating the tabViews
  • Easy to read code

Contributors

react-native-dynamic-tab-view's People

Contributors

fullerlee avatar harpreetcd avatar indupal avatar iyifr avatar maherzaidoune avatar priyathamv avatar protoerik avatar yashgada avatar yeswanth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-native-dynamic-tab-view's Issues

Tabs in index 3 and 5 are not scrolling back

<DynamicTabView data={productCategories.map((item, index) => { return { title: item.catName, key: item.catId, }; })} renderTab={(cat) => ( <FlatList data={productData.filter((item) => item.catName === cat.title)} removeClippedSubview={true} windowSize={17} initialNumToRender={8} numColumns={2} keyExtractor={(item, index) => index} renderItem={(item) => <Product key={item.itemId} product={item} />} /> )} onChangeTab={onChangeTab} defaultIndex={defaultIndex} containerStyle={{flex: 1}} headerBackgroundColor="white" headerUnderlayColor="#E85123" headerTextStyle={{color: 'black'}} />

TypeError: Cannot read property '0' of undefined

I am using FlatList under renderItem Method
<DynamicTabView
data={this.state.data}
renderTab={this._renderItem}
defaultIndex={this.state.defaultIndex}
containerStyle={styles.container}
headerBackgroundColor={"white"}
headerTextStyle={styles.headerText}
onChangeTab={this.onChangeTab}
headerUnderlayColor={"blue"}
/>

Can't customize tabItemContainer style

It becomes necessary to customise the tabItemContainer, for example if one needs to remove the bottom padding below the Highlight, or add a background or so.
I'll share a pull request to make it available as a prop. Naming it tabItemContainerStyle is a mouthfull, but let me know if you have any better ideas.
Line 19 at DynamicTabViewScrollHeader.js

Add types

Hello! I'm really enjoying this library, since I need dynamic tabs in many projects. However it would be nice to have some typedefinitions. If there are typedefinitions please tell me how to access them since npm install @types/react-native-dynamic-tab-view does not exist :)

header styling not working

Hello,

Im trying to change the color of text inside tabs, but they are unchangeable (always white) and cant give it 100% width .

Screen Shot 2019-06-13 at 9 51 47 PM

I need to make the header with full width grey

Default Index is not working.

When using this TabView with a default index to open a specific tab the default index is not working. Even though if I am trying to set it statically then also it is not working.

<DynamicTabView
        data={tabNames}
        renderTab={_renderTabItem}
        defaultIndex={defaultIndex}
        containerStyle={styles.tabContainer}
        headerBackgroundColor={'#8e8e8e'}
        headerTextStyle={styles.headerText}
        onChangeTab={(index) => onChangeTab(index)}
        headerUnderlayColor={'#8e8e8e'}
        headerContainerStyle={{ backgroundColor: '#afafaf' }}
        headerActiveTextStyle={{ color: '#8e8e8e' }}
        highlightStyle={{ backgroundColor: '#8e8e8e' }}
        tabContainerStyle={{}}
        noHighlightStyle={{ backgroundColor: '#8e8e8e' }}
        extraData={{}} />

Scroll bug

1 When you reach to the last tab(lets say 10th tab) and still swipe right. The 9th tab gets selected
2 Swipe right again and then the 10th tab header
3. Steps 1 and 2 goes in a loop

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.