Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeviceInfo.isTablet returning wrong value #198

Closed
victorileaf opened this issue Aug 3, 2017 · 9 comments
Closed

DeviceInfo.isTablet returning wrong value #198

victorileaf opened this issue Aug 3, 2017 · 9 comments

Comments

@victorileaf
Copy link

victorileaf commented Aug 3, 2017

DeviceInfo.isTablet is true for both Nexus 7, Nexus 4 and Nexus 5.
check using Emulator.

@samueljseay
Copy link

If you look at the implementation of isTablet it is just checking screen sizes. There isn't afaik a truly reliable way to determine whether the device is a tablet or phone (at least for Android I don't know of one, therefore its not gonna be cross platform).

@machour
Copy link
Collaborator

machour commented Feb 3, 2018

The problem is that there is not real way in Android to tell if we're on a Tablet, and detection have become harder & harder with new phones having extra high definitions..

Anyone have an idea on how to address this? 🤔

@samueljseay
Copy link

samueljseay commented Feb 3, 2018

This looks promising: https://stackoverflow.com/a/24701063/472987 (for Android)

@machour
Copy link
Collaborator

machour commented Feb 4, 2018

Doesn't seem really reliable either, according to the comments right below :/

@mikpalm
Copy link
Contributor

mikpalm commented Feb 6, 2018

Just tried to alter this and so far it looks good. But needs alot more testing and I bet its not reliable. This is what Im doing right now.
RNDeviceModule.java

private Boolean isTablet() {
    //int layout = getReactApplicationContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
    //layout = (Configuration.SCREENLAYOUT_SIZE_LARGE || layout == Configuration.SCREENLAYOUT_SIZE_XLARGE);
    boolean layout = (getReactApplicationContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
    if (layout) {
      DisplayMetrics metrics = new DisplayMetrics();
      getCurrentActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);

      if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT
              || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH
              || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM
              || metrics.densityDpi == DisplayMetrics.DENSITY_TV
              || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) {
        return true;
      } else {
        return false;
      }
    }
    return false;
  }

Got this issue since newer phones in standard screensize works. but when the user alters there settings to higher dens it returns as istablet.

@machour
Copy link
Collaborator

machour commented Feb 6, 2018

@mikpalm could you open a PR for this so we can work/adjust the code there? Thank you mate!

@mikpalm
Copy link
Contributor

mikpalm commented Feb 6, 2018

Done. #313

@machour
Copy link
Collaborator

machour commented Feb 6, 2018

Thank you! PR #313 was opened to deal with this.

@machour machour added the has PR label Feb 6, 2018
@machour
Copy link
Collaborator

machour commented Feb 27, 2018

The PR was merged in 0.17.2, thank you again @mikpalm & @Ingibjorg !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants