Skip to content
This repository has been archived by the owner on Feb 4, 2021. It is now read-only.

Commit

Permalink
Avatar now accepts an Image component instead of src to allow for loc…
Browse files Browse the repository at this point in the history
…al and external images
  • Loading branch information
Ehesp committed Dec 24, 2015
1 parent 4a2b598 commit d038043
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/Avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { getColor } from './helpers';
export default class Avatar extends Component {

static propTypes = {
image: PropTypes.shape({ type: PropTypes.oneOf([Image]) }),
icon: PropTypes.string,
src: PropTypes.string,
size: PropTypes.number,
color: PropTypes.string,
backgroundColor: PropTypes.string
Expand All @@ -19,15 +19,18 @@ export default class Avatar extends Component {
};

render() {
const { icon, src, size, color, backgroundColor } = this.props;
const { image, icon, size, color, backgroundColor } = this.props;

if (src) {
return (
<Image
style={{ width: size, height: size, borderRadius: size / 2, borderColor: 'rgba(0,0,0,.1)', borderWidth: 1 }}
source={{ uri: src }}
/>
);
if (image) {
return React.cloneElement(image, {
style: {
width: size,
height: size,
borderRadius: size / 2,
borderColor: 'rgba(0,0,0,.1)',
borderWidth: 1
}
});
}

if (icon) {
Expand All @@ -43,5 +46,7 @@ export default class Avatar extends Component {
</View>
);
}

return null;
}
}

0 comments on commit d038043

Please sign in to comment.