Skip to content

Instantly share code, notes, and snippets.

@marras
Created May 13, 2016 15:41
Show Gist options
  • Save marras/48102f3d686dc71b0d5575980b150575 to your computer and use it in GitHub Desktop.
Save marras/48102f3d686dc71b0d5575980b150575 to your computer and use it in GitHub Desktop.
import React, { View, Text, StyleSheet } from 'react-native';
var MY_TEXT_REF = "MyText"
class MyText extends React.Component {
static propTypes = {
bold: React.PropTypes.bool,
children: React.PropTypes.node,
style: React.PropTypes.instanceOf(StyleSheet),
}
static defaultProps = {
bold: false,
}
setNativeProps(props: Object) {
this.refs[MY_TEXT_REF].setNativeProps(props);
}
defaultTextStyle() {
if(this.props.bold)
return styles.bold;
else
return styles.regular;
}
render() {
return (
<Text ref={MY_TEXT_REF} style={[this.defaultTextStyle(), this.props.style]}>{this.props.children}</Text>
);
}
}
var styles = StyleSheet.create({
regular: {
fontFamily: 'Montserrat',
},
bold: {
fontFamily: 'Montserrat-Bold',
},
});
module.exports = MyText;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment