Skip to content

Commit 45741db

Browse files
Sankhadeep RoySankhadeep Roy
authored andcommitted
merged
2 parents 0846edc + a60f2ae commit 45741db

File tree

3 files changed

+100
-6
lines changed

3 files changed

+100
-6
lines changed

Components/Widgets/Card.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* @flow */
2+
'use strict';
3+
4+
import React, {View} from 'react-native';
5+
import NativeBaseComponent from '../Base/NativeBaseComponent';
6+
import _ from 'lodash';
7+
import computeProps from '../../Utils/computeProps';
8+
9+
export default class CardNB extends NativeBaseComponent {
10+
11+
getInitialStyle() {
12+
return {
13+
card: {
14+
borderWidth: 1,
15+
borderRadius: 8
16+
}
17+
}
18+
}
19+
20+
prepareRootProps() {
21+
22+
var defaultProps = {
23+
style: this.getInitialStyle().card
24+
};
25+
26+
return computeProps(this.props, defaultProps);
27+
28+
}
29+
30+
render() {
31+
return(
32+
<View {...this.prepareRootProps()} >
33+
{this.props.children}
34+
</View>
35+
);
36+
}
37+
38+
}

Components/Widgets/ListItem.js

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/* @flow */
22
'use strict';
33

4-
import React from 'react-native';
4+
import React, {Image} from 'react-native';
55
import NativeBaseComponent from '../Base/NativeBaseComponent';
66
import _ from 'lodash';
77
import computeProps from '../../Utils/computeProps';
88
import Icon from './Icon';
99
import Text from './Text';
1010
import View from './View';
1111
import Button from './Button';
12+
import Thumbnail from './Thumbnail';
1213

1314
export default class ListItemNB extends NativeBaseComponent {
1415

@@ -21,7 +22,8 @@ export default class ListItemNB extends NativeBaseComponent {
2122
paddingLeft: 10,
2223
flex: 1,
2324
flexDirection: 'row',
24-
justifyContent: 'space-between'
25+
justifyContent: 'space-between',
26+
alignItems: 'center'
2527
},
2628
listItemDivider: {
2729
borderBottomWidth: 1,
@@ -50,31 +52,83 @@ export default class ListItemNB extends NativeBaseComponent {
5052
flex: 1,
5153
textAlign: 'right',
5254

55+
},
56+
itemSubNote: {
57+
fontSize: 15,
58+
color: '#999'
59+
},
60+
thumbnail: {
61+
62+
},
63+
fullImage: {
64+
width: 300,
65+
height: 300
5366
}
5467
}
5568
}
5669

70+
isThumbnail() {
71+
var thumbnailComponentPresent = false;
72+
React.Children.forEach(this.props.children, function (child) {
73+
if(child.type == Thumbnail)
74+
thumbnailComponentPresent = true;
75+
})
76+
77+
return thumbnailComponentPresent;
78+
}
79+
5780
getChildStyle(child) {
5881
var mergedStyle = {};
5982
if(child.type == Icon) {
6083
return _.merge(mergedStyle, this.getInitialStyle().itemIcon, child.props.style);
6184
}
6285

6386
else if(child.type == Text) {
64-
if(child.props.note)
87+
if(child.props.note && this.isThumbnail())
88+
return _.merge(mergedStyle, this.getInitialStyle().itemSubNote, child.props.style);
89+
else if(child.props.note)
6590
return _.merge(mergedStyle, this.getInitialStyle().itemNote, child.props.style);
66-
else
91+
else
6792
return _.merge(mergedStyle, this.getInitialStyle().itemText, child.props.style);
6893
}
6994

7095
else if(child.type == Button) {
7196
return _.merge(mergedStyle, this.getInitialStyle().itemButton, child.props.style);
7297
}
7398

99+
else if(child.type == Thumbnail) {
100+
return _.merge(mergedStyle, this.getInitialStyle().thumbnail, child.props.style);
101+
}
102+
103+
else if(child.type == Image && !Array.isArray(this.props.children))
104+
return _.merge(mergedStyle, this.getInitialStyle().fullImage, child.props.style);
74105
else
75106
return child.props.style;
76107
}
77108

109+
getChildProps(child) {
110+
var defaultProps = {};
111+
if(child.type == Image && !Array.isArray(this.props.children)) {
112+
defaultProps = {
113+
resizeMode: 'stretch',
114+
style: this.getChildStyle(child)
115+
}
116+
}
117+
else if(child.type == Button) {
118+
defaultProps = {
119+
small: true,
120+
style: this.getChildStyle(child)
121+
}
122+
}
123+
else {
124+
defaultProps = {
125+
style: this.getChildStyle(child)
126+
}
127+
}
128+
129+
return computeProps(child.props, defaultProps);
130+
}
131+
78132
prepareRootProps() {
79133
if(this.props.itemDivider)
80134
var defaultProps = {
@@ -93,7 +147,7 @@ export default class ListItemNB extends NativeBaseComponent {
93147

94148
renderChildren() {
95149
var newChildren = React.Children.map(this.props.children, (child) => {
96-
return React.cloneElement(child, {style: this.getChildStyle(child)})
150+
return React.cloneElement(child, this.getChildProps(child));
97151
});
98152

99153
console.log(newChildren);

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Input from './Components/Widgets/Input';
2121
import InputGroup from './Components/Widgets/InputGroup';
2222
import Icon from './Components/Widgets/Icon';
2323
import Thumbnail from './Components/Widgets/Thumbnail';
24+
import Card from './Components/Widgets/Card';
2425

2526
module.exports = {
2627
Header: Header,
@@ -41,5 +42,6 @@ module.exports = {
4142
View: View,
4243
InputGroup: InputGroup,
4344
Icon: Icon,
44-
Thumbnail: Thumbnail
45+
Thumbnail: Thumbnail,
46+
Card: Card
4547
};

0 commit comments

Comments
 (0)