Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.

Commit 2c8c9a1

Browse files
authored
Merge branch 'master' into master
2 parents 3514314 + 8b0e7bd commit 2c8c9a1

File tree

6 files changed

+32
-26
lines changed

6 files changed

+32
-26
lines changed

CONTRIBUTORS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Federico Martín Alconada Verzini (https://github.com/fedealconada)
22
Havens (https://github.com/havenS)
3-
Michael O'Connor Havens (https://github.com/seeocon)
3+
Dajaffe (https://github.com/dajaffe)
4+
Michael O'Connor Havens (https://github.com/seeocon)

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ into a tag when a space or comma is entered.
1111
## Installation
1212

1313
```terminal
14-
npm install react-native-tags
14+
npm install --save react-native-tags
1515
```
1616

1717
```terminal
@@ -20,7 +20,7 @@ yarn add react-native-tags
2020

2121
## Usage
2222

23-
```javascript
23+
```jsx
2424
import React from "react";
2525
import Tags from "react-native-tags";
2626

@@ -44,7 +44,8 @@ const UselessComponent = () => (
4444
| initialTags | ['the', 'initial', 'tags'] |
4545
| onChangeTags | Fires when tags are added or removed |
4646
| maxNumberOfTags | integer: up to you (mandatory) |
47-
| readonly | Removes the TextInput |
47+
| onTagPress | Fires when tags are pressed |
48+
| readonly | Tags cannot be modified |
4849
| containerStyle | Style |
4950
| style | Style (`containerStyle` alias) |
5051
| inputStyle | Style |

Tags/Tag.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,28 @@ import { View, Text, TextInput, TouchableOpacity } from "react-native";
44

55
import styles from "./styles";
66

7-
const Tag = ({ label, onPress, tagContainerStyle, tagTextStyle }) => (
8-
<TouchableOpacity style={[styles.tag, tagContainerStyle]} onPress={onPress}>
9-
<Text style={[styles.tagLabel, tagTextStyle]}>{label}</Text>
10-
</TouchableOpacity>
11-
);
7+
const Tag = ({ label, onPress, tagContainerStyle, tagTextStyle, readonly }) => {
8+
const tagText = <Text style={[styles.tagLabel, tagTextStyle]}>{label}</Text>;
9+
10+
if (readonly) {
11+
return (
12+
<View style={[styles.tag, tagContainerStyle]}>
13+
{tagText}
14+
</View>
15+
)
16+
} else {
17+
return (
18+
<TouchableOpacity style={[styles.tag, tagContainerStyle]} onPress={onPress}>
19+
{tagText}
20+
</TouchableOpacity>
21+
)
22+
}
23+
}
1224

1325
Tag.propTypes = {
1426
label: PropTypes.string.isRequired,
15-
onPress: PropTypes.func
27+
onPress: PropTypes.func,
28+
readonly: PropTypes.bool
1629
};
1730

1831
export default Tag;

Tags/index.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@ class Tags extends React.Component {
1515
};
1616
}
1717

18-
static getDerivedStateFromProps(nextProps, prevState) {
19-
if (
20-
nextProps.initialTags === prevState.initialTags &&
21-
nextProps.initialText === prevState.initialText
22-
) {
23-
return null;
24-
}
25-
return {
26-
tags: nextProps.initialTags,
27-
text: nextProps.initialText
28-
};
29-
}
30-
3118
componentWillReceiveProps(props) {
3219
const { initialTags = [], initialText = " " } = props;
3320

@@ -92,7 +79,11 @@ class Tags extends React.Component {
9279
<Tag
9380
key={i}
9481
label={tag}
95-
onPress={() => this.arraySplice(tag)}
82+
onPress={e => {
83+
this.arraySplice(tag)
84+
this.props.onTagPress(i, tag, e)
85+
}}
86+
readonly={this.props.readonly}
9687
tagContainerStyle={this.props.tagContainerStyle}
9788
tagTextStyle={this.props.tagTextStyle}
9889
/>

Tags/styles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default StyleSheet.create({
99

1010
textInputContainer: {
1111
flex: 1,
12-
width: 100,
12+
minWidth: 100,
1313
height: 32,
1414
margin: 4,
1515
borderRadius: 16,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-tags",
3-
"version": "1.2.1",
3+
"version": "1.3.0",
44
"description": "Tag input component for React Native",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)