React Native如何检查iPhone Xs Max?

时间:2018-09-26 13:56:21

标签: react-native

我正在尝试为iPhone Xs Max中的react native做一个具体案例?

这是我为react-native-iphone-x-helper中的IphoneX提供的代码的一部分

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

iPhone Xs Max的尺寸是多少,仅添加iPhone Xs Max尺寸就足够了吗?

2 个答案:

答案 0 :(得分:7)

最后我去了:

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

答案 1 :(得分:2)

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

设计本机应用程序