ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
50.89k stars 13.52k forks source link

feat: platform.is should accept multiple values #24033

Open davidecampello opened 2 years ago

davidecampello commented 2 years ago

Prerequisites

Describe the Feature Request

I think platform.is should accept multiple values to help avoid multiple call with or

Describe the Use Case

this.platform.is('desktop', 'mobileweb', ...) instad of this.platform.is('desktop') || this.platform.is('mobileweb')

Describe Preferred Solution

No response

Describe Alternatives

No response

Related Code

No response

Additional Information

No response

liamdebeasi commented 2 years ago

Thanks for the issue. Can you provide a use case for this feature? Also, what do you think the platform.is call should return when passing in multiple values? Would you expect it to return true only if all of the conditions are met, or would you expect it to allow for partial matching?

indraraj26 commented 2 years ago

if all are matched then it should return true otherwise if you want allow if one of the matched then you can use old way as we have been using with OR operator

davidecampello commented 2 years ago

In my case I would like to have a OR operator between all passed parameters but maybe a good solution can be have tho methods:

anyMatch(...platform: Array<Platform>): boolean
allMatch(...platform: Array<Platform>): boolean

or maybe we can call "every" and "some", like in javascript Array

But for retrocompatibility this is not a good option...

In my case I have an app that use capacitor-community/barcode-scanner and I need to open a modal instead of the plugin only if platform is desktop and mobileweb so I tought to suggest this update and generally I prefer to write a code like this.platform.is('desktop', 'mobileweb', ...) instad of this.platform.is('desktop') || this.platform.is('mobileweb') but I'm aware this is not a very important thing. I can also create a small utility in my app.

Thanks

liamdebeasi commented 2 years ago

Thanks! I can talk with the team about this feature.

liamdebeasi commented 2 years ago

I discussed this with the team, and we think this is a valuable feature to add to Ionic. No ETA on implementation, but I will update this thread when I have more to share.