1.0.2 • Published 5 years ago

react-native-tag-group v1.0.2

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

react-native-tag-group

npm.io npm.io

A simple Tag component that supports both single and multiple selection.

Get Started

Installation

npm i react-native-tag-group --save

TagGroup Usage

import TagGroup from 'react-native-tag-group';

// ...

render() {
  return (
    <TagGroup 
      ref={ref => this.tagGroup = ref}
      source={['One', 'Two', 'Three']}
      onSelectedTagChange={(selected) => { this.setState({selected}); }}
    />
  );
}

TagGroup Props

PropsTypeDescription
styleView stylecontainer's style
sourcearraysource array, usually a string array.
singleChoiceModeboolonly allow select one Tag at one time. Default false.
onSelectedTagChangefunctioncallback after Tag(s) pressed, the parameter is a string array[], or (stringValue, selectedIndex) when set singleChoiceMode to true.
tintColorstringset the border color and background color when Tag is selected.
tagStyle/activeTagStyleView styleset the Tag's style before and after selected.
textStyle/activeTextStyleText styleset the Tag's text style before and after selected.
touchableOpacitybooluse TouchableOpacity instead of TouchableWithoutFeedback.

Methods

select(index)

Select Tag at the index, this WON'T invoke onSelectedTagChange callback.

unselect(index)

Unselect Tag at the index, this WON'T invoke onSelectedTagChange callback.

getSelectedIndex()

Get the index array of the selected Tag(s), return -1 if no Tag is selected.

Tag Usage

Tag can also be used as a simple button, for example:

import {Tag} from 'react-native-tag-group';

// ...

<Tag 
  text={'Button Text'}
  tagStyle={styles.buttonContainer}
  textStyle={styles.buttonText}
  onPress={this.onTagPress}
  touchableOpacity
/>

// ...

onTagPress = () => {
 console.log('Hello world!')
}

Tag Props

PropsTypeDescription
tintColorstringTag's border color, you can also cusotomize it with tagStyle prop.
tagStyleView styleTag style.
textStyleText styleTag's text style.
onPressfunctioncallback function when Tag is pressed.
touchableOpacitybooluse TouchableOpacity instead of TouchableWithoutFeedback.

For more information please check the example.