1234567891011121314151617181920212223242526272829303132333435363738 |
- let {Dimensions,StatusBar,Platform,PixelRatio} = require('react-native');
- let {width,scale,height,fontScale} = Dimensions.get("window");
- let isIOS = Platform.OS == "ios";
- let statusBarHeight = isIOS? 20: StatusBar.currentHeight;
- let pixelRatio = PixelRatio;
- fontScale = scale;
- const widthScale = width / 375;
- const heightScale = height / 667;
- /*
- * 设计稿元素宽度(px) / 设计稿总宽度(px) = 元素的宽度(dp) / 屏幕的总宽度(dp)
- */
- export default Dimensions = {
- get:Dimensions.get,
- screenWidth:width,
- screenHeight:height,
- screenScale:scale,
- width:width,
- height:height,
- scale:scale,
- fontScale:fontScale,
- statusBarHeight:statusBarHeight,
- contentHeight:height-statusBarHeight,
- pixelRatio: pixelRatio,
- getFontSize:function(size){
- return size*fontScale;
- },
- getWidth:function(px){
- return width * px /375;
- },
- getHeight:function(px){
- return width / 375 * px ;
- },
- /* px转dp */
- getDp: px => PixelRatio.roundToNearestPixel(px),
- size:{
- "1":1*fontScale
- }
- }
|