Skip to content

Rethink how we do platform detection #17631

Closed

Description

@liamdebeasi

Feature Request

Ionic version:

[x] 4.x

Describe the Feature Request

Platform detection in Ionic has worked fairly well for some time, but as the types of devices have diversified, I think it's time we rethink how we do platform detection. In particular, devices such as larger tablets are sometimes getting misclassified as desktop devices and some of the other detection methods are either a bit flimsy or hard to test.

Describe Preferred Solution

  1. Discuss what should be considered mobile. From what I've seen with a number of Android Tablets, they are not considered "mobile" (i.e. the word "mobile" is not in tablet user agents, but it is in phone user agents). We have a check called isMobile that returns true if any-pointer: coarse in matchMedia. Touch screens count as a coarse pointer, so touch screen laptops would be considered mobile here.

  2. Rewrite detection methods in a more "future-proof" way. I realize this is a difficult thing to do, but it would be good to write these methods in a way that will hold up over time. For example, the isTablet method has not held up over time because we now have tablets that exceed the dimensions of what we test for (ex: iPad Pro).

  3. Add detection for desktop platforms. This is more for when we add desktop support, but it would be great to be able to detect macOS, Windows, Linux, etc. Right now we have isDesktop which wouldn't give that kind of information.

Describe Alternatives
I created a PR #17630 for better handling of tablet detection, but it's not perfect. The purpose of that PR was to add support for some of the larger tablets (iPad Pro, large Android tablets, etc).

Related Code

Check out: https://github.com/matthewhudson/current-device
It's not a perfect library, but I think it does a pretty good job of covering its bases in terms of platform detection. It probably does more than we really need, but I think it would be worthwhile to look at.

https://stackoverflow.com/questions/5341637/how-do-detect-android-tablets-in-general-useragent
https://webmasters.googleblog.com/2011/03/mo-better-to-also-detect-mobile-user.html
https://developers.chrome.com/multidevice/user-agent

Safari on iPadOS now serves up the macOS Safari user agent as part of its "desktop class browsing" change: https://medium.com/@pixelthing/safari-on-ipados13-a-web-devs-guide-c31b34236e61

Activity

  1. added
    type: feature request
    and removed on Feb 27, 2019
  2. liamdebeasi commented on Mar 20, 2019

    @liamdebeasi
    ContributorAuthor

    other issues to note:

  3. alek-aleksandrov commented on Mar 27, 2019

    @alek-aleksandrov

    If it is relevant: for anyone using the current-device package to cover your bases instead of platform, it will conflict with the cordova plugin Device. Current-device and cordova Device both store information on the window.device property, so it causes issues if trying to use both. Warning to anyone who found this and perhaps if used to replace functionality.

  4. added this to the Next milestone on Jul 29, 2019
  5. rossholdway commented on Aug 1, 2019

    @rossholdway
    Contributor

    When running Ionic (latest version 4.7.1) iPadOS displays using the Android style :/

  6. liamdebeasi commented on Oct 18, 2019

    @liamdebeasi
    ContributorAuthor

    After discussion with the team, we have decided to keep the overall platform detection as is. It's not realistically possible to account for 100% of Android devices, so we're going to opt to make smaller improvements as we find them rather than a massive overhaul.

    Additionally, we have fixed the iPadOS bug in Ionic 4.9.1. Thanks!

  7. ionitron-bot commented on Nov 17, 2019

    @ionitron-bot

    Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

  8. locked and limited conversation to collaborators on Nov 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: coretype: feature request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions