Created
May 13, 2016 15:41
-
-
Save marras/48102f3d686dc71b0d5575980b150575 to your computer and use it in GitHub Desktop.
This file contains 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, { 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