font size in react native code example
Example 1: react native scaling font
<Text
numberOfLines={1}// add this
adjustsFontSizeToFit// add this
style={{textAlign:'center',fontSize:30}}
>
Example 2: text size react native
fontSize: 24
Example 3: color text react native
// Some code....
<Text
// Topic 2: Text Style
style={styles.headline}>Hi, Lunox!
</Text>
// Some code....
headline: {
color: 'white', // <-- The magic
textAlign: 'center', // <-- The magic
fontWeight: 'bold',
fontSize: 50,
backgroundColor: 'purple',
}
// Some code....
Look how I use it here:
https://github.com/Lunox-code/100dayscode-react.native/blob/master/App.js
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');
// based on iphone 5s's scale
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>