/**
 * @flow
 * Created by shiyunjie on 2018/7/11.
 */


import { Dimensions, Platform, PixelRatio } from 'react-native';
//import type { ConnectionType } from '@react-native-community/netinfo';
const { width } = Dimensions.get('window');

const basePx = Platform.OS === 'ios' ? 750 : 720;

export const Px2Dp = function px2dp(px: number): number {
  const layoutSize = (px / basePx) * width;

  return PixelRatio.roundToNearestPixel(layoutSize);
};

export const getNetInfoStatus = (netInfo: any) => {
  const { type } = netInfo;
  return {
    isConnect: type.toUpperCase() === 'WIFI' || type.toUpperCase() === 'CELLULAR',
    isWifi: type.toUpperCase() === 'WIFI',
    isCellular: type.toUpperCase() === 'CELLULAR',
  };
};

export const findPopKey = (routes: Array, pageName) => {
  let key = '';
  if (routes.length > 0) {
    const tag = routes.find(route => route.routeName === pageName);
    key = tag.key;
  }
  return key;
};

export const RandomNumBoth = (Min,Max) => {

  const Range = Max - Min;

  const Rand = Math.random();

  const num = Min + Math.round(Rand * Range); //四舍五入

  return num;

};
