fontsize react native code example
Example 1: react-native italics
<Text style={styles.bold}>I'm bold!</Text>
<Text style={styles.italic}>I'm italic!</Text>
<Text style={styles.underline}>I'm underlined!</Text>
const styles = StyleSheet.create({
bold: {fontWeight: 'bold'},
italic: {fontStyle: 'italic'},
underline: {textDecorationLine: 'underline'}
})
Example 2: color text react native
<Text
style={styles.headline}>Hi, Lunox!
</Text>
headline: {
color: 'white',
textAlign: 'center',
fontWeight: 'bold',
fontSize: 50,
backgroundColor: 'purple',
}
Look how I use it here:
https://github.com/Lunox-code/100dayscode-react.native/blob/master/App.js
Example 3: react native scaling font
<Text
numberOfLines={1}
adjustsFontSizeToFit
style={{textAlign:'center',fontSize:30}}
>
Example 4: change text size according to screen react native
import { Dimensions, Platform, PixelRatio } from 'react-native';
const {
width: SCREEN_WIDTH,
height: SCREEN_HEIGHT,
} = Dimensions.get('window');
const scale = SCREEN_WIDTH / 320 ;
export function actuatedNormalize(size) {
const newSize = size * scale
if (Platform.OS === 'ios') {
return Math.round(PixelRatio.roundToNearestPixel(newSize))
} else {
return Math.round(PixelRatio.roundToNearestPixel(newSize)) - 2
}
}
Example 5: react native font based on viewport dimensions
<View>
<Text
numberOfLines={1}
adjustsFontSizeToFit
style={{textAlign:'center',fontSize:30}}
>
{this.props.email}
</Text>
</View>