Skip to content

improve TextField example screen #618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions demo/src/navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {Navigation} from 'react-native-navigation';

export const pushScreen = ({componentId, name, title, passProps}) => {
Navigation.push(componentId, {
component: {
name,
passProps,
options: {
topBar: {
title: {
text: title
}
}
}
}
});
};

export const showModal = ({name, title, passProps}) => {
Navigation.showModal({
stack: {
children: [
{
component: {
name,
passProps,
options: {
topBar: {
title: {
text: title
}
}
}
}
}
]
}
});
};
2 changes: 1 addition & 1 deletion demo/src/screens/MenuStructure.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const navigationData = {
{title: 'Checkbox', tags: 'checkbox toggle controls', screen: 'unicorn.components.CheckboxScreen'},
{title: 'Color Picker', tags: 'color picker control', screen: 'unicorn.components.ColorPickerScreen'},
{title: 'Color Swatch', tags: 'color swatch and palette', screen: 'unicorn.components.ColorSwatchScreen'},
{title: 'TextField', tags: 'text input field form', screen: 'unicorn.components.InputsScreen'},
{title: 'TextField', tags: 'text input field form', screen: 'unicorn.components.TextFieldScreen'},
{title: 'Picker', tags: 'picker form', screen: 'unicorn.components.PickerScreen'},
{title: 'DateTimePicker', tags: 'date time picker form', screen: 'unicorn.components.DateTimePickerScreen'},
{title: 'RadioButton', tags: 'radio button group controls', screen: 'unicorn.components.RadioButtonScreen'},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, {Component} from 'react';
import {StyleSheet, ScrollView} from 'react-native';
import {View, Text, TextField, Colors, Spacings} from 'react-native-ui-lib';
import {Navigation} from 'react-native-navigation';

class CustomInputsScreen extends Component {
state = {};
render() {
return (
<ScrollView>
<View padding-s5>
<Text text40 marginB-s5>
Custom Inputs
</Text>
<TextField title="Default" placeholder="Enter Text" enableErrors={false} containerStyle={styles.input}/>
<TextField
title="Square"
placeholder="Enter Text"
hideUnderline
containerStyle={styles.input}
style={{padding: 10, borderWidth: 1, borderColor: Colors.grey50, borderRadius: 4}}
enableErrors={false}
/>
<TextField
placeholder="Enter text"
title="Rounded"
text70
containerStyle={styles.input}
style={{
backgroundColor: Colors.grey60,
height: '100%',
paddingHorizontal: 15,
paddingVertical: 8,
borderRadius: 20
}}
hideUnderline
enableErrors={false}
titleStyle={{marginLeft: 10}}
/>
</View>
</ScrollView>
);
}
}

export default CustomInputsScreen;

Navigation.registerComponent('unicorn.components.CustomInputsScreen', () => CustomInputsScreen);

const styles = StyleSheet.create({
input: {
marginBottom: Spacings.s4
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import React, {Component} from 'react';
import {StyleSheet, ScrollView} from 'react-native';
import {View, Text, TextField, Button, Spacings} from 'react-native-ui-lib';
import {Navigation} from 'react-native-navigation';
import {KeyboardAwareInsetsView} from 'react-native-keyboard-tracking-view';

class InputValidationsScreen extends Component {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you want to add an useTopErrors example? Maybe a toggle button to switch between the top and the bottom error like in the input screen?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

state = {
useTopErrors: false
};

toggleTopErrors = () => {
this.setState({useTopErrors: !this.state.useTopErrors});
};

render() {
const {useTopErrors} = this.state;
return (
<View flex>
<View paddingH-s5 paddingT-s5 left/>
<ScrollView>
<View padding-s5>
<View row centerV spread marginB-s5>
<Text text40 >
Validations
</Text>
<Button
size="small"
label={`TopError : ${useTopErrors ? 'ON' : 'OFF'}`}
outline={!useTopErrors}
onPress={this.toggleTopErrors}
/>
</View>
<TextField
title="Required Field"
containerStyle={styles.input}
placeholder="Enter Text"
validate="required"
errorMessage="This is a mandatory field "
useTopErrors={useTopErrors}
/>
<TextField
title="Email"
containerStyle={styles.input}
placeholder="Enter valid email"
validate="email"
errorMessage="email is invalid"
useTopErrors={useTopErrors}
validateOnChange
/>
<TextField
title="Price"
containerStyle={styles.input}
placeholder="Enter price"
validate="price"
errorMessage="Price is invalid"
useTopErrors={useTopErrors}
/>
<TextField
title="Number"
containerStyle={styles.input}
placeholder="Enter a Number"
validate="number"
errorMessage="Number is invalid"
useTopErrors={useTopErrors}
/>
<TextField
title="URL"
containerStyle={styles.input}
placeholder="Enter a url"
validate="url"
errorMessage="Url is invalid"
useTopErrors={useTopErrors}
/>

<TextField
title="Required Email (2 validations)"
containerStyle={styles.input}
placeholder="Enter an email"
validate={['required', 'email']}
errorMessage={['This field is required', 'Email is invalid']}
useTopErrors={useTopErrors}
/>
<TextField
title="Custom Validation"
containerStyle={styles.input}
placeholder="Enter a text that starts with B"
validate={value => /^B.*/.test(value)}
errorMessage={'Text does not start with "B"'}
useTopErrors={useTopErrors}
/>
</View>
<KeyboardAwareInsetsView/>
</ScrollView>
</View>
);
}
}

export default InputValidationsScreen;

Navigation.registerComponent('unicorn.components.InputValidationsScreen', () => InputValidationsScreen);

const styles = StyleSheet.create({
input: {
marginBottom: Spacings.s2
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import React, {Component} from 'react';
import {ScrollView, StyleSheet, Alert} from 'react-native';
import {Colors, Typography, View, Text, TextField, TextArea, Modal, Button} from 'react-native-ui-lib'; //eslint-disable-line
import {KeyboardAwareInsetsView} from 'react-native-keyboard-tracking-view';
import {Navigation} from 'react-native-navigation';


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

this.state = {
error: '',
topError: false,
customExpandableValue: 'Custom Expandable'
};
}

onChangeText = (text) => {
onChangeText = text => {
let message = '';
if (text === '') {
message = 'This field is mandatory';
Expand All @@ -41,22 +40,17 @@ export default class InputsScreen extends Component {
message = 'Please enter a valid text';
}
this.setState({error: message});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is a dedicated screen for validations why not clean this screen from all error examples to keep it simple?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. So you want to merge it like that or after the cleanup?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I'll make it more simple in the future, for now I move the error/validation examples

}

onButtonPressed = () => {
const {topError} = this.state;
this.setState({topError: !topError});
}
};

onPressInfo = () => {
Alert.alert('Info button pressed');
}
};

onPress = () => {
this.setState({customExpandableValue: 'New Value'}, () => {
this.input.toggleExpandableModal(false);
});
}
};

renderExpandable = () => {
return (
Expand All @@ -65,20 +59,13 @@ export default class InputsScreen extends Component {
<Text marginB-20 text50>
Do Whatever you want here
</Text>
<Button
label="Close Me"
onPress={this.onPress}
/>
<Button label="Close Me" onPress={this.onPress}/>
</View>
</Modal>
);
}
};

render() {
const {topError} = this.state;
const state = topError ? 'On' : 'Off';
const btnLabel = `Top Errors: ${state}`;

return (
<View flex>
<ScrollView
Expand All @@ -90,23 +77,13 @@ export default class InputsScreen extends Component {
<Text style={{marginBottom: 20, marginRight: 20}} text40>
Inputs
</Text>
<Button
style={{height: 28, alignSelf: 'flex-start', marginBottom: 20}}
outline={!topError}
size="small"
label={btnLabel}
onPress={this.onButtonPressed}
/>

<TextField
text70
containerStyle={{marginBottom: INPUT_SPACING}}
floatingPlaceholder
placeholder="FloatingPlaceholder & validator"
placeholder="FloatingPlaceholder"
onChangeText={this.onChangeText}
validate={'required'}
errorMessage={'Required field!'}
useTopErrors={this.state.topError}
floatOnFocus
/>

Expand All @@ -130,8 +107,6 @@ export default class InputsScreen extends Component {
placeholder="With helperText"
helperText="this is an helper text"
onChangeText={this.onChangeText}
error={this.state.error}
useTopErrors={this.state.topError}
/>

<TextField
Expand All @@ -151,8 +126,6 @@ export default class InputsScreen extends Component {
maxLength={3}
showCharacterCounter
onChangeText={this.onChangeText}
error={this.state.error}
useTopErrors={this.state.topError}
/>

<TextField
Expand All @@ -162,11 +135,9 @@ export default class InputsScreen extends Component {
titleStyle={{fontSize: Typography.text70.fontSize}}
placeholder="Multiline & titleStyle"
multiline
maxLength={32}
maxLength={150}
showCharacterCounter
onChangeText={this.onChangeText}
error={this.state.error}
useTopErrors={this.state.topError}
autoCapitalize="words"
/>

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

Expand All @@ -213,7 +183,7 @@ export default class InputsScreen extends Component {
containerStyle={{marginBottom: INPUT_SPACING}}
placeholder="Share your story"
value={
"Share Your Story exists to provide spaces to hear people's stories, in order to inspire us to" +
'Share Your Story exists to provide spaces to hear people\'s stories, in order to inspire us to' +
'live better ones ourselves.'
}
multiline
Expand Down Expand Up @@ -262,7 +232,7 @@ export default class InputsScreen extends Component {
multiline
rightButtonProps={{iconSource: richText, onPress: this.onPressInfo, iconColor: Colors.red30}}
/>

<TextField
text70
containerStyle={{marginBottom: INPUT_SPACING}}
Expand All @@ -280,7 +250,9 @@ export default class InputsScreen extends Component {
rightIconSource={dropDown}
/>

<Text dark10 marginB-5>Text Area</Text>
<Text dark10 marginB-5>
Text Area
</Text>
<View
style={{
height: 150,
Expand Down Expand Up @@ -343,3 +315,5 @@ const styles = StyleSheet.create({
marginVertical: 20
}
});

Navigation.registerComponent('unicorn.components.InputsScreen', () => InputsScreen);
Loading