I've created a Bottom Tab Navbar fro my React Native App. The icons I'm using are imported images.
The question is: How do I make the icons have the correct size across all devices without hardcoding the values for width and height?
Right now, the values are hardcoded but I'm sure that this is not the best practice:
return <Image style={{ width: 30, height: 30 }} source={iconName}/>;
I've also tried to do this alternatively by importing Dimensions
but the icons don't look right no matter what I put in the * x
:
import { Dimensions } from 'react-native';
const windowWidth = Dimensions.get('window').width;
const windowHeight = Dimensions.get('window').height;
....
return <Image style={{ width: windowWidth * 0.1, height: windowHeight * 0.05 }} source={iconName}/>;
Any ideas? Or is it going to be ok if I leave the hardcoded values?