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

[XF] Xamarin has deprecated OnPlatform #1025

Closed
brianlagunas opened this issue Apr 18, 2017 · 12 comments
Closed

[XF] Xamarin has deprecated OnPlatform #1025

brianlagunas opened this issue Apr 18, 2017 · 12 comments
Labels

Comments

@brianlagunas
Copy link
Member

Since Xamarin has marked OnPlatform obsolete, we need to update Prism to remove the deprecated methods in favor of the new APIs.

http://motzcod.es/post/159463651162/device-os-xamarin-forms-obsolete-runtime-os

http://motzcod.es/post/159684940967/important-onplatform-changes-xamarin-forms?utm_content=bufferf80db&utm_medium=social&utm_source=twitter.com&utm_campaign=buffer

@dansiegel
Copy link
Member

Agreed but there is another change coming with OnPlatform which is the introduction of Default like the following:

<OnPlatform x:TypeArguments="string" Default="Foo">
    <On Platform="UWP, WinPhone" Value="Bar" />
</OnPlatform>

@brianlagunas
Copy link
Member Author

I'm not sure the Prism API's will have to change, only the implementation.

@dansiegel
Copy link
Member

Actually we never actually use OnPlatform in the registration extensions. We do however use the Device.OS which was also deprecated.

@brianlagunas
Copy link
Member Author

What about the IDeviceService?

@dansiegel
Copy link
Member

forgot all about that ;)

@brianlagunas
Copy link
Member Author

Since Xamarin has changed the way OnPlatform works (XAML friendly only) and added a new RuntimePlatform property of type string, this is what I am thinking.

First create an Enum that wraps the string property of RuntimePlatform.

	public enum RuntimePlatform
	{
		Android,
		iOS,
		Windows, //2.3.4
		WinPhone,
		//WinRT, //2.3.5
		//UWP, //2.3.5
		Unknown
	}

Then in the IDeviceService deprecate the OnPlatform methods and add a new property of type RuntimePlatform Enum

		/// <summary>
		/// Gets the Platform (OS) that Xamarin.Forms is working on.
		/// </summary>
		RuntimePlatform RuntimePlatform { get; }

Next deprecate the RegisterTypeForNavigationOnPlatform methods for the containers. This means that you will now be required to manually check the Device.RuntimePlatform property value to register different views based on the result.

Thoughts?

@brianlagunas
Copy link
Member Author

brianlagunas commented May 16, 2017

Please check out PR #1043 to see if this is an acceptable solution to the deprecation of the OnPlatform API.

Notable changes:

Add new Enum to replace the string-based RuntimePlatform:

	public enum RuntimePlatform
	{
		Android,
		iOS,
		macOS,
		Tizen,
		UWP,
		WinPhone,
		WinRT,
		Unknown
	}

IDeviceService

  • deprecated OnPlatform methods
  • added DeviceRuntimePlatform property - this mimics the XF API and returns a string
  • added RuntimePlatform property which returns an Enum of type RuntimePlatform and wraps the XF string-based values

RegisterTypeForNavigationOnPlatform Extensions

  • deprecated the RegisterTypeForNavigationOnPlatform signature that requires explicit platform parameters
  • added new signature that accepts new IPlatform objects
    Example:
Container.RegisterTypeForNavigationOnPlatform<MainPage, MainPageViewModel>("Main",
     new Platform<MainPage_Android>(RuntimePlatform.Android),
     new Platform<MainPage_iOS>(RuntimePlatform.iOS));

I would like your feedback on this new API.

@mackayn
Copy link

mackayn commented May 16, 2017

Hi Brian,

API changes make sense to me. I take it UWP will return when running on Windows10 etc or Windows 10 on a mobile device?

@mackayn
Copy link

mackayn commented May 16, 2017

Just curious how this will play with Forms 2.3.4 as macOS is only supported in 2.3.5-pre?

Does it just return unknown?

@brianlagunas
Copy link
Member Author

@mackayn not sure, I haven't fully tested their API. This is mimicking Xamairn.Forms API exactly as-is.

@dansiegel
Copy link
Member

@mackayn since this is abstracting away using the XF Device class, the result should vary based on the version of XF that you use. So with 2.3.4 you'll never get macOS or UWP.

@lock
Copy link

lock bot commented Jan 30, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants