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
Conversation
…higher dp and screensizes returns as tablet, needs further testing.
@Ingibjorg thank you for reaching out! We need more testing as mentioned by Mikael. |
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. |
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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? 🙏
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Ew, sorry I thought that |
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes fixing.
Thank you both 🙌 I'll test this PR tomorrow and will ship it in 0.17.2 |
Co-authored-by: Mikael Palm <mikael@flashguru.se>
Changed the nature of IsTablet for Android, since newer devices with higher dp and screensizes returns as tablet, needs further testing.