2.0.1 • Published 11 months ago

react-native-segmented-control-2 v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

React Native Segmented Control 2

npm version npm Platform - Android and iOS License: MIT styled with prettier

Installation

Add the dependency:

npm i react-native-segmented-control-2

Peer Dependencies

Zero Dependency 🥳

Usage

Import

import SegmentedControl from "react-native-segmented-control-2";

Fundamental Usage

<SegmentedControl
  tabs={["Label 1", "Label 2", "Label 3"]}
  onChange={(index: number) => console.log("Index: ", index)}
/>

Customized Usage

<SegmentedControl
  style={{ marginTop: 32, backgroundColor: "#ffe0e0" }}
  activeTabColor="#ff2929"
  activeTextColor="#fff"
  tabs={["Label 1", "Label 2", "Label 3"]}
  onChange={(index: number) => console.log("Index: ", index)}
/>

Any Component Usage

You can use the segmented control with any component. All you need to do is that put any component into the tabs props. Please check out the example for its usage

Example Project 😍

You can checkout the example project 🥰

Simply run

  • npm i
  • react-native run-ios/android

should work of the example project.

Configuration - Props

Fundamentals

PropertyTypeDefaultDescription
tabsany[]undefinedset the array for tabs
onChangefunctionundefinedset your own logic when the tab is pressed / changed

Customization (Optionals)

PropertyTypeDefaultDescription
styleViewStyledefaultset or override the style object for the main container
widthnumberScreenWidth * 0.9change the width of the main segmented control
initialIndexnumber0set the initial index
activeTextColorstring#000change the active tab's text color
activeTabColorstring#FFFchange the active tab's color
extraSpacingnumber0set extra spacing for animation horizontal value
tabStyleViewStyledefaultset or override the style object for the tab
selectedTabStyleViewStyledefaultset or override the style object for the selected tab
textStyleTextStyledefaultset or override the style object for tab's text

Future Plans

  • LICENSE
  • Write an article about the lib on Medium

Credits

Heavily inspired by these libraries:

I created this library because they're really not maintain actively and this is a pure javascript written library

Author

FreakyCoder, kurayogun@gmail.com

License

React Native Segmented Control 2 is available under the MIT license. See the LICENSE file for more info.