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

Commit 1b4969d

Browse files
committed
clean up
1 parent 3dc20c2 commit 1b4969d

File tree

2 files changed

+54
-63
lines changed

2 files changed

+54
-63
lines changed

Tags/Input.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import styles from "./styles";
66
const Input = (props) => {
77

88
const {
9+
value,
10+
onChangeText,
11+
onSubmitEditing,
912
inputStyle,
1013
inputContainerStyle,
1114
textInputProps
@@ -16,15 +19,14 @@ const Input = (props) => {
1619
<TextInput
1720
{...textInputProps}
1821
style={[styles.textInput, inputStyle]}
19-
20-
value={props.value}
21-
onChangeText={props.onChangeText}
22-
onSubmitEditing={props.onSubmitEditing}
23-
22+
value={value}
23+
onChangeText={onChangeText}
24+
onSubmitEditing={onSubmitEditing}
2425
underlineColorAndroid="transparent"
2526
/>
2627
</View>
2728
);
29+
2830
};
2931

3032
export {Input};

Tags/index.js

Lines changed: 47 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Tags extends React.Component {
1414
tags: props.initialTags,
1515
text: props.initialText
1616
};
17-
}
17+
};
1818

1919
showLastTag = () => {
2020
this.setState(state =>
@@ -38,13 +38,12 @@ class Tags extends React.Component {
3838
};
3939

4040
onChangeText = text => {
41-
const regex = new RegExp(`^[${this.props.createTagOnString.join("")}]+$`, 'g');
4241
if (text.length === 0) {
4342
this.showLastTag();
4443
} else if (
4544
text.length > 1 &&
46-
!text.match(regex) &&
4745
this.props.createTagOnString.includes(text.slice(-1)) &&
46+
!text.match(new RegExp(`^[${this.props.createTagOnString.join("")}]+$`, 'g')) &&
4847
!(this.state.tags.indexOf(text.slice(0, -1).trim()) > -1)
4948
) {
5049
this.addTag(text.slice(0, -1));
@@ -66,73 +65,63 @@ class Tags extends React.Component {
6665
containerStyle,
6766
style,
6867
readonly,
69-
maxNumberOfTags
68+
maxNumberOfTags,
69+
tagContainerStyle,
70+
tagTextStyle,
71+
deleteTagOnPress,
72+
onTagPress,
73+
renderTag
7074
} = this.props;
7175

7276
return (
7377
<View style={[styles.container, containerStyle, style]}>
7478

75-
{this.state.tags.map(this._renderTag)}
79+
{this.state.tags.map((tag, index) => {
80+
81+
const tagProps = {
82+
tag,
83+
index,
84+
deleteTagOnPress,
85+
onPress: event => {
86+
event.persist();
87+
if (deleteTagOnPress && !readonly) {
88+
this.setState(state =>
89+
({
90+
tags: [
91+
...state.tags.slice(0, index),
92+
...state.tags.slice(index + 1)
93+
]
94+
}),
95+
() => {
96+
this.props.onChangeTags &&
97+
this.props.onChangeTags(this.state.tags);
98+
onTagPress && onTagPress(index, tag, event, true);
99+
}
100+
);
101+
} else {
102+
onTagPress && onTagPress(index, tag, event, false);
103+
}
104+
},
105+
tagContainerStyle,
106+
tagTextStyle
107+
};
108+
109+
return renderTag(tagProps);
110+
})}
76111

77112
{!readonly
78113
&& maxNumberOfTags > this.state.tags.length
79-
&& (
80-
<Input
81-
value={this.state.text}
82-
onChangeText={this.onChangeText}
83-
onSubmitEditing={this.onSubmitEditing}
84-
{...this.props}
85-
/>)
114+
&&
115+
<Input
116+
value={this.state.text}
117+
onChangeText={this.onChangeText}
118+
onSubmitEditing={this.onSubmitEditing}
119+
{...this.props}
120+
/>
86121
}
87122

88123
</View>
89124
);
90-
91-
}
92-
93-
_renderTag = (tag, index) => {
94-
95-
const {
96-
tagContainerStyle,
97-
tagTextStyle,
98-
deleteTagOnPress,
99-
onTagPress,
100-
readonly,
101-
renderTag
102-
} = this.props;
103-
104-
const onPress = event => {
105-
event.persist();
106-
if (deleteTagOnPress && !readonly) {
107-
this.setState(state =>
108-
({
109-
tags: [
110-
...state.tags.slice(0, index),
111-
...state.tags.slice(index + 1)
112-
]
113-
}),
114-
() => {
115-
this.props.onChangeTags &&
116-
this.props.onChangeTags(this.state.tags);
117-
onTagPress && onTagPress(index, tag, event, true);
118-
}
119-
);
120-
} else {
121-
onTagPress && onTagPress(index, tag, event, false);
122-
}
123-
};
124-
125-
const tagProps = {
126-
tag,
127-
index,
128-
deleteTagOnPress,
129-
onPress,
130-
tagContainerStyle,
131-
tagTextStyle
132-
};
133-
134-
return renderTag(tagProps);
135-
136125
};
137126

138127
}

0 commit comments

Comments
 (0)