Skip to content

Commit eee164e

Browse files
ethansharInbal-Tish
authored andcommitted
improve TextField example screen (#618)
* improve TextField example screen * move validation and error examples to InputValidation screen
1 parent b0aa5f7 commit eee164e

File tree

8 files changed

+273
-50
lines changed

8 files changed

+273
-50
lines changed

demo/src/navigation.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {Navigation} from 'react-native-navigation';
2+
3+
export const pushScreen = ({componentId, name, title, passProps}) => {
4+
Navigation.push(componentId, {
5+
component: {
6+
name,
7+
passProps,
8+
options: {
9+
topBar: {
10+
title: {
11+
text: title
12+
}
13+
}
14+
}
15+
}
16+
});
17+
};
18+
19+
export const showModal = ({name, title, passProps}) => {
20+
Navigation.showModal({
21+
stack: {
22+
children: [
23+
{
24+
component: {
25+
name,
26+
passProps,
27+
options: {
28+
topBar: {
29+
title: {
30+
text: title
31+
}
32+
}
33+
}
34+
}
35+
}
36+
]
37+
}
38+
});
39+
};

demo/src/screens/MenuStructure.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const navigationData = {
5252
{title: 'Checkbox', tags: 'checkbox toggle controls', screen: 'unicorn.components.CheckboxScreen'},
5353
{title: 'Color Picker', tags: 'color picker control', screen: 'unicorn.components.ColorPickerScreen'},
5454
{title: 'Color Swatch', tags: 'color swatch and palette', screen: 'unicorn.components.ColorSwatchScreen'},
55-
{title: 'TextField', tags: 'text input field form', screen: 'unicorn.components.InputsScreen'},
55+
{title: 'TextField', tags: 'text input field form', screen: 'unicorn.components.TextFieldScreen'},
5656
{title: 'Picker', tags: 'picker form', screen: 'unicorn.components.PickerScreen'},
5757
{title: 'DateTimePicker', tags: 'date time picker form', screen: 'unicorn.components.DateTimePickerScreen'},
5858
{title: 'RadioButton', tags: 'radio button group controls', screen: 'unicorn.components.RadioButtonScreen'},
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React, {Component} from 'react';
2+
import {StyleSheet, ScrollView} from 'react-native';
3+
import {View, Text, TextField, Colors, Spacings} from 'react-native-ui-lib';
4+
import {Navigation} from 'react-native-navigation';
5+
6+
class CustomInputsScreen extends Component {
7+
state = {};
8+
render() {
9+
return (
10+
<ScrollView>
11+
<View padding-s5>
12+
<Text text40 marginB-s5>
13+
Custom Inputs
14+
</Text>
15+
<TextField title="Default" placeholder="Enter Text" enableErrors={false} containerStyle={styles.input}/>
16+
<TextField
17+
title="Square"
18+
placeholder="Enter Text"
19+
hideUnderline
20+
containerStyle={styles.input}
21+
style={{padding: 10, borderWidth: 1, borderColor: Colors.grey50, borderRadius: 4}}
22+
enableErrors={false}
23+
/>
24+
<TextField
25+
placeholder="Enter text"
26+
title="Rounded"
27+
text70
28+
containerStyle={styles.input}
29+
style={{
30+
backgroundColor: Colors.grey60,
31+
height: '100%',
32+
paddingHorizontal: 15,
33+
paddingVertical: 8,
34+
borderRadius: 20
35+
}}
36+
hideUnderline
37+
enableErrors={false}
38+
titleStyle={{marginLeft: 10}}
39+
/>
40+
</View>
41+
</ScrollView>
42+
);
43+
}
44+
}
45+
46+
export default CustomInputsScreen;
47+
48+
Navigation.registerComponent('unicorn.components.CustomInputsScreen', () => CustomInputsScreen);
49+
50+
const styles = StyleSheet.create({
51+
input: {
52+
marginBottom: Spacings.s4
53+
}
54+
});
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import React, {Component} from 'react';
2+
import {StyleSheet, ScrollView} from 'react-native';
3+
import {View, Text, TextField, Button, Spacings} from 'react-native-ui-lib';
4+
import {Navigation} from 'react-native-navigation';
5+
import {KeyboardAwareInsetsView} from 'react-native-keyboard-tracking-view';
6+
7+
class InputValidationsScreen extends Component {
8+
state = {
9+
useTopErrors: false
10+
};
11+
12+
toggleTopErrors = () => {
13+
this.setState({useTopErrors: !this.state.useTopErrors});
14+
};
15+
16+
render() {
17+
const {useTopErrors} = this.state;
18+
return (
19+
<View flex>
20+
<View paddingH-s5 paddingT-s5 left/>
21+
<ScrollView>
22+
<View padding-s5>
23+
<View row centerV spread marginB-s5>
24+
<Text text40 >
25+
Validations
26+
</Text>
27+
<Button
28+
size="small"
29+
label={`TopError : ${useTopErrors ? 'ON' : 'OFF'}`}
30+
outline={!useTopErrors}
31+
onPress={this.toggleTopErrors}
32+
/>
33+
</View>
34+
<TextField
35+
title="Required Field"
36+
containerStyle={styles.input}
37+
placeholder="Enter Text"
38+
validate="required"
39+
errorMessage="This is a mandatory field "
40+
useTopErrors={useTopErrors}
41+
/>
42+
<TextField
43+
title="Email"
44+
containerStyle={styles.input}
45+
placeholder="Enter valid email"
46+
validate="email"
47+
errorMessage="email is invalid"
48+
useTopErrors={useTopErrors}
49+
validateOnChange
50+
/>
51+
<TextField
52+
title="Price"
53+
containerStyle={styles.input}
54+
placeholder="Enter price"
55+
validate="price"
56+
errorMessage="Price is invalid"
57+
useTopErrors={useTopErrors}
58+
/>
59+
<TextField
60+
title="Number"
61+
containerStyle={styles.input}
62+
placeholder="Enter a Number"
63+
validate="number"
64+
errorMessage="Number is invalid"
65+
useTopErrors={useTopErrors}
66+
/>
67+
<TextField
68+
title="URL"
69+
containerStyle={styles.input}
70+
placeholder="Enter a url"
71+
validate="url"
72+
errorMessage="Url is invalid"
73+
useTopErrors={useTopErrors}
74+
/>
75+
76+
<TextField
77+
title="Required Email (2 validations)"
78+
containerStyle={styles.input}
79+
placeholder="Enter an email"
80+
validate={['required', 'email']}
81+
errorMessage={['This field is required', 'Email is invalid']}
82+
useTopErrors={useTopErrors}
83+
/>
84+
<TextField
85+
title="Custom Validation"
86+
containerStyle={styles.input}
87+
placeholder="Enter a text that starts with B"
88+
validate={value => /^B.*/.test(value)}
89+
errorMessage={'Text does not start with "B"'}
90+
useTopErrors={useTopErrors}
91+
/>
92+
</View>
93+
<KeyboardAwareInsetsView/>
94+
</ScrollView>
95+
</View>
96+
);
97+
}
98+
}
99+
100+
export default InputValidationsScreen;
101+
102+
Navigation.registerComponent('unicorn.components.InputValidationsScreen', () => InputValidationsScreen);
103+
104+
const styles = StyleSheet.create({
105+
input: {
106+
marginBottom: Spacings.s2
107+
}
108+
});

demo/src/screens/componentScreens/InputsScreen.js renamed to demo/src/screens/componentScreens/TextFieldScreen/InputsScreen.js

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import React, {Component} from 'react';
22
import {ScrollView, StyleSheet, Alert} from 'react-native';
33
import {Colors, Typography, View, Text, TextField, TextArea, Modal, Button} from 'react-native-ui-lib'; //eslint-disable-line
44
import {KeyboardAwareInsetsView} from 'react-native-keyboard-tracking-view';
5+
import {Navigation} from 'react-native-navigation';
56

6-
7-
const richText = require('../../assets/icons/richText.png');
8-
const dropDown = require('../../assets/icons/chevronDown.png');
9-
const star = require('../../assets/icons/star.png');
7+
const richText = require('../../../assets/icons/richText.png');
8+
const dropDown = require('../../../assets/icons/chevronDown.png');
9+
const star = require('../../../assets/icons/star.png');
1010
const LONG_TEXT =
1111
'Concept, edition and design direction for the editorial piece “La Forma Bruta” by the photographer' +
1212
'Martín Bollati. In this piece';
13-
const transformPrice = (value) => {
13+
const transformPrice = value => {
1414
let cleanValue;
1515
let priceText = '';
1616
if (value) {
@@ -27,12 +27,11 @@ export default class InputsScreen extends Component {
2727

2828
this.state = {
2929
error: '',
30-
topError: false,
3130
customExpandableValue: 'Custom Expandable'
3231
};
3332
}
3433

35-
onChangeText = (text) => {
34+
onChangeText = text => {
3635
let message = '';
3736
if (text === '') {
3837
message = 'This field is mandatory';
@@ -41,22 +40,17 @@ export default class InputsScreen extends Component {
4140
message = 'Please enter a valid text';
4241
}
4342
this.setState({error: message});
44-
}
45-
46-
onButtonPressed = () => {
47-
const {topError} = this.state;
48-
this.setState({topError: !topError});
49-
}
43+
};
5044

5145
onPressInfo = () => {
5246
Alert.alert('Info button pressed');
53-
}
47+
};
5448

5549
onPress = () => {
5650
this.setState({customExpandableValue: 'New Value'}, () => {
5751
this.input.toggleExpandableModal(false);
5852
});
59-
}
53+
};
6054

6155
renderExpandable = () => {
6256
return (
@@ -65,20 +59,13 @@ export default class InputsScreen extends Component {
6559
<Text marginB-20 text50>
6660
Do Whatever you want here
6761
</Text>
68-
<Button
69-
label="Close Me"
70-
onPress={this.onPress}
71-
/>
62+
<Button label="Close Me" onPress={this.onPress}/>
7263
</View>
7364
</Modal>
7465
);
75-
}
66+
};
7667

7768
render() {
78-
const {topError} = this.state;
79-
const state = topError ? 'On' : 'Off';
80-
const btnLabel = `Top Errors: ${state}`;
81-
8269
return (
8370
<View flex>
8471
<ScrollView
@@ -90,23 +77,13 @@ export default class InputsScreen extends Component {
9077
<Text style={{marginBottom: 20, marginRight: 20}} text40>
9178
Inputs
9279
</Text>
93-
<Button
94-
style={{height: 28, alignSelf: 'flex-start', marginBottom: 20}}
95-
outline={!topError}
96-
size="small"
97-
label={btnLabel}
98-
onPress={this.onButtonPressed}
99-
/>
10080

10181
<TextField
10282
text70
10383
containerStyle={{marginBottom: INPUT_SPACING}}
10484
floatingPlaceholder
105-
placeholder="FloatingPlaceholder & validator"
85+
placeholder="FloatingPlaceholder"
10686
onChangeText={this.onChangeText}
107-
validate={'required'}
108-
errorMessage={'Required field!'}
109-
useTopErrors={this.state.topError}
11087
floatOnFocus
11188
/>
11289

@@ -130,8 +107,6 @@ export default class InputsScreen extends Component {
130107
placeholder="With helperText"
131108
helperText="this is an helper text"
132109
onChangeText={this.onChangeText}
133-
error={this.state.error}
134-
useTopErrors={this.state.topError}
135110
/>
136111

137112
<TextField
@@ -151,8 +126,6 @@ export default class InputsScreen extends Component {
151126
maxLength={3}
152127
showCharacterCounter
153128
onChangeText={this.onChangeText}
154-
error={this.state.error}
155-
useTopErrors={this.state.topError}
156129
/>
157130

158131
<TextField
@@ -162,11 +135,9 @@ export default class InputsScreen extends Component {
162135
titleStyle={{fontSize: Typography.text70.fontSize}}
163136
placeholder="Multiline & titleStyle"
164137
multiline
165-
maxLength={32}
138+
maxLength={150}
166139
showCharacterCounter
167140
onChangeText={this.onChangeText}
168-
error={this.state.error}
169-
useTopErrors={this.state.topError}
170141
autoCapitalize="words"
171142
/>
172143

@@ -189,7 +160,6 @@ export default class InputsScreen extends Component {
189160
placeholder="Underline colors & error"
190161
onChangeText={this.onChangeText}
191162
error={this.state.error}
192-
useTopErrors={this.state.topError}
193163
underlineColor={{focus: Colors.purple50, error: Colors.yellow60}}
194164
/>
195165

@@ -213,7 +183,7 @@ export default class InputsScreen extends Component {
213183
containerStyle={{marginBottom: INPUT_SPACING}}
214184
placeholder="Share your story"
215185
value={
216-
"Share Your Story exists to provide spaces to hear people's stories, in order to inspire us to" +
186+
'Share Your Story exists to provide spaces to hear people\'s stories, in order to inspire us to' +
217187
'live better ones ourselves.'
218188
}
219189
multiline
@@ -262,7 +232,7 @@ export default class InputsScreen extends Component {
262232
multiline
263233
rightButtonProps={{iconSource: richText, onPress: this.onPressInfo, iconColor: Colors.red30}}
264234
/>
265-
235+
266236
<TextField
267237
text70
268238
containerStyle={{marginBottom: INPUT_SPACING}}
@@ -280,7 +250,9 @@ export default class InputsScreen extends Component {
280250
rightIconSource={dropDown}
281251
/>
282252

283-
<Text dark10 marginB-5>Text Area</Text>
253+
<Text dark10 marginB-5>
254+
Text Area
255+
</Text>
284256
<View
285257
style={{
286258
height: 150,
@@ -343,3 +315,5 @@ const styles = StyleSheet.create({
343315
marginVertical: 20
344316
}
345317
});
318+
319+
Navigation.registerComponent('unicorn.components.InputsScreen', () => InputsScreen);

0 commit comments

Comments
 (0)