-
-
Save ekzn/3fbd16a3ca4a0e6cee4c53ee4699f6d1 to your computer and use it in GitHub Desktop.
React Native Text Wrapper for default font
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
'use strict'; | |
import React, {Component} from 'react'; | |
import { | |
Text, | |
} from 'react-native'; | |
export default class AppText extends Component { | |
constructor(props) { | |
super(props) | |
// Put your default font styles here. | |
this.style = [{fontFamily: 'Helvetica', fontSize: 10}]; | |
if( props.style ) { | |
if( Array.isArray(props.style) ) { | |
this.style = this.style.concat(props.style) | |
} else { | |
this.style.push(props.style) | |
} | |
} | |
} | |
render() { return ( | |
<Text {...this.props} style={this.style}> | |
{this.props.children} | |
</Text> | |
)} | |
} |
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
'use strict'; | |
import React, {Component} from 'react'; | |
import Text from './AppText'; | |
import {View} from 'react-native'; | |
export default class Foo extends Component { | |
render() { return ( | |
<View> | |
<Text> | |
This will show in default font. | |
</Text> | |
<Text onPress={() => alert('tapped')}> | |
Properties are passed through to the rendered node, so onPress etc will work. | |
</Text> | |
<Text style={{fontSize: 40, fontFamily: 'Arial'}}> | |
Defaults can be overridden. | |
</Text> | |
</Text> | |
)} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment