From 9ba95b6a481ff0a6e6279835ab73e368c3679379 Mon Sep 17 00:00:00 2001 From: Emil Alipiev Date: Thu, 21 Mar 2019 04:11:34 -0700 Subject: [PATCH] DetectPlatform Fixed for UWP (#5182) fixes #4852 * detectplatform fixed using Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily UWP-Xbox sets TV...Surface tablets sets Desktop intead of Phone * Update Xamarin.Forms.Platform.UAP/Forms.cs Default was changed to be Unsupported Idiom Co-Authored-By: EmilAlipiev * Update Xamarin.Forms.Platform.UAP/Forms.cs Co-Authored-By: EmilAlipiev --- Xamarin.Forms.Platform.UAP/Forms.cs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/Xamarin.Forms.Platform.UAP/Forms.cs b/Xamarin.Forms.Platform.UAP/Forms.cs index 794a356..c87c998 100644 --- a/Xamarin.Forms.Platform.UAP/Forms.cs +++ b/Xamarin.Forms.Platform.UAP/Forms.cs @@ -40,18 +40,26 @@ namespace Xamarin.Forms Device.SetFlags(s_flags); Device.Info = new WindowsDeviceInfo(); - switch (DetectPlatform()) + switch (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily) { - case Windows.Foundation.Metadata.Platform.Windows: - Device.SetIdiom(TargetIdiom.Desktop); + case "Windows.Desktop": + if (Windows.UI.ViewManagement.UIViewSettings.GetForCurrentView().UserInteractionMode == + Windows.UI.ViewManagement.UserInteractionMode.Touch) + Device.SetIdiom(TargetIdiom.Tablet); + else + Device.SetIdiom(TargetIdiom.Desktop); break; - case Windows.Foundation.Metadata.Platform.WindowsPhone: + case "Windows.Mobile": Device.SetIdiom(TargetIdiom.Phone); break; + case "Windows.Xbox": + Device.SetIdiom(TargetIdiom.TV); + break; default: - Device.SetIdiom(TargetIdiom.Tablet); + Device.SetIdiom(TargetIdiom.Unsupported); break; } + ExpressionSearch.Default = new WindowsExpressionSearch(); Registrar.ExtraAssemblies = rendererAssemblies?.ToArray(); @@ -63,16 +71,7 @@ namespace Xamarin.Forms Platform.UWP.Platform.SubscribeAlertsAndActionSheets(); } - - static Windows.Foundation.Metadata.Platform DetectPlatform() - { - bool isHardwareButtonsAPIPresent = ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"); - - if (isHardwareButtonsAPIPresent) - return Windows.Foundation.Metadata.Platform.WindowsPhone; - return Windows.Foundation.Metadata.Platform.Windows; - } - + static FlowDirection GetFlowDirection() { string resourceFlowDirection = ResourceContext.GetForCurrentView().QualifierValues["LayoutDirection"]; @@ -91,4 +90,4 @@ namespace Xamarin.Forms }; } } -} \ No newline at end of file +} -- 2.7.4