androidiosreact-nativetabletscreen-resolution

React native check if tablet or screen in inches


I've established a different render logic for tablets and mobile devices. I was wondering if there is a way to get the screen size in inches or maybe even any module to automatically detect if the device is a tablet or not.

The reason I am not using the dimensions api directly to get the screen resolution is that there are many android tablets with lower resolution than many of their mobile counterparts.

Thanks.


Solution

  • Based on @martinarroyo's answer, a way to go about it use the react-native-device-info package.

    However the android implementation is based on screen resolution. That can be a problem as there are many tablet devices with a lower resolution than many mobile devices and this can cause problems.

    The solution I will be using and am suggesting is use react-native-device-info for apple devices and for android devices go with a simple ratio logic of the type:

    function isTabletBasedOnRatio(ratio){
    
    if(ratio > 1.6){
        return false;
    }else{
        return true;
    }
    
    }
    

    This is not a perfect solution but there are many small tablets with phonelike ratios as well or even phablets ( android is blurry) and this solutions is inclusive towards those as well.