react-native-tags-input
Advanced tools
+45
-7
@@ -10,4 +10,3 @@ import React from 'react'; | ||
| TouchableOpacity, | ||
| ViewPropTypes, | ||
| FlatList | ||
| ViewPropTypes | ||
| } from 'react-native'; | ||
@@ -74,4 +73,8 @@ | ||
| onChangeText = (text, tags, updateState, keysForTags) => { | ||
| onChangeText = (text, tags, updateState, keysForTags, keysForTagsArray) => { | ||
| if (keysForTagsArray) { | ||
| return this.onChangeText2(text, tags, updateState, keysForTagsArray) | ||
| } | ||
| let keysStr; | ||
@@ -104,2 +107,35 @@ if (typeof keysForTags === 'string') { | ||
| onChangeText2 = (text, tags, updateState, keysForTagsArray) => { | ||
| // Escaping special characters. | ||
| const keys = keysForTagsArray.map((str) => (str+'').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1")); | ||
| const regexp = new RegExp(keys.join('|')); | ||
| if (regexp.test(text)) { | ||
| if (keysForTagsArray.includes(text)) { | ||
| // The following processing is required because multiple characters may be specified as one delimiter. | ||
| let tempObject = { | ||
| tag: '', | ||
| tagsArray: tags.tagsArray, | ||
| }; | ||
| updateState(tempObject); | ||
| return this.input.clear(); | ||
| } | ||
| const tempTag = text.replace(regexp, ''); | ||
| const tempArray = tags.tagsArray.concat(tempTag); | ||
| let tempObject = { | ||
| tag: '', | ||
| tagsArray: [...new Set(tempArray)] // Deduplication | ||
| }; | ||
| updateState(tempObject); | ||
| return this.input.clear(); | ||
| } | ||
| let tempObject = { | ||
| tag: text, | ||
| tagsArray: tags.tagsArray | ||
| }; | ||
| return updateState(tempObject) | ||
| }; | ||
| deleteTag = (tagToDelete, tags, updateState) => { | ||
@@ -136,2 +172,3 @@ | ||
| keysForTag, | ||
| keysForTagsArray, | ||
| deleteElement, | ||
@@ -162,3 +199,3 @@ deleteIconStyles, | ||
| value={tags.tag} | ||
| onChangeText={text => this.onChangeText(text, tags, updateState, keysForTag)} | ||
| onChangeText={text => this.onChangeText(text, tags, updateState, keysForTag, keysForTagsArray)} | ||
| onEndEditing={() => this.onEndEditing(tags, updateState)} | ||
@@ -169,3 +206,3 @@ /> | ||
| {customElement ? customElement : null} | ||
| <FlatList style={StyleSheet.flatten([styles.tagsView, tagsViewStyle])}> | ||
| <View style={StyleSheet.flatten([styles.tagsView, tagsViewStyle])}> | ||
| {tags.tagsArray.map((item, count) => { | ||
@@ -178,3 +215,3 @@ return ( | ||
| <Text style={StyleSheet.flatten([styles.tagText, tagTextStyle])}>{item}</Text> | ||
| <TouchableOpacity onPress={() => this.deleteTag(count, tags, updateState) }> | ||
| <TouchableOpacity onPressIn={() => this.deleteTag(count, tags, updateState) }> | ||
| {deleteElement ? deleteElement : ( | ||
@@ -190,3 +227,3 @@ <Image | ||
| })} | ||
| </FlatList> | ||
| </View> | ||
| </View> | ||
@@ -206,2 +243,3 @@ ); | ||
| keysForTag: PropTypes.string, | ||
| keysForTagsArray: PropTypes.arrayOf(PropTypes.string), | ||
| containerStyle: ViewPropTypes.style, | ||
@@ -208,0 +246,0 @@ inputContainerStyle: ViewPropTypes.style, |
+1
-1
| { | ||
| "name": "react-native-tags-input", | ||
| "version": "1.0.9", | ||
| "version": "1.0.10", | ||
| "description": "Input component for React Native to add and remove tags.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
16802
8%287
12.99%