import React, { Component,PropTypes } from 'react';
import { Dimensions,PixelRatio,Platform,StatusBar,View } from 'react-native';
let props = {};
export default class Resolution {
static get(useFixWidth = true) {
return useFixWidth ? {
...props.fw
} : {
...props.fh
}
}

static setDesignSize(dwidth = 750, dheight = 1336, dim = "window") {
let designSize = {
width: dwidth,
height: dheight
};

let navHeight = Platform.OS === 'android' ? StatusBar.currentHeight : 0;
let pxRatio = PixelRatio.get(dim);
let {
  width,
  height
} = Dimensions.get(dim);
if (dim != "screen") height -= navHeight;
let w = PixelRatio.getPixelSizeForLayoutSize(width);
let h = PixelRatio.getPixelSizeForLayoutSize(height);

let fw_design_scale = designSize.width / w;
fw_width = designSize.width;
fw_height = h * fw_design_scale;
fw_scale = 1 / pxRatio / fw_design_scale;

let fh_design_scale = designSize.height / h;
fh_width = w * fh_design_scale;
fh_height = designSize.height;
fh_scale = 1 / pxRatio / fh_design_scale;

props.fw = {
  width: fw_width,
  height: fw_height,
  scale: fw_scale,
  navHeight
};
props.fh = {
  width: fh_width,
  height: fh_height,
  scale: fh_scale,
  navHeight
};

console.log("winSize", JSON.stringify({
  width,
  height
}))
console.log("winPixelSize", JSON.stringify({
  width: w,
  height: h
}))
console.log("pxRatio", pxRatio)
console.log("fixWidth", JSON.stringify(props.fw))
console.log("fixHeight", JSON.stringify(props.fh))

}

static FixWidthView = (p) => {
let {
width,
height,
scale,
navHeight
} = props.fw;
return ( <
View {
...p
}
style = {
[p.style, {
marginTop: navHeight,
width: width,
height: height,
transform: [{
translateX: -width * .5
},
{
translateY: -height * .5
},
{
scale: scale
},
{
translateX: width * .5
},
{
translateY: height * .5
}
]
}]
}
/>
);
};

static FixHeightView = (p) => {
let {
width,
height,
scale,
navHeight
} = props.fh;
return ( <
View {
...p
}
style = {
[p.style, {
marginTop: navHeight,
width: width,
height: height,
transform: [{
translateX: -width * .5
},
{
translateY: -height * .5
},
{
scale: scale
},
{
translateX: width * .5
},
{
translateY: height * .5
}
]
}]
}
/>
);
};
};
//init
Resolution.setDesignSize();

最新文章

  1. JavaScript学习总结(三)——this、原型、javascript面向对象
  2. java基础-多线程执行
  3. Mac OS 电脑播放 iPhone音乐
  4. Linux phpbb论坛的安装(中文版)
  5. 网页中的超链接&lt;a&gt;标签
  6. java webservice的多种实现方法汇总
  7. Android批量插入数据到SQLite数据库
  8. UVA 507 - Jill Rides Again 动态规划
  9. MYSQL设计优化
  10. android之wifi开发
  11. HTML5 3D翻书效果(双面效应)
  12. User Browsing Model简介
  13. sys.argv向脚本中传递参数
  14. 520. Detect Capital
  15. html中几种常见长度单位介绍
  16. Unity 用ml-agents机器学习造个游戏AI吧(1)(Windows环境配置)
  17. 吴恩达机器学习笔记53-高斯分布的算法(Algorithm of Gaussian Distribution)
  18. [物理学与PDEs]第1章第7节 媒质中的 Maxwell 方程组 7.2 媒质交界面上的条件
  19. MySQL没有备份怎么恢复被drop的表(利用undrop-for-innodb)
  20. [Python设计模式] 第28章 男人和女人——访问者模式

热门文章

  1. 用go写爬虫服务并发请求,限制并发数
  2. abstract class
  3. 一致性 hash 算法( consistent hashing )及java实现
  4. FPGA浮点数定点数的处理
  5. [LC] 300. Longest Increasing Subsequence
  6. 微信小游戏排行榜页滚动查看排行榜(canvas指定区域溢出滚动,懒渲染)
  7. &lt;SCOI2009&gt;粉刷匠の思路
  8. (二)一个很好用的自动生成工具——mybatis generator
  9. java中的URLEncoder和URLDecoder类;中文在地址栏中的处理
  10. 以后的IT路还很长(1)