Created
June 22, 2017 10:39
-
-
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
This file contains hidden or 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
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