forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextInputExample.js
109 lines (99 loc) · 2.57 KB
/
TextInputExample.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* @flow */
import * as React from 'react';
import {
StyleSheet,
View,
ScrollView,
KeyboardAvoidingView,
type Theme,
} from 'react-native';
import { TextInput, HelperText, withTheme } from 'react-native-paper';
type Props = {
theme: Theme,
};
type State = {
text: string,
name: string,
outlinedText: string,
};
class TextInputExample extends React.Component<Props, State> {
static title = 'TextInput';
state = {
text: '',
name: '',
outlinedText: '',
};
_isUsernameValid = () => /^[a-zA-Z]*$/.test(this.state.name);
render() {
const {
theme: {
colors: { background },
},
} = this.props;
return (
<KeyboardAvoidingView
style={styles.wrapper}
behavior="padding"
keyboardVerticalOffset={80}
>
<ScrollView
style={[styles.container, { backgroundColor: background }]}
keyboardShouldPersistTaps={'always'}
removeClippedSubviews={false}
>
<TextInput
style={styles.inputContainerStyle}
label="Flat input"
placeholder="Type something"
value={this.state.text}
onChangeText={text => this.setState({ text })}
/>
<TextInput
disabled
style={styles.inputContainerStyle}
label="Disabled flat input"
/>
<TextInput
mode="outlined"
style={styles.inputContainerStyle}
label="Outlined input"
placeholder="Type something"
value={this.state.outlinedText}
onChangeText={outlinedText => this.setState({ outlinedText })}
/>
<TextInput
mode="outlined"
disabled
style={styles.inputContainerStyle}
label="Disabled outlined input"
/>
<View style={styles.inputContainerStyle}>
<TextInput
label="Input with helper text"
placeholder="Enter username, only letters"
value={this.state.name}
error={!this._isUsernameValid()}
onChangeText={name => this.setState({ name })}
/>
<HelperText type="error" visible={!this._isUsernameValid()}>
Error: Only letters are allowed
</HelperText>
</View>
</ScrollView>
</KeyboardAvoidingView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 8,
},
wrapper: {
flex: 1,
},
inputContainerStyle: {
margin: 8,
},
});
export default withTheme(TextInputExample);