Skip to content

Commit c7a92fe

Browse files
authored
Update of the react native components (#207)
* Update to react-native-element 1.x + add parser func for int + keyboardType func + remove actions.pop() that's display state update errors in render * Update Show added proptype + mapstate
1 parent 151bd87 commit c7a92fe

File tree

6 files changed

+41
-30
lines changed

6 files changed

+41
-30
lines changed

templates/react-native/components/foo/Create.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ class Create extends Component {
1515

1616
onSubmit = values => {
1717
this.props.create(values);
18-
Actions.{{{lc}}}List();
18+
Actions.pop();
1919
delayRefresh();
2020
};
2121

2222
render() {
2323

24-
if (this.props.created) return Actions.pop();
25-
2624
const {viewStyle, textStyle} = styles;
2725

2826
return (

templates/react-native/components/foo/Form.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,63 @@ import React, { Component } from 'react';
22
import { Field, reduxForm } from 'redux-form';
33
import { View } from 'react-native';
44
import {
5-
FormLabel,
6-
FormInput,
7-
FormValidationMessage,
5+
Input,
86
Button,
97
} from 'react-native-elements';
108

119

1210
class Form extends Component {
1311

1412
renderField(data) {
15-
const hasError = data.meta.touched && !!data.meta.error;
13+
1614
data.input.value = data.input.value.toString();
15+
16+
let keyboard = data.type === "number" ? keyboard = "numeric" : keyboard = "default"
17+
1718
return (
1819
<View>
19-
<FormLabel labelStyle={ {color: 'gray', fontSize: 20} }>
20-
{data.input.name}
21-
</FormLabel>
22-
<FormInput containerStyle={ {flexDirection:'row'} }
23-
inputStyle={ {color: 'black', flex:1} }
20+
<Input
21+
labeltStyle={ {color: 'gray', flex:1} }
2422
{...data.input}
2523
step={data.step}
2624
required={data.required}
2725
placeholder={data.placeholder}
2826
id={`{{{lc}}}_${data.input.name}`}
29-
multiline={true}
30-
keyboardType='numeric'
27+
errorMessage={data.meta.error}
28+
keyboardType={keyboard}
29+
label={data.input.name}
3130
/>
32-
{hasError &&
33-
<FormValidationMessage>{data.meta.error}</FormValidationMessage> }
3431
</View>
3532
);
3633
}
3734

35+
intParser = (value) => {
36+
if(isNaN(value)) {
37+
value
38+
}
39+
else if(this.props.initialValues) {
40+
if ((isNaN(value)) && (typeof value === 'string')){
41+
value
42+
} else if(value) {
43+
return parseInt(value, 10)
44+
} else{
45+
value
46+
}
47+
}
48+
else {
49+
return parseInt(value, 10)
50+
}
51+
return value
52+
}
53+
3854
render() {
3955
const {handleSubmit, mySubmit} = this.props;
4056

4157
return (
4258
<View style={ {backgroundColor: 'white', paddingBottom: 20} }>
4359
{{#each formFields}}
4460
<Field component={this.renderField} name="{{{name}}}" type="{{{type}}}"
45-
placeholder="{{{description}}}"{{#if required}} required={true}{{/if}} />
61+
placeholder="{{{description}}}"{{#if required}} required={true}{{/if}} parse={this.intParser} value="" />
4662
{{/each}}
4763
<Button buttonStyle={styles.button}
4864
title='SAVE'

templates/react-native/components/foo/List.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { Component } from 'react';
22
import { connect } from 'react-redux';
33
import PropTypes from 'prop-types';
44
import { ScrollView, View, Text } from 'react-native';
5-
import { List, ListItem } from 'react-native-elements';
5+
import { ListItem, Icon } from 'react-native-elements';
66
import { Actions } from 'react-native-router-flux';
77
import Spinner from '../Spinner';
88
import { list, reset } from '../../actions/{{{lc}}}/list';
@@ -36,7 +36,9 @@ class ListComponent extends Component {
3636
return (
3737
<ListItem
3838
key={Math.random()}
39-
onPressRightIcon={() => ListComponent.show(item['@id'])}
39+
rightIcon={
40+
<Icon name='eye' onPress={() => ListComponent.show(item['@id'])}
41+
reverse={true} type='font-awesome' color='#3faab4'/>}
4042
subtitle={
4143
<View>
4244
<View style={viewList}>

templates/react-native/components/foo/Show.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { Component } from 'react';
22
import { connect } from 'react-redux';
33
import PropTypes from 'prop-types';
44
import { ScrollView, View, Text } from 'react-native';
5-
import { Card, List, ListItem, SocialIcon } from 'react-native-elements';
5+
import { Card, ListItem, SocialIcon } from 'react-native-elements';
66
import { Actions } from 'react-native-router-flux';
77
import Spinner from '../Spinner';
88
import { retrieve, reset } from '../../actions/{{{lc}}}/show';
@@ -51,7 +51,6 @@ class Show extends Component {
5151
subtitleStyle={ {color: 'black', fontSize: 16} }
5252
titleStyle={ {color: 'gray', fontSize: 16, paddingBottom: 10} }
5353
key={value}
54-
hideChevron={true}
5554
title={title}
5655
subtitle={Array.isArray(value) ? value.length.toString() : value}
5756
subtitleNumberOfLines={100}
@@ -87,9 +86,8 @@ class Show extends Component {
8786
render() {
8887

8988
if (this.props.loading) return <Spinner size="large"/>;
90-
if (this.props.deleted) return Actions.pop();
9189

92-
const item = this.props.retrieved;
90+
const item = this.props.updated ? this.props.updated : this.props.retrieved;
9391

9492
const {viewStyle, textStyleAlert } = styles;
9593

@@ -98,14 +96,12 @@ class Show extends Component {
9896
<ScrollView>
9997
{item &&
10098
<Card title="{{{title}}}">
101-
<List title="title">
10299
{Show.renderRow('id', item['@id'])}
103100
{{#each fields}}
104101
{{#ifNotResource reference }}
105102
{Show.renderRow('{{{name}}}', item['{{{name}}}'])}
106103
{{/ifNotResource}}
107104
{{/each}}
108-
</List>
109105
</Card>
110106
}
111107
{this.props.deleteLoading && <View style={viewStyle}><Spinner size='large'/></View>}
@@ -133,6 +129,7 @@ const mapStateToProps = (state) => {
133129
deleteError: state.{{{lc}}}.del.error,
134130
deleteLoading: state.{{{lc}}}.del.loading,
135131
deleted: state.{{{lc}}}.del.deleted,
132+
update: state.{{{lc}}}.update.updated
136133
};
137134
};
138135

@@ -179,7 +176,8 @@ Show.propTypes = {
179176
showModal:PropTypes.bool,
180177
refresh:PropTypes.number,
181178
id:PropTypes.string,
182-
list: PropTypes.func.isRequired
179+
list: PropTypes.func.isRequired,
180+
updated: PropTypes.object
183181
};
184182

185183
export default connect(mapStateToProps, mapDispatchToProps)(Show);

templates/react-native/components/foo/Update.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ class Update extends Component {
2929

3030
render() {
3131

32-
if (this.props.deleted) return Actions.pop();
33-
3432
const item = this.props.updated ? this.props.updated : this.props.retrieved;
3533

3634
const {viewStyle, textStyleAlert, textStyleSuccess} = styles;
@@ -101,7 +99,7 @@ Update.propTypes = {
10199
update: PropTypes.func.isRequired,
102100
reset: PropTypes.func.isRequired,
103101
id: PropTypes.string,
104-
created:PropTypes.func
102+
created:PropTypes.object
105103
};
106104

107105
export default connect(mapStateToProps, mapDispatchToProps)(Update);

templates/react-native/routes/foo.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export default [
1717
<Scene key="{{{lc}}}Create" component={Create}
1818
title="Add a new {{{lc}}}"/>,
1919
<Scene key="{{{lc}}}Show" component={Show}
20-
title="{{{title}}}"
2120
leftTitle="< List of {{{title}}}s"
2221
onLeft={() => {
2322
Actions.pop();

0 commit comments

Comments
 (0)