代码之家  ›  专栏  ›  技术社区  ›  Kevin Amiranoff

如何检查iphonexsmax?

  •  1
  • Kevin Amiranoff  · 技术社区  · 6 年前

    我正试图为你做一个具体的说明 iPhone Xs Max react native ?

    这就是我的代码 IphoneX react-native-iphone-x-helper

    export function isIphoneX() {
        let dimen = Dimensions.get('window');
        return (
            Platform.OS === 'ios' &&
            !Platform.isPad &&
            !Platform.isTVOS &&
            (dimen.height === 812 || dimen.width === 812)
        );
    }
    

    iPhone Xs最大 iPhone Xs最大

    2 回复  |  直到 6 年前
        1
  •  21
  •   Kevin Amiranoff    4 年前

    最后我说:

    export function isIphoneXorAbove() {
      const dimen = Dimensions.get('window');
      return (
        Platform.OS === 'ios' &&
        !Platform.isPad &&
        !Platform.isTVOS &&
        ((dimen.height === 812 || dimen.width === 812) || (dimen.height === 896 || dimen.width === 896))
      );
    }
    

    PR

    编辑:

    function isIphoneWithNotch() {
      const dimen = Dimensions.get('window');
      return (
        Platform.OS === 'ios' &&
        !Platform.isPad &&
        !Platform.isTVOS &&
        (dimen.height === 780 ||
          dimen.width === 780 ||
          dimen.height === 812 ||
          dimen.width === 812 ||
          dimen.height === 844 ||
          dimen.width === 844 ||
          dimen.height === 896 ||
          dimen.width === 896 ||
          dimen.height === 926 ||
          dimen.width === 926)
      );
    }
    
        2
  •  1
  •   David    6 年前

    你可以用 https://github.com/ptelad/react-native-iphone-x-helper 包裹。它允许您为 iPhone X, XS, XS Max & XR