1.4.0 • Published 5 years ago

react-native-segmented-control-tabs v1.4.0

Weekly downloads
8
License
MIT
Repository
github
Last release
5 years ago

React Native Segmented Control Tabs

A React Native component for iOS and Android based on SegmentedControlIOS. The component supports Expo and React Native.

Installing

With npm

npm install react-native-segmented-control-tabs --save

With yarn

yarn add react-native-segmented-control-tabs

Usage

import SegmentedControlTabs from 'react-native-segmented-control-tabs';

Examples

Tabs with text

iOSAndroid
React Native iOS Segmented Control tabs with textReact Native Android Segmented Control tabs with text

Example code

<SegmentedControlTabs
                    values={[
                        <Text style={{ color: '#1B3964' }]}>LOG IN</Text>,
                        <Text style={{ color: '#89AECC' }}>SIGN UP</Text>
                    ]}
                    handleOnChangeIndex={handleSelectedIndex}
                    activeIndex={selectedIndex}
                    tabsContainerStyle={{
                        width: '100%',
                        height: 35,
                        backgroundColor: '#EAF3FF',
                        borderTopLeftRadius: 20,
                        borderBottomLeftRadius: 20,
                        borderTopRightRadius: 20,
                        borderBottomRightRadius: 20,
                        borderColor: '#EAF3FF',
                        borderWidth: 1
                    }}
                    activeTabStyle={{
                        borderBottomColor: "rgb(255,177,120)",
                        borderBottomWidth: 3,
                        borderColor: "rgb(213,228,241)",
                        zIndex: 1,
                    }}
                    firstTabStyle={{
                        borderTopLeftRadius: 20,
                        borderBottomLeftRadius: 20,
                        backgroundColor: '#fff'
                    }}
                    lastTabStyle={{
                        borderTopRightRadius: 20,
                        borderBottomRightRadius: 20,
                    }}
                    tabStyle={{
                        borderColor: 'transparent'
                    }}
                />

Tabs with images

iOSAndroid
React Native iOS Segmented Control tabs with imagesReact Native Android Segmented Control tabs with images

Example code

<SegmentedControlTabs
                    values={[
                        <Image
                            style={{ width: 40, height: 40, resizeMode: 'contain' }}
                            source={require('../../assets/icon.png')}
                        />,
                        <Image
                            style={{ width: 40, height: 40, resizeMode: 'contain' }}
                            source={require('../../assets/icon.png')}
                        />,
                        <Image
                            style={{ width: 40, height: 40, resizeMode: 'contain' }}
                            source={require('../../assets/icon.png')}
                        />,
                        <Image
                            style={{ width: 40, height: 40, resizeMode: 'contain' }}
                            source={require('../../assets/icon.png')}
                        />,
                    ]}
                    handleOnChangeIndex={handleSelectedIndex}
                    selectedIndexes={[0]}
                    activeIndex={selectedIndex}
                    selectedTabStyle={{ backgroundColor: '#fff' }}
                    selectedFirstTabStyle={{ backgroundColor: '#fff' }}
                    selectedLastTabStyle={{ backgroundColor: '#fff', 
                    borderBottomRightRadius: 20, 
                    borderTopRightRadius: 20 
                    }}
                    tabsContainerStyle={{
                        width: '100%',
                        height: 35,
                        backgroundColor: '#EAF3FF',
                        borderTopLeftRadius: 20,
                        borderBottomLeftRadius: 20,
                        borderTopRightRadius: 20,
                        borderBottomRightRadius: 20,
                        borderColor: '#EAF3FF',
                        borderWidth: 1
                    }}
                    activeTabStyle={{
                        borderBottomColor: "rgb(255,177,120)",
                        borderBottomWidth: 3,
                        borderColor: "rgb(213,228,241)",
                        zIndex: 1,
                    }}
                    firstTabStyle={{
                        borderTopLeftRadius: 20,
                        borderBottomLeftRadius: 20,
                        backgroundColor: '#fff'
                    }}
                    lastTabStyle={{
                        borderTopRightRadius: 20,
                        borderBottomRightRadius: 20,
                    }}
                    tabStyle={{
                        borderColor: 'transparent'
                    }}
                />

Multiple selected tabs

iOSAndroid
React Native iOS Segmented Control tabs with imagesReact Native Android Segmented Control tabs with images

Pass an array of indexes as shown below.

selectedIndexes={[0,1,2]}

Props

PropDescriptionTypeRequired
valuesList of titles, images or a mix of bothArrayYes
handleOnChangeIndexCallback function when a tab is selectedfuncYes
selectedIndexesIndexes of the tabs to be highlightedArrayNo
activeIndexIndex of the active tabArrayYes
selectedTabStyleStyle to be used for highlighted tabsStyle ObjectYes, when selectedIndexes is used
selectedFirstTabStyleStyle to be used for first highlighted tabStyle ObjectYes, when selectedIndexes is used
selectedLastTabStyleStyle to be used for last highlighted tabStyle ObjectYes, when selectedIndexes is used
tabsContainerStyleStyle to be used for tab containerStyle ObjectYes
activeTabStyleStyle to be used for active tabStyle ObjectNo
firstTabStyleStyle to be used for first tab when selected tabs are not usedStyle ObjectNo
lastTabStyleStyle to be used for last tab when selected tabs are not usedStyle ObjectNo
tabStyleStyle to be used as default tabStyle ObjectYes

Authors

  • Pavan Welihinda - Initial work - pavan168

License

This project is licensed under the MIT License.