I know with React Native that we have the ability to determine whether iOS or Android is being run using the Platform
module, but how can we determine what device i
I use this solution: https://stackoverflow.com/a/48709199/2400373
My solution final is this:
import { Platform } from "react-native";
Dispositivo() {
if (Platform.isPad == true) {
return(
<Text>test</Text>
)
}
Then I call this function:
{this.Dispositivo()}
You can roughly determine what iOS device is being used without any external dependencies... First query Platform.OS
then the Dimensions module allows you to query the device for screen dimensions which can be translated to devices: http://iosres.com/
$ npm install react-native-device-detection --save
$ react-native link
if(Device.isIos) {
}
if(Device.isTablet) {
}
If you're looking for a way to do that without including 3rd party libraries (like react-native-device-info) you can also do:
import { NativeModules } from 'react-native';
const { PlatformConstants } = NativeModules;
const deviceType = PlatformConstants.interfaceIdiom;
deviceType
can take the values: phone
, pad
, tv
, carplay
and unknown
.
As of 9.02.2018 there is also
import { Platform } from 'react-native'
Platform.isPad // boolean
Mind that (as of now) it has no android counterpart.
You should be able to get that information from the module react-native-device-info
https://github.com/rebeccahughes/react-native-device-info