From b799ecf327908f4bca4638b1446ccc3459745fe4 Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Sat, 22 Apr 2017 11:01:43 -0700 Subject: [PATCH] Allow text size of Avatar to be customized along with the image size Also add some bonus styles and props to ensure centering and stop text selection --- lib/Avatar.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/Avatar.js b/lib/Avatar.js index 1126c16..7cd281b 100644 --- a/lib/Avatar.js +++ b/lib/Avatar.js @@ -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'; @@ -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, @@ -33,6 +35,8 @@ export default class Avatar extends Component { size, color, backgroundColor, + textSize, + textLineHeight, text, borderRadius, borderColor, @@ -69,7 +73,17 @@ export default class Avatar extends Component { return ( - {text} + + {text} + ); @@ -78,3 +92,11 @@ export default class Avatar extends Component { return null; } } + +const styles = StyleSheet.create({ + text: { + textAlign: 'center', + textAlignVertical: 'center', + includeFontPadding: false + } +}); \ No newline at end of file