@uiw/react-native
Version:
UIW for React Native
37 lines (35 loc) • 883 B
JavaScript
import { Platform } from 'react-native';
import { deviceHeight, deviceWidth, ONE_PIXEL, px } from './normalize';
// import rddNode from './rddNode';
/**
* 判断是否是IOS系统
*/
const isIOS = Platform.OS === 'ios';
/**
* 根据条件决定样式是否生效
* @param condition
* @param style
*/
const conditionalStyle = (condition, style) => condition ? style : {};
function hexToRgba(hex, alpha = 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 {
// rddNode,
px,
deviceWidth,
deviceHeight,
ONE_PIXEL,
isIOS,
conditionalStyle,
hexToRgba
};