DetectPlatform Fixed for UWP (#5182) fixes #4852
authorEmil Alipiev <emil.alipiev@gmail.com>
Thu, 21 Mar 2019 11:11:34 +0000 (04:11 -0700)
committerRui Marinho <me@ruimarinho.net>
Thu, 21 Mar 2019 11:11:34 +0000 (11:11 +0000)
* 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 <emil.alipiev@gmail.com>
* Update Xamarin.Forms.Platform.UAP/Forms.cs

Co-Authored-By: EmilAlipiev <emil.alipiev@gmail.com>
Xamarin.Forms.Platform.UAP/Forms.cs

index 794a356..c87c998 100644 (file)
@@ -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
+}