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

fix: enhance isTablet() on Android #313

Merged
merged 4 commits into from Feb 27, 2018

Conversation

mikpalm
Copy link
Contributor

@mikpalm mikpalm commented Feb 6, 2018

Changed the nature of IsTablet for Android, since newer devices with higher dp and screensizes returns as tablet, needs further testing.

…higher dp and screensizes returns as tablet, needs further testing.
@machour machour changed the title Android isTablet fix: enhance isTablet() on Android Feb 6, 2018
@Ingibjorg
Copy link

Ingibjorg commented Feb 26, 2018

@mikpalm and @machour how is this coming along? The PR is tagged with "help wanted". How can I help?

@machour
Copy link
Collaborator

machour commented Feb 26, 2018

@Ingibjorg thank you for reaching out! We need more testing as mentioned by Mikael.
Do you have a failing isTablet() test that is fixed by this PR?

@mikpalmen
Copy link
Contributor

Can be tested on almost any newer android. Change the resolution from standard to high. Then logout the response from isTablet. it will give you true. when this fix is not applied. I have only tried it on 2 android phones but on Emulators for tablets and more phones.

Copy link
Collaborator

@machour machour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get this PR ready meanwhile, two small things to change please.

|| metrics.densityDpi == DisplayMetrics.DENSITY_TV
|| metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) {
return true;
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else can be dropped, false is returned at the end of the function

@@ -90,8 +90,21 @@ private Boolean isEmulator() {
}

private Boolean isTablet() {
int layout = getReactApplicationContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
return layout == Configuration.SCREENLAYOUT_SIZE_LARGE || layout == Configuration.SCREENLAYOUT_SIZE_XLARGE;
boolean layout = (getReactApplicationContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if Configuration.SCREENLAYOUT_SIZE_LARGE is 3 and SCREENLAYOUT_SIZE_XLARGE; is 4, I wouldn't rely on that as we never know what may be added in the future..

Can you switch back to testing both values? 🙏

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the unnecessary else. What do you meen by switching back to test both. Im doing bigger than or equal?

 >= Configuration.SCREENLAYOUT_SIZE_LARGE;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int layout = getReactApplicationContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;

if (layout != Configuration.SCREENLAYOUT_SIZE_LARGE && layout != Configuration.SCREENLAYOUT_SIZE_XLARGE) {
  return false;
}

// rest of your code, without the if (layout)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@machour
Copy link
Collaborator

machour commented Feb 26, 2018

Ew, sorry I thought that needs further testing was referring to this PR :)

return 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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a build error on this line: error: cannot find symbol DisplayMetrics. Did you forget to import android.util.DisplayMetrics?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes fixing.

@machour
Copy link
Collaborator

machour commented Feb 26, 2018

Thank you both 🙌

I'll test this PR tomorrow and will ship it in 0.17.2

@machour machour merged commit 8b7ddac into react-native-device-info:master Feb 27, 2018
machour added a commit that referenced this pull request Mar 1, 2018
Co-authored-by: Mikael Palm <mikael@flashguru.se>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants