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
68const 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
7147type Face = {
7248 imageUrl : string ,
7349 id ?: string
74- }
50+ } ;
7551
7652type 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