Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Device Model from React Native Device Info for iPhone X

Tags:

react-native

general question here. I'm using rn-device-info library. I want to know what will be the return on console.log("Device Model", DeviceInfo.getModel()); for iPhone X? Is it "iPhone X" or "iPhone 10"?

Thanks.

like image 681
Nimila Hiranya Avatar asked Oct 18 '25 11:10

Nimila Hiranya


2 Answers

It will return iPhone X.

Source: RNDeviceInfo.m

PS: Make sure you are on the latest version of rn-device-info

like image 114
Akshet Avatar answered Oct 21 '25 09:10

Akshet


This is might be old question to answer but here is answer for people who looking for it, without installing any external libraries create file name isIphoneX.js

insert this code

import { Dimensions, Platform } from 'react-native';

export function isIphoneX() {
  const dim = Dimensions.get('window');

  return (
    // This has to be iOS
    Platform.OS === 'ios' &&

    // Check either, iPhone X or XR
    (isIPhoneXSize(dim) || isIPhoneXrSize(dim))
  );
}

export function isIPhoneXSize(dim) {
  return dim.height == 812 || dim.width == 812;
}

export function isIPhoneXrSize(dim) {
  return dim.height == 896 || dim.width == 896;
}

the code above will check if it's iphone X, Xr you can update the code as you wish just create new functions and export them and use it inside you code.

like image 38
Balalen Avatar answered Oct 21 '25 09:10

Balalen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!