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

feat: Add ability to override platform detection methods #19737

Closed
liamdebeasi opened this issue Oct 23, 2019 · 2 comments
Closed

feat: Add ability to override platform detection methods #19737

liamdebeasi opened this issue Oct 23, 2019 · 2 comments
Labels
package: core @ionic/core package type: feature request a new feature, enhancement, or improvement
Milestone

Comments

@liamdebeasi
Copy link
Contributor

liamdebeasi commented Oct 23, 2019

Feature Request

Ionic version:

[x] 4.x

Describe the Feature Request

The platform detection methods Ionic provides cover most use cases; however, it is not going to be possible for us to reasonably detect 100% of all devices correctly. This is particularly true for off brand Android devices that do not conform to a standard when it comes to identifying themselves on the web.

It would be good for us to allow users to override our own methods with their custom methods in case they need to handle those specific edge cases in their apps.

Describe Preferred Solution

The easiest way to do this is to let developers customize the PLATFORMS_MAP object: https://github.com/ionic-team/ionic/blob/master/core/src/utils/platform.ts#L118

I see two options for doing this:

  1. Expose a function (tentatively) called setPlatformDetection(platform: Platform, callback: any). This function will allow users to provide a platform and a detection function. Usage is as follows:
import { setPlatformDetection } from '@ionic/core';

const customAndroidFunction = (win: Window) => {
  return window.someExample === true;
}

setPlatformDetection('android', customAndroidFunction);

(Note: The any type will be replaced with the appropriate function type once that is determined)

  1. Opt for a config approach where developers specify this on app start. Ionic Angular usage is as follows:
...

IonicModule.forRoot({
  'platformDetection': {
    'android': customAndroidFunction
  }
});

...

After discussing with the team, I am leaning more towards option 2. I can see things getting a bit messy if users override the platform detection using option 1 after the app has already been initialized.

Additional Context

We might also want to consider exposing the testUserAgent and matchMedia functions that Ionic uses internally. I could see those being helpful when customizing the platform detection functions.

@ionitron-bot ionitron-bot bot added the triage label Oct 23, 2019
@liamdebeasi liamdebeasi added package: core @ionic/core package type: feature request a new feature, enhancement, or improvement labels Oct 23, 2019
@ionitron-bot ionitron-bot bot removed the triage label Oct 23, 2019
@liamdebeasi liamdebeasi added this to the 6.0.0 milestone Feb 3, 2021
@liamdebeasi liamdebeasi added type: feature request a new feature, enhancement, or improvement and removed type: feature request a new feature, enhancement, or improvement labels Jul 16, 2021
@willmartian
Copy link
Contributor

This feature has been added and will be available in the next beta release of Ionic Framework v6. 🥳

@ionitron-bot
Copy link

ionitron-bot bot commented Oct 14, 2021

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.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Oct 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: core @ionic/core package type: feature request a new feature, enhancement, or improvement
Projects
None yet
Development

No branches or pull requests

2 participants