Skip to content

Instantly share code, notes, and snippets.

@ssomnoremac
Last active January 20, 2017 15:39
Show Gist options
  • Save ssomnoremac/c45135ca3b607533c321863b44fea6f0 to your computer and use it in GitHub Desktop.
Save ssomnoremac/c45135ca3b607533c321863b44fea6f0 to your computer and use it in GitHub Desktop.
import React from 'react';
import RN from 'react-native';
// http://stackoverflow.com/questions/32947036/how-to-set-font-size-for-different-ios-devices-in-react-native
import { getCorrectFontSizeForScreen } from '../services/Design';
const RNText = RN.Text;
const Platform = RN.Platform;
const FONTS = Platform.OS === 'ios' ? {
'light': 'AvenirNext-Light',
'regular':'AvenirNext-Regular',
'medium': 'AvenirNext-Medium',
'bold': 'AvenirNext-Bold',
} : {
'light': 'AvenirNext_light',
'regular':'AvenirNext_regular',
'medium': 'AvenirNext_medium',
'bold': 'AvenirNext_bold',
};
const Text = (props) => {
const {
type = 'regular',
lines = 1,
color,
style,
center,
right,
transparent,
} = props;
const textAlign = center ? 'center' : right ? 'right' : null;
const fontSize = props.fontSize ? getCorrectFontSizeForScreen(props.fontSize) : getCorrectFontSizeForScreen(12);
const backgroundColor = transparent ? 'transparent' : null
return(
<RNText
style={[{fontFamily: FONTS[type], fontSize, textAlign, color, backgroundColor}, style]}
numberOfLines={lines}
>
{props.children}
</RNText>
);
}
export default Text;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment