react-native-responsive-screen-font
Version:
Make React Native views responsive for all devices screens and fonts with the use of 4 simple methods.
49 lines (46 loc) • 1.29 kB
JavaScript
// packages
import * as React from "react";
import { StyleSheet, Text, View } from "react-native";
import {
widthPercentageToDP,
heightPercentageToDP,
widthPercentageToFonts,
heightPercentageToFonts,
} from "react-native-responsive-screen-font";
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<View style={styles.responsiveBox}>
<Text style={styles.text}>
This box is always of 84.5% width and 17% height.
</Text>
<Text style={styles.text}>
Test it by running this example repo in phones/ emulators with
screens of various dimensions and pixel per inch (ppi).
</Text>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "gray",
alignItems: "center",
justifyContent: "center",
},
responsiveBox: {
width: widthPercentageToDP("84.5%"),
height: heightPercentageToDP("17%"),
borderWidth: 2,
borderColor: "orange",
flexDirection: "column",
justifyContent: "space-around",
},
text: {
color: "white",
fontSize: widthPercentageToFonts("3%"), //this will give you better font results in ipad and ios also
},
});