Skip to content

Commit f73cba5

Browse files
author
Peter Piekarczyk
committed
add additional proptypes, update readme
1 parent d21f752 commit f73cba5

File tree

3 files changed

+97
-56
lines changed

3 files changed

+97
-56
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,20 @@ const FACES = [
3838

3939
// ...
4040

41-
<FacePile faces={FACES} additionalFaces={10} />
41+
<FacePile faces={FACES} overflow={10} />
4242

4343
```
4444

4545
## Proptypes
46+
47+
```es6
48+
faces: PropTypes.shape({
49+
imageUrl: PropTypes.string
50+
}),
51+
overflow: PropTypes.number,
52+
circleHeight: PropTypes.number,
53+
circleWidth: PropTypes.number,
54+
containerStyle: PropTypes.style,
55+
circleStyle: PropTypes.style,
56+
overflowStyle: PropTypes.styles
57+
```

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"main": "src/index.js",
66
"repository": "git@github.com:peterpme/react-native-face-pile.git",
77
"author": "Peter Piekarczyk <peterpiekarczyk@gmail.com>",
8+
"scripts": {
9+
"release": "npm version patch && npm publish && git push --tags"
10+
},
811
"keywords": [
912
"facepile",
1013
"face-pile",
@@ -17,5 +20,8 @@
1720
"peerDependencies": {
1821
"react": "^15.6.1",
1922
"react-native": "^0.46.4"
23+
},
24+
"devDependencies": {
25+
"prop-types": "^15.5.10"
2026
}
2127
}

src/index.js

Lines changed: 78 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// @flow
2-
import React from 'react'
3-
import type { StyleObj } from 'react-native/Libraries/StyleSheet/StyleSheetTypes'
4-
import { View, Text, Image, StyleSheet } from 'react-native'
2+
3+
import React, { PureComponent } from 'react';
4+
import PropTypes from 'prop-types';
5+
import type { StyleObj } from 'react-native/Libraries/StyleSheet/StyleSheetTypes';
6+
import { View, Text, Image, StyleSheet } from 'react-native';
57

68
const styles = StyleSheet.create({
79
container: {
@@ -28,7 +30,7 @@ const styles = StyleSheet.create({
2830
avatar: {
2931
width: 40,
3032
height: 40,
31-
borderRadius: 20,
33+
borderRadius: 20
3234
},
3335
extra: {
3436
backgroundColor: '#b6c0ca',
@@ -40,67 +42,88 @@ const styles = StyleSheet.create({
4042
color: '#333',
4143
fontSize: 12
4244
}
43-
})
44-
45-
function renderFace (face, index) {
46-
return (
47-
<View key={face.id || index} style={styles.circle}>
48-
<View style={styles.avatarContainer}>
49-
<Image
50-
style={styles.avatar}
51-
source={{ uri: face.imageUrl }}
52-
resizeMode='contain'
53-
/>
54-
</View>
55-
</View>
56-
)
57-
}
58-
59-
function renderoverflow (overflow) {
60-
return (
61-
<View style={styles.circle}>
62-
<View style={[styles.avatar, styles.extra]}>
63-
<Text style={styles.extraLabel}>
64-
+{overflow}
65-
</Text>
66-
</View>
67-
</View>
68-
)
69-
}
45+
});
7046

7147
type Face = {
7248
imageUrl: string,
7349
id?: string
74-
}
50+
};
7551

7652
type FacePileType = {
7753
faces: Array<Face>,
7854
overflow: number,
7955
containerStyle?: StyleObj
80-
}
56+
};
57+
58+
class FacePile extends PureComponent {
59+
static propTypes = {
60+
faces: PropTypes.shape({
61+
imageUrl: PropTypes.string
62+
}),
63+
overflow: PropTypes.number,
64+
circleHeight: PropTypes.number,
65+
circleWidth: PropTypes.number,
66+
containerStyle: PropTypes.style,
67+
circleStyle: PropTypes.style,
68+
overflowStyle: PropTypes.styles
69+
};
70+
71+
static defaultProps = {
72+
faces: [
73+
{
74+
imageUrl: 'https://lorempixel.com/200/200/people'
75+
},
76+
{
77+
imageUrl: 'https://lorempixel.com/200/203/people'
78+
},
79+
{
80+
imageUrl: 'https://lorempixel.com/200/201/people'
81+
},
82+
{
83+
imageUrl: 'https://lorempixel.com/200/202/people'
84+
}
85+
],
86+
overflow: 8
87+
};
88+
89+
_renderOverflowCircle = overflow => {
90+
const { overflowStyle } = this.props;
91+
return (
92+
<View style={styles.circle}>
93+
<View style={[styles.avatar, styles.extra, overflowStyle]}>
94+
<Text style={styles.extraLabel}>
95+
+{overflow}
96+
</Text>
97+
</View>
98+
</View>
99+
);
100+
};
81101

82-
const FacePile = ({ faces, overflow, containerStyle }: FacePileType) =>
83-
<View style={[styles.container, containerStyle]}>
84-
{renderoverflow(overflow)}
85-
{faces.map(renderFace)}
86-
</View>
102+
_renderFace = face => {
103+
const { circleStyle, circleHeight, circleWidth } = this.props
104+
if (!face.imageUrl) return null;
105+
return (
106+
<View key={face.id || index} style={styles.circle}>
107+
<View style={[styles.avatarContainer, circleStyle, { width: circleWidth, height: circleHeight }]}>
108+
<Image
109+
style={[styles.avatar, { width: circleWidth / 2, height: circleHeight / 2}]}
110+
source={{ uri: face.imageUrl }}
111+
resizeMode="contain"
112+
/>
113+
</View>
114+
</View>
115+
);
116+
};
87117

88-
FacePile.defaultProps = {
89-
faces: [
90-
{
91-
imageUrl: 'https://lorempixel.com/200/200/people'
92-
},
93-
{
94-
imageUrl: 'https://lorempixel.com/200/203/people'
95-
},
96-
{
97-
imageUrl: 'https://lorempixel.com/200/201/people'
98-
},
99-
{
100-
imageUrl: 'https://lorempixel.com/200/202/people'
101-
}
102-
],
103-
overflow: 8
118+
render() {
119+
const { faces, overflow, containerStyle } = this.props;
120+
return (
121+
<View style={[styles.container, containerStyle]}>
122+
{this._renderOverflowCircle(overflow)}
123+
{faces.map(this._renderFace)}
124+
</View>
125+
);
126+
}
104127
}
105128

106-
export default FacePile
129+
export default FacePile;

0 commit comments

Comments
 (0)