1.0.3 • Published 7 years ago

react-native-segmented-control-ui v1.0.3

Weekly downloads
39
License
MIT
Repository
github
Last release
7 years ago

react-native-segmented-control-ui(for Android/iOS) 🚀

npm Monthly Downloads

PRs Welcome

NPM

An extendable tab components for React Native similar to iOSSegmentedControl, Primarily built to support both iOS and Android.

Usage

import SegmentedControlTab from 'react-native-segmented-control-ui'

const ConsumerComponent extends Component {

    constructor(){
        super()
        this.state = {
            selectedIndex: 0
        };
    }

    handleIndexChange = (index) => {
        this.setState({
            selectedIndex: index
        });
    }

    render() {
        return (
            <View>
                <SegmentedControlTab
                    values={['First', 'Second', 'Third']}
                    selectedIndex={this.state.selectedIndex}
                    onTabPress={this.handleIndexChange}
                    />
            </View>
        );
    }
}

API

NameDescriptionDefaultType
valuestitles of tabs['One', 'Two', 'Three']array
selectedIndexindex of tab item to be selected initially0number
borderRadiusborderRadius of whole tab5number
tabsContainerStyleexternal styles can be passed to override the default styles of the segmentedControl wrappertabsContainerStyleobject(styles)
tabStyleexternal styles can be passed to override the default styles of the tabstabStyleobject(styles)
tabTextStyleexternal styles can be passed to override the default styles of the tab titletabTextStyleobject(styles)
activeTabStyleexternal styles can be passed to override the default styles of the active tabactiveTabStyleobject(styles)
activeTabTextStyleexternal styles can be passed to override the default styles of the active tab textactiveTabTextStyleobject(styles)
badgesbadges values to display[1, 2, 3]array
tabBadgeContainerStyleexternal style can be passed to override the default style of the badge containertabBadgeContainerStyleobject(styles)
activeTabBadgeContainerStyleexternal style can be passed to override the default style of the active badge containeractiveTabBadgeContainerStyleobject(styles)
tabBadgeStyleexternal style can be passed to override the default style of the badge texttabsContainerStyleobject(styles)
activeTabBadgeStyleexternal style can be passed to override the default style of the active badge textactiveTabBadgeStyleobject(styles)
onTabPresscall-back function when a tab is selected() => {}func
allowFontScalingwhether the segment & badge text should allow font scaling (default matches React Native default)truebool
accessibleenables accessibility for each tabtruebool
accessibilityLabelsReads out the given text on each tab press when voice over is enabled. If not set, uses the text passed in as values in props as a fallback'Label 1', 'Label 2', 'Label 3'array
testIDsUnique identifier for each tab which acts as a hook for functional test'Label 1', 'Label 2', 'Label 3'array

Custom styling

```javascript
    <SegmentedControlTab tabsContainerStyle={styles.tabsContainerStyle}
        tabStyle={styles.tabStyle}
        tabTextStyle={styles.tabTextStyle}
        activeTabStyle={styles.activeTabStyle}
        activeTabTextStyle={styles.activeTabTextStyle}
        selectedIndex={1}
        allowFontScaling={false}
        values={['First', 'Second', 'Third']}
        onPress= {index => this.setState({selected:index})}
    />

    const styles = StyleSheet.create({
        tabsContainerStyle: {
            backgroundColor: 'transparent',
            flexDirection: 'row',
        },
        tabStyle: {
            paddingVertical: 5,
            flex: 1,
            justifyContent: 'center',
            alignItems: 'center',
            borderColor: '#0076FF',
            borderWidth: 1,
            backgroundColor: 'white',
        },
        activeTabStyle: {
            backgroundColor: '#0076FF'
        },
        tabTextStyle: {
            color: '#0076FF'
        },
        activeTabTextStyle: {
            color: 'white'
        },
        tabBadgeContainerStyle: {
            borderRadius: 20,
            backgroundColor: 'red',
            paddingLeft: 5,
            paddingRight: 5,
            marginLeft: 5,
            marginBottom: 3
        },
        activeTabBadgeContainerStyle: {
            backgroundColor: 'white'
        },
        tabBadgeStyle: {
            color: 'white',
            fontSize: 11,
            fontWeight: 'bold'
        },
        activeTabBadgeStyle: {
            color: 'black'
        }
    })
```

Try it out

You can try it out with Exponent here.

Example

Look at the example folder to run the expo app locally.

License

MIT