-
-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from galio-org/dev
v0.7.0
- Loading branch information
Showing
19 changed files
with
515 additions
and
184 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
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,109 @@ | ||
import React from 'react'; | ||
import { View, Text, StyleSheet, Image, ViewPropTypes } from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import { withGalio } from 'theme'; | ||
|
||
const Avatar = ({ | ||
source, | ||
size, | ||
label, | ||
labelColor, | ||
backgroundColor, | ||
labelStyle, | ||
imageProps, | ||
imageStyle, | ||
containerStyle, | ||
styles, | ||
theme, | ||
}) => { | ||
const getContainerStyle = () => { | ||
return { | ||
width: size, | ||
height: size, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
borderRadius: size / 2, | ||
}; | ||
}; | ||
|
||
const getLabelContainerStyle = () => { | ||
return { | ||
...StyleSheet.absoluteFillObject, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
borderRadius: size / 2, | ||
}; | ||
}; | ||
|
||
const renderImage = () => { | ||
if (source) { | ||
return ( | ||
<Image | ||
style={[getContainerStyle(), StyleSheet.absoluteFillObject, imageStyle]} | ||
{...{ source }} | ||
{...imageProps} | ||
/> | ||
); | ||
} | ||
return null; | ||
}; | ||
|
||
const labelContainerStyle = [ | ||
getLabelContainerStyle(), | ||
source && styles.labelContainerWithInset, | ||
{ backgroundColor: backgroundColor || theme.COLORS.MUTED }, | ||
]; | ||
|
||
const labelTextStyle = [ | ||
{ fontSize: size * 0.32 }, | ||
styles.labelText, | ||
labelColor && { color: labelColor }, | ||
labelStyle || {}, | ||
]; | ||
|
||
return ( | ||
<View style={[getContainerStyle(), containerStyle]}> | ||
<View style={labelContainerStyle}> | ||
{label && ( | ||
<Text numberOfLines={1} style={labelTextStyle}> | ||
{label} | ||
</Text> | ||
)} | ||
</View> | ||
{renderImage()} | ||
</View> | ||
); | ||
}; | ||
|
||
Avatar.defaultProps = { | ||
size: 50, | ||
}; | ||
|
||
Avatar.propTypes = { | ||
label: PropTypes.string, | ||
labelColor: PropTypes.string, | ||
size: PropTypes.number, | ||
source: PropTypes.oneOfType([PropTypes.object, PropTypes.number]), | ||
backgroundColor: PropTypes.string, | ||
imageProps: PropTypes.object, | ||
imageStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array, PropTypes.number]), | ||
containerStyle: ViewPropTypes.style, | ||
styles: PropTypes.any, | ||
theme: PropTypes.any, | ||
}; | ||
|
||
const styles = theme => | ||
StyleSheet.create({ | ||
labelContainerWithInset: { | ||
top: 1, | ||
right: 1, | ||
bottom: 1, | ||
left: 1, | ||
}, | ||
labelText: { | ||
color: theme.COLORS.BLACK, | ||
backgroundColor: 'transparent', | ||
}, | ||
}); | ||
|
||
export default withGalio(Avatar, styles); |
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
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
Oops, something went wrong.