-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInput.js
More file actions
43 lines (34 loc) · 825 Bytes
/
Input.js
File metadata and controls
43 lines (34 loc) · 825 Bytes
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
import React, { Component } from 'react'
import { TextInput, StyleSheet } from 'react-native'
export default class Input extends Component {
state = {
text: '',
}
onChangeText = (text) => this.setState({text})
onSubmitEditing = () => {
const {onSubmitEditing} = this.props
const {text} = this.state
if (!text) return // Don't submit if empty
onSubmitEditing(text)
this.setState({text: ''})
}
render() {
const {placeholder} = this.props
const {text} = this.state
return (
<TextInput
style={styles.input}
value={text}
placeholder={placeholder}
onChangeText={this.onChangeText}
onSubmitEditing={this.onSubmitEditing}
/>
)
}
}
const styles = StyleSheet.create({
input: {
padding: 15,
height: 50,
},
})