[TIMOB-10492] MobileWeb: Need a way to determine if the browser is on tablet or handset
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2017-06-26T22:23:51.000+0000 |
Affected Version/s | Release 3.0.0 |
Fix Version/s | n/a |
Components | MobileWeb |
Labels | api |
Reporter | Russell McMahon |
Assignee | Chris Barber |
Created | 2012-08-18T21:08:35.000+0000 |
Updated | 2018-04-04T23:20:33.000+0000 |
Subtle distinction worth noting: we can determine if the device is handset or is not a handset. This means that tablets and desktop browsers will be lumped together.
Bryan, that sounds absolutely fine for alloy's purposes. Out of curiosity, hat type of measurement will you be performing to determine the form factor?
We are looking at the screen width. Because of historical reasons, handheld devices always have a reported width (when viewed in portrait) of 320, and every tablet device we tested has a width greater than about 450 IIRC. Landscape has a width slightly smaller due to window chrome, so we basically do:
Are the height and width measurements affected by screen density in mobileweb? Density made things especially tricky when finding a solution for this on Android.
Height and width measurements are not affected by density on handheld devices, but are on tablets and desktops.
Currently in Alloy I do. iOS gets a certain value based on Ti.Platform.osname being either 'iphone' or 'ipad'. Android gets a certain value based on a custom module, which will be replaced by Ti.Platform.Android.physicalSizeCategory. Mobileweb is currently checked by simply measuring the height and width of the device. The current calculation looks like this:
This isn't exactly as consistent as iOS and Android so the nature of this ticket was to see if the Mobileweb crew could devise a more reliable method to determine the device size. If a better solution cannot be achieved, we will continue to use the above method. Also, if the above method looks inaccurate, please provide feedback.
@Tony Try setting your min a lot lower. I found that 400 was a better value. Every last phone that I tested reported a width of exactly 320 in portrait, and a height that was a little less in landscape. That should give you better results. The method you are using is the only one available, and is how we would have implemented it in Mobile Web. Nit pick: I would call it isPhone and remove the negation because your detection code really detects if it is a phone, or something else that isn't a phone (which includes tablets, desktops, and everything else).
@Bryan thanks for the help there. I'll adjust the measurements. The snippet above doesn't quite give the whole context of how these values are used, but I can assure you your concerns with the negation are handled appropriately. As for the naming, we will probably keep it as is for now, but in future versions of Alloy, a more precise "size" identification will probably be in order.
@Tony Perhaps I wasn't clear...I have no problem with the negation, just the name. Using the name isTablet is disingenuous because that does not accurately represent what the device is. I would say it's better to use !isPhone in conditionals than isTablet. Same logic, just a better name :).
Resolving as "Won't Fix" as MobileWeb has been deprecated.
Closing as will not fix.