react native font responsive code example
Example 1: react native responsive font
import { Dimensions } from 'react-native';
const { width, **fontScale** } = Dimensions.get("window");
const styles = StyleSheet.create({
fontSize: idleFontSize / **fontScale**,
});
Example 2: 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
}
}