Skip to content

Instantly share code, notes, and snippets.

@jkomyno
Created June 22, 2017 10:39
Show Gist options
  • Save jkomyno/12667dfaf0d1f032458302cbbf7045d6 to your computer and use it in GitHub Desktop.
Save jkomyno/12667dfaf0d1f032458302cbbf7045d6 to your computer and use it in GitHub Desktop.
React Native's Text wrapper which allows to define easily a global font for the application
import React from 'react';
import PropTypes from 'prop-types';
import {
Text,
StyleSheet,
ViewPropTypes,
} from 'react-native';
const baseStyle = StyleSheet.create({
fontFamily: 'Helvetica', // your font here
fontSize: 14,
});
const AppText = ({ style, children, ...props }) => {
let newStyle;
if (Array.isArray(style)) {
newStyle = [baseStyle, ...style];
} else {
newStyle = [baseStyle, style];
}
return (
<Text {...props} style={newStyle}>
{children}
</Text>
);
};
AppText.propTypes = {
children: PropTypes.node.isRequired,
style: ViewPropTypes.style,
};
AppText.defaultProps = {
style: {},
};
export default AppText;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment