-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04117da
commit 659548f
Showing
5 changed files
with
124 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* @flow */ | ||
'use strict'; | ||
|
||
import React from 'react'; | ||
import {Image} from 'react-native'; | ||
import NativeBaseComponent from '../Base/NativeBaseComponent'; | ||
import computeProps from '../../Utils/computeProps'; | ||
import _ from 'lodash'; | ||
import md5 from 'blueimp-md5'; | ||
|
||
const GRAVATAR_URI = 'https://www.gravatar.com/avatar/'; | ||
|
||
export default class GravatarNB extends NativeBaseComponent { | ||
|
||
propTypes: { | ||
email: React.PropTypes.string.isRequired, | ||
style : React.PropTypes.object, | ||
size : React.PropTypes.number, | ||
circular : React.PropTypes.bool, | ||
square : React.PropTypes.bool | ||
} | ||
|
||
getInitialStyle() { | ||
return { | ||
gravatar: { | ||
borderRadius: this.props.size ? this.props.size/2 : 15, | ||
width: this.props.size ? this.props.size : 30, | ||
height: this.props.size ? this.props.size : 30, | ||
resizeMode: this.props.contain ? 'contain' : undefined | ||
} | ||
} | ||
} | ||
|
||
prepareRootProps() { | ||
var gravatarStyle = {}; | ||
if(this.props.circular) { | ||
gravatarStyle.width = this.props.size; | ||
gravatarStyle.height = this.props.size; | ||
gravatarStyle.borderRadius = this.props.size/2; | ||
} | ||
else if(this.props.square) { | ||
gravatarStyle.width = this.props.size; | ||
gravatarStyle.height = this.props.size; | ||
gravatarStyle.borderRadius = 0; | ||
} | ||
|
||
var defaultProps = { | ||
style: _.merge(this.getInitialStyle().gravatar, gravatarStyle) | ||
}; | ||
|
||
return computeProps(this.props, defaultProps); | ||
} | ||
|
||
render() { | ||
const props = this.prepareRootProps(); | ||
|
||
const uri = GRAVATAR_URI + md5(this.props.email) + '?s='+props.style.height; | ||
return( | ||
<Image ref={c => this._root = c} {...props} source={{uri:uri}}/> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters