@td-design/react-native
Version:
react-native UI组件库
39 lines (37 loc) • 994 B
JavaScript
import { Platform } from 'react-native';
import { deviceHeight, deviceWidth, ONE_PIXEL, px } from './normalize';
import renderNode from './renderNode';
/**
* 判断是否是IOS系统
*/
const isIOS = Platform.OS === 'ios';
/**
* 根据条件决定样式是否生效
* @param condition
* @param style
*/
const conditionalStyle = (condition, style) => condition ? style : {};
function hexToRgba(hex) {
let alpha = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
let c;
if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
let arr = hex.substring(1).split('');
if (arr.length == 3) {
arr = [arr[0], arr[0], arr[1], arr[1], arr[2], arr[2]];
}
c = '0x' + arr.join('');
return 'rgba(' + [c >> 16 & 255, c >> 8 & 255, c & 255].join(',') + `,${alpha})`;
}
throw new Error('Bad Hex');
}
export default {
renderNode,
px,
deviceWidth,
deviceHeight,
ONE_PIXEL,
isIOS,
conditionalStyle,
hexToRgba
};
//# sourceMappingURL=index.js.map