@@ -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