xxxxxxxxxx
import React from 'react';
import { View, Text, Dimensions, StyleSheet } from 'react-native';
const App = () => {
const windowWidth = Dimensions.get('window').width;
// Function to calculate responsive font size based on window width
const getResponsiveFontSize = (size) => {
const baseSize = 16; // Base font size for normal screens
const ratio = size / 375; // Ratio of current screen width to base screen width (375)
// Calculate responsive font size
const responsiveSize = Math.round(baseSize * ratio);
return responsiveSize;
};
return (
<View style={styles.container}>
<Text style={[styles.text, { fontSize: getResponsiveFontSize(20) }]}>
Hello, world!
</Text>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
text: {
fontFamily: 'Arial',
fontWeight: 'bold',
},
});
export default App;
xxxxxxxxxx
<Text
numberOfLines={1}// add this
adjustsFontSizeToFit// add this
style={{textAlign:'center',fontSize:30}}
>
xxxxxxxxxx
import { Dimensions } from 'react-native';
const { width, **fontScale** } = Dimensions.get("window");
const styles = StyleSheet.create({
fontSize: idleFontSize / **fontScale**,
});
xxxxxxxxxx
import { Dimensions, Platform, PixelRatio } from 'react-native';
const {
width,
height,
} = Dimensions.get('window');
export function normalize(size, multiplier = 2) {
const scale = (width / height) * multiplier;
const newSize = size * scale;
return Math.round(PixelRatio.roundToNearestPixel(newSize));
}