-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
80 lines (69 loc) · 2.36 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React, { Component } from 'react'
import { View, StyleSheet, Text, TextInput, Button } from 'react-native'
import TagInput from './src/Components/TagInput'
var outArray = [] //Generic Array to help updating the items received into the state
class App extends Component {
state = {
item: '',
itemsArray: [],
deniedEntry: false //Boolean state to prevent blank entries
}
addItem = () => {
outArray.push(this.state.item)
this.setState({ itemsArray: outArray })
this.setState({ item: '' })
}
updateArray = items => {
outArray = items
this.setState({ itemsArray: items })
}
render() {
return (
<View style={styles.container}>
<Text style={{ fontSize: 30, color: '#06BEB6', textAlign: 'center', paddingBottom: 50 }}>Tag Input</Text>
<TextInput
underlineColorAndroid='#7A7A7A'
placeholder={this.state.deniedEntry ? 'You need to insert an item!' : 'Insert a tag...'}
placeholderTextColor={this.state.deniedEntry ? '#F00' : '#707070' }
style={this.state.deniedEntry ? [styles.input, styles.deniedColor] : styles.input}
value={this.state.item}
onChangeText={value => {
this.state.deniedEntry
? this.setState({ deniedEntry: !this.state.deniedEntry })
: null
this.setState({ item: value })
}}
/>
<View style={{ padding: 5 }}>
<Button
title='Insert'
color='#06BEB6'
onPress={() => {
if (this.state.item != '') {
this.addItem()
} else {
this.setState({ deniedEntry: true })
}
}}
/>
</View>
<TagInput
items={[...this.state.itemsArray]}
updateArray={this.updateArray}
/>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1
},
input: {
paddingHorizontal: 5,
paddingBottom: 5,
justifyContent: 'center',
fontSize: 20
},
})
export default App