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

Allow text size of Avatar to be customized along with the image size #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions lib/Avatar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {Component, PropTypes} from "react";
import {View, Image, Text} from "react-native";
import {StyleSheet, View, Image, Text} from "react-native";
import Icon from './Icon';
import { getColor } from './helpers';

Expand All @@ -9,6 +9,8 @@ export default class Avatar extends Component {
image: PropTypes.shape({ type: PropTypes.oneOf([Image]) }),
icon: PropTypes.string,
size: PropTypes.number,
textSize: PropTypes.number,
textLineHeight: PropTypes.number,
color: PropTypes.string,
backgroundColor: PropTypes.string,
text: PropTypes.string,
Expand All @@ -33,6 +35,8 @@ export default class Avatar extends Component {
size,
color,
backgroundColor,
textSize,
textLineHeight,
text,
borderRadius,
borderColor,
Expand Down Expand Up @@ -69,7 +73,17 @@ export default class Avatar extends Component {
return (
<View style={{ flex: 1 }}>
<View style={{ width: size, height: size, borderRadius: borderRadius, backgroundColor: getColor(backgroundColor), alignItems:'center', justifyContent: 'center' }}>
<Text style={{ color: getColor(color) }}>{text}</Text>
<Text
suppressHighlighting
style={[
styles.text,
{ color: getColor(color) },
textSize && { fontSize: textSize },
textLineHeight && { lineHeight: textLineHeight }]
}
>
{text}
</Text>
</View>
</View>
);
Expand All @@ -78,3 +92,11 @@ export default class Avatar extends Component {
return null;
}
}

const styles = StyleSheet.create({
text: {
textAlign: 'center',
textAlignVertical: 'center',
includeFontPadding: false
}
});