Git Product home page Git Product logo

rn-segmented-control's Introduction

npm npm npm

React Native Segmented Control


Installation

yarn add rn-segmented-control
# or
npm i rn-segmented-control

Also you need to have lodash installed.

Usage

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import SegmentedControl from 'rn-segmented-control';

const AppRoot = () => {
  const handleTabPress = (index) => {
    // Function Callback with Tab index pressed
    console.log("Tab index", index)
  }
  return (
    <View style={styles.container}>
      <Text style={styles.textStyle}>Hello,World !</Text>
      <Text style={styles.textStyle}> Segmented Control with 2 labels</Text>
      <SegmentedControl
        tabs={['Label', 'Label']}
        onTabPress={handleTabPress}
      />
      <Text style={styles.textStyle}> Segmented Control with 3 labels</Text>
      <SegmentedControl
        tabs={['Label', 'Label', 'Label']}
        onTabPress={handleTabPress}
      />
      <Text style={styles.textStyle}> Segmented Control with 4 labels</Text>
      <SegmentedControl
        tabs={['Label', 'Label', 'Label', 'Label']}
        onTabPress={handleTabPress}
      />
      <Text style={styles.textStyle}>Customised Segmented Control</Text>
      <SegmentedControl
        tabs={['Shop', 'Discover', 'Brands']}
        onTabPress={handleTabPress}
        segmentedControlBackgroundColor='#E5E5EA'
        activeSegmentBackgroundColor='white'
        activeTextColor='black'
        textColor='black'
        currentIndex={1}
      />
    </View>
  )
}


const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    marginHorizontal: 16
  },
  textStyle: {
    fontSize: 24,
    textAlign: 'center',
    paddingVertical: 10
  }
})


export default AppRoot;

Props

Name Description Required Type Default
tabs An array of labels for segments YES Array -
onTabPress A callback Function with pressed segment index YES Function -
currentIndex Index of the currently active segment NO Number 0
activeSegmentBackgroundColor Background color of Active Label NO Color '#0482f7'
segmentedControlBackgroundColor Background color of the segment NO Color '#86c4fd'
textColor Color of Label Text NO Color 'white'
activeTextColor Color of Active Label Text NO Color 'black'

Color accepts all React Native Colors.

Example

Checkout the example here.

Blog

Have a look at my blog here.

Built with ❤️

Todos

  • Customisable Text Styles
  • Make it work in Landscape mode
  • Custom Animation Spring Config
  • handlePress can be in a useCallback to prevent the closure from being created on every re-render.

Contributing

Pull requests are always welcome! Feel free to open a new GitHub issue for any changes that can be made.

Author

Karthik B

License

MIT

rn-segmented-control's People

Contributors

karthik-b-06 avatar

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.