From 230001171c2013c6afc048ece351784a37a913d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez=20Ruiz?= Date: Thu, 3 Feb 2022 13:06:47 +0100 Subject: [PATCH 01/13] Remove unsupported targets in Device class --- .../Core/src/Windows/WindowsPlatformServices.cs | 2 +- .../CarouselItemsGallery.cs | 2 +- .../CollectionViewGalleries/ExampleTemplates.cs | 2 +- .../GroupedReorderingGallery.cs | 2 +- .../UngroupedReorderingGallery.cs | 2 +- .../CustomSwipeItemGallery.cs | 2 +- .../SwipeViewGalleries/SwipeItemIconGallery.cs | 2 +- .../Controls.Sample/Pages/Core/DevicePage.xaml | 17 +++++++++++++++++ .../Pages/Core/DevicePage.xaml.cs | 10 ++++++++++ .../samples/Controls.Sample/Pages/MainPage.xaml | 10 +--------- .../Controls.Sample/ViewModels/CoreViewModel.cs | 3 +++ src/Controls/src/Core/Device.cs | 9 +++++---- .../MarkupExtensions/OnPlatformExtension.cs | 17 ++++++++++++----- 13 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 src/Controls/samples/Controls.Sample/Pages/Core/DevicePage.xaml create mode 100644 src/Controls/samples/Controls.Sample/Pages/Core/DevicePage.xaml.cs diff --git a/src/Compatibility/Core/src/Windows/WindowsPlatformServices.cs b/src/Compatibility/Core/src/Windows/WindowsPlatformServices.cs index 46c8daa45832..cb65d5f064b9 100644 --- a/src/Compatibility/Core/src/Windows/WindowsPlatformServices.cs +++ b/src/Compatibility/Core/src/Windows/WindowsPlatformServices.cs @@ -101,7 +101,7 @@ public Color GetNamedColor(string name) return ((global::Windows.UI.Color)Microsoft.UI.Xaml.Application.Current?.Resources[name]).ToColor(); } - public string RuntimePlatform => Device.UWP; + public string RuntimePlatform => Device.WinUI; public void StartTimer(TimeSpan interval, Func callback) { diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/CarouselViewGalleries/CarouselItemsGallery.cs b/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/CarouselViewGalleries/CarouselItemsGallery.cs index 4d471ea6a102..7818a4a9444b 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/CarouselViewGalleries/CarouselItemsGallery.cs +++ b/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/CarouselViewGalleries/CarouselItemsGallery.cs @@ -200,7 +200,7 @@ static string DefaultFontFamily() case Device.iOS: fontFamily = "Ionicons"; break; - case Device.UWP: + case Device.WinUI: fontFamily = "Assets/Fonts/ionicons.ttf#ionicons"; break; case Device.Android: diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/ExampleTemplates.cs b/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/ExampleTemplates.cs index f74cba7bc659..cf210d450e0f 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/ExampleTemplates.cs +++ b/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/ExampleTemplates.cs @@ -552,7 +552,7 @@ static string DefaultFontFamily() case Device.iOS: fontFamily = "Ionicons"; break; - case Device.UWP: + case Device.WinUI: fontFamily = "Assets/Fonts/ionicons.ttf#ionicons"; break; case Device.Android: diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/ReorderingGalleries/GroupedReorderingGallery.cs b/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/ReorderingGalleries/GroupedReorderingGallery.cs index 2290bc977ae5..88e3cb5315aa 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/ReorderingGalleries/GroupedReorderingGallery.cs +++ b/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/ReorderingGalleries/GroupedReorderingGallery.cs @@ -33,7 +33,7 @@ public GroupedReorderingGallery(IItemsLayout itemsLayout) Text = "Reordering of grouped sources is not supported on Windows!", FontSize = 24, FontAttributes = FontAttributes.Bold, - IsVisible = (Device.RuntimePlatform == Device.UWP), + IsVisible = (Device.RuntimePlatform == Device.WinUI), BackgroundColor = Colors.Red }; diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/ReorderingGalleries/UngroupedReorderingGallery.cs b/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/ReorderingGalleries/UngroupedReorderingGallery.cs index 4fc029af6d19..4e18b3c01149 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/ReorderingGalleries/UngroupedReorderingGallery.cs +++ b/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/ReorderingGalleries/UngroupedReorderingGallery.cs @@ -77,7 +77,7 @@ async void UpdateItemsSourceType(ItemsSourceGenerator generator, ItemsSourceType { generator.GenerateItems(itemsSourceType); - if (Device.RuntimePlatform == Device.UWP && !(collectionView.ItemsSource is INotifyCollectionChanged)) + if (Device.RuntimePlatform == Device.WinUI && !(collectionView.ItemsSource is INotifyCollectionChanged)) { await DisplayAlert("Warning!", "Reordering on UWP/WinUI only works with ObservableCollections!", "OK"); } diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/SwipeViewGalleries/CustomSwipeItemGallery.cs b/src/Controls/samples/Controls.Sample/Pages/Controls/SwipeViewGalleries/CustomSwipeItemGallery.cs index f987a86ce2cf..bd8f7286bc3f 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Controls/SwipeViewGalleries/CustomSwipeItemGallery.cs +++ b/src/Controls/samples/Controls.Sample/Pages/Controls/SwipeViewGalleries/CustomSwipeItemGallery.cs @@ -18,7 +18,7 @@ public CustomSwipeItemGallery() } }; - if (Device.RuntimePlatform != Device.UWP) + if (Device.RuntimePlatform != Device.WinUI) { layout.Children.Add(GalleryBuilder.NavButton("SwipeItemView Gallery", () => new CustomSwipeItemViewGallery(), Navigation)); layout.Children.Add(GalleryBuilder.NavButton("CustomSwipeItem Size Gallery", () => new CustomSizeSwipeViewGallery(), Navigation)); diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/SwipeViewGalleries/SwipeItemIconGallery.cs b/src/Controls/samples/Controls.Sample/Pages/Controls/SwipeViewGalleries/SwipeItemIconGallery.cs index e0cf71826460..5d761dfb73a7 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Controls/SwipeViewGalleries/SwipeItemIconGallery.cs +++ b/src/Controls/samples/Controls.Sample/Pages/Controls/SwipeViewGalleries/SwipeItemIconGallery.cs @@ -98,7 +98,7 @@ public SwipeItemIconGallery() case Device.iOS: fontFamily = "Ionicons"; break; - case Device.UWP: + case Device.WinUI: fontFamily = "Assets/Fonts/ionicons.ttf#ionicons"; break; case Device.Android: diff --git a/src/Controls/samples/Controls.Sample/Pages/Core/DevicePage.xaml b/src/Controls/samples/Controls.Sample/Pages/Core/DevicePage.xaml new file mode 100644 index 000000000000..100afe24f6e5 --- /dev/null +++ b/src/Controls/samples/Controls.Sample/Pages/Core/DevicePage.xaml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/src/Controls/samples/Controls.Sample/Pages/Core/DevicePage.xaml.cs b/src/Controls/samples/Controls.Sample/Pages/Core/DevicePage.xaml.cs new file mode 100644 index 000000000000..805371071979 --- /dev/null +++ b/src/Controls/samples/Controls.Sample/Pages/Core/DevicePage.xaml.cs @@ -0,0 +1,10 @@ +namespace Maui.Controls.Sample.Pages +{ + public partial class DevicePage + { + public DevicePage() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/src/Controls/samples/Controls.Sample/Pages/MainPage.xaml b/src/Controls/samples/Controls.Sample/Pages/MainPage.xaml index 3258a42ebd16..df081a065463 100644 --- a/src/Controls/samples/Controls.Sample/Pages/MainPage.xaml +++ b/src/Controls/samples/Controls.Sample/Pages/MainPage.xaml @@ -51,7 +51,7 @@ - - \ No newline at end of file diff --git a/src/Controls/samples/Controls.Sample/ViewModels/CoreViewModel.cs b/src/Controls/samples/Controls.Sample/ViewModels/CoreViewModel.cs index 74b0c33eee74..e0be39a219c3 100644 --- a/src/Controls/samples/Controls.Sample/ViewModels/CoreViewModel.cs +++ b/src/Controls/samples/Controls.Sample/ViewModels/CoreViewModel.cs @@ -27,6 +27,9 @@ protected override IEnumerable CreateItems() => new[] new SectionModel(typeof(ClipPage), "Clip", "Defines the outline of the contents of an element."), + new SectionModel(typeof(DevicePage), "Device", + "A number of properties and methods to help developers customize layout and functionality on a per-platform basis"), + new SectionModel(typeof(EffectsPage), "Effects", "Apply Effects to a View."), diff --git a/src/Controls/src/Core/Device.cs b/src/Controls/src/Core/Device.cs index a83c0963b6b1..8536ae92c6a9 100644 --- a/src/Controls/src/Core/Device.cs +++ b/src/Controls/src/Core/Device.cs @@ -19,15 +19,16 @@ public static class Device /// public const string Android = "Android"; /// - public const string UWP = "UWP"; + internal const string UWP = "UWP"; /// - public const string macOS = "macOS"; + internal const string macOS = "macOS"; /// - public const string GTK = "GTK"; + internal const string GTK = "GTK"; /// public const string Tizen = "Tizen"; /// - public const string WPF = "WPF"; + internal const string WPF = "WPF"; + public const string WinUI = "WinUI"; public const string MacCatalyst = "MacCatalyst"; public const string tvOS = "tvOS"; diff --git a/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs b/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs index e3bd98a1a71b..67986a18a899 100644 --- a/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs +++ b/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs @@ -12,13 +12,14 @@ public class OnPlatformExtension : IMarkupExtension public object Default { get; set; } = s_notset; public object Android { get; set; } = s_notset; - public object GTK { get; set; } = s_notset; + internal object GTK { get; set; } = s_notset; public object iOS { get; set; } = s_notset; - public object macOS { get; set; } = s_notset; + internal object macOS { get; set; } = s_notset; public object MacCatalyst { get; set; } = s_notset; public object Tizen { get; set; } = s_notset; - public object UWP { get; set; } = s_notset; - public object WPF { get; set; } = s_notset; + internal object UWP { get; set; } = s_notset; + internal object WPF { get; set; } = s_notset; + public object WinUI { get; set; } = s_notset; public IValueConverter Converter { get; set; } @@ -33,7 +34,8 @@ public object ProvideValue(IServiceProvider serviceProvider) && MacCatalyst == s_notset && Tizen == s_notset && UWP == s_notset - && WPF == s_notset + && WPF == s_notset + && WinUI == s_notset && Default == s_notset) { throw new XamlParseException("OnPlatformExtension requires a value to be specified for at least one platform or Default.", serviceProvider); @@ -147,6 +149,11 @@ bool TryGetValueForPlatform(out object value) value = WPF; return true; } + if (Device.RuntimePlatform == Device.WinUI && WinUI != s_notset) + { + value = WinUI; + return true; + } value = Default; return value != s_notset; } From bb5c87d478ef278e0b11c22d90b9b6e496daecc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez=20Ruiz?= Date: Fri, 18 Feb 2022 17:48:12 +0100 Subject: [PATCH 02/13] Fixed broken tests --- .../Xaml.UnitTests/MarkupExpressionParserTests.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Controls/tests/Xaml.UnitTests/MarkupExpressionParserTests.cs b/src/Controls/tests/Xaml.UnitTests/MarkupExpressionParserTests.cs index ca671aa29bf6..3ea01ca6cac1 100644 --- a/src/Controls/tests/Xaml.UnitTests/MarkupExpressionParserTests.cs +++ b/src/Controls/tests/Xaml.UnitTests/MarkupExpressionParserTests.cs @@ -351,17 +351,14 @@ public void BindingWithStaticConverter() [TestCase("{OnPlatform 20, Android=23}", Device.Android, 23)] [TestCase("{OnPlatform Android=20, iOS=25}", Device.iOS, 25)] - [TestCase("{OnPlatform Android=20, GTK=25}", Device.GTK, 25)] - [TestCase("{OnPlatform Android=20, macOS=25}", Device.macOS, 25)] + [TestCase("{OnPlatform Android=20, MacCatalyst=25}", Device.MacCatalyst, 25)] [TestCase("{OnPlatform Android=20, Tizen=25}", Device.Tizen, 25)] - [TestCase("{OnPlatform Android=20, UWP=25}", Device.UWP, 25)] - [TestCase("{OnPlatform Android=20, WPF=25}", Device.WPF, 25)] + [TestCase("{OnPlatform Android=20, WinUI=25}", Device.WinUI, 25)] + [TestCase("{OnPlatform 20}", Device.Android, 20)] [TestCase("{OnPlatform 20}", Device.iOS, 20)] - [TestCase("{OnPlatform 20}", Device.GTK, 20)] - [TestCase("{OnPlatform 20}", Device.macOS, 20)] + [TestCase("{OnPlatform 20}", Device.MacCatalyst, 20)] [TestCase("{OnPlatform 20}", Device.Tizen, 20)] - [TestCase("{OnPlatform 20}", Device.UWP, 20)] - [TestCase("{OnPlatform 20}", Device.WPF, 20)] + [TestCase("{OnPlatform 20}", Device.WinUI, 20)] [TestCase("{OnPlatform 20}", "Foo", 20)] [TestCase("{OnPlatform Android=23, Default=20}", "Foo", 20)] public void OnPlatformExtension(string markup, string platform, int expected) From 297ed091270b5bfd6b1acaf30e57afe5d99d0977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez=20Ruiz?= Date: Thu, 24 Feb 2022 18:21:21 +0100 Subject: [PATCH 03/13] Deprecate UWP target --- src/Compatibility/Core/src/Android/Forms.cs | 2 +- src/Controls/src/Core/Device.cs | 1 + src/Controls/src/Core/DeviceStateTrigger.cs | 4 ++-- src/Controls/src/Core/Shell/BaseShellItem.cs | 12 ++++++------ .../src/Xaml/MarkupExtensions/OnPlatformExtension.cs | 2 ++ src/Controls/src/Xaml/XamlParser.cs | 2 +- src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs | 2 +- src/Essentials/src/Types/DevicePlatform.shared.cs | 2 ++ 8 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Compatibility/Core/src/Android/Forms.cs b/src/Compatibility/Core/src/Android/Forms.cs index 21cae8b8082c..0e14f6e5009d 100644 --- a/src/Compatibility/Core/src/Android/Forms.cs +++ b/src/Compatibility/Core/src/Android/Forms.cs @@ -230,7 +230,7 @@ static void SetupInit( var androidServices = new AndroidPlatformServices(activity); Device.PlatformServices = androidServices; - + Profile.FramePartition("RegisterAll"); if (maybeOptions?.Flags.HasFlag(InitializationFlags.SkipRenderers) != true) diff --git a/src/Controls/src/Core/Device.cs b/src/Controls/src/Core/Device.cs index e20d0e59bd7f..1e39a019ccd5 100644 --- a/src/Controls/src/Core/Device.cs +++ b/src/Controls/src/Core/Device.cs @@ -17,6 +17,7 @@ public static class Device /// public const string Android = "Android"; /// + [Obsolete("Use WinUI instead")] internal const string UWP = "UWP"; /// internal const string macOS = "macOS"; diff --git a/src/Controls/src/Core/DeviceStateTrigger.cs b/src/Controls/src/Core/DeviceStateTrigger.cs index 55f37d304174..fdf74c301af2 100644 --- a/src/Controls/src/Core/DeviceStateTrigger.cs +++ b/src/Controls/src/Core/DeviceStateTrigger.cs @@ -38,8 +38,8 @@ void UpdateState() case FormsDevice.iOS: SetActive(FormsDevice.RuntimePlatform == FormsDevice.iOS); break; - case FormsDevice.UWP: - SetActive(FormsDevice.RuntimePlatform == FormsDevice.UWP); + case FormsDevice.WinUI: + SetActive(FormsDevice.RuntimePlatform == FormsDevice.WinUI); break; } } diff --git a/src/Controls/src/Core/Shell/BaseShellItem.cs b/src/Controls/src/Core/Shell/BaseShellItem.cs index ed176655daa9..c7d4e1c06aaf 100644 --- a/src/Controls/src/Core/Shell/BaseShellItem.cs +++ b/src/Controls/src/Core/Shell/BaseShellItem.cs @@ -303,7 +303,7 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, str return new DataTemplate(() => { var grid = new Grid(); - if (Device.RuntimePlatform == Device.UWP) + if (Device.RuntimePlatform == Device.WinUI) grid.ColumnSpacing = grid.RowSpacing = 0; grid.Resources = new ResourceDictionary(); @@ -342,7 +342,7 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, str var selectedState = new VisualState(); selectedState.Name = "Selected"; - if (Device.RuntimePlatform != Device.UWP) + if (Device.RuntimePlatform != Device.WinUI) { selectedState.Setters.Add(new Setter { @@ -374,7 +374,7 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, str columnDefinitions.Add(new ColumnDefinition { Width = 54 }); else if (Device.RuntimePlatform == Device.iOS) columnDefinitions.Add(new ColumnDefinition { Width = 50 }); - else if (Device.RuntimePlatform == Device.UWP) + else if (Device.RuntimePlatform == Device.WinUI) columnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); columnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); @@ -387,7 +387,7 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, str sizeRequest = 24; else if (Device.RuntimePlatform == Device.iOS) sizeRequest = 22; - else if (Device.RuntimePlatform == Device.UWP) + else if (Device.RuntimePlatform == Device.WinUI) sizeRequest = 16; if (sizeRequest > 0) @@ -396,7 +396,7 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, str defaultImageClass.Setters.Add(new Setter() { Property = Image.WidthRequestProperty, Value = sizeRequest }); } - if (Device.RuntimePlatform == Device.UWP) + if (Device.RuntimePlatform == Device.WinUI) { defaultImageClass.Setters.Add(new Setter { Property = Image.HorizontalOptionsProperty, Value = LayoutOptions.Start }); defaultImageClass.Setters.Add(new Setter { Property = Image.MarginProperty, Value = new Thickness(12, 0, 12, 0) }); @@ -436,7 +436,7 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, str defaultLabelClass.Setters.Add(new Setter { Property = Label.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, label) }); defaultLabelClass.Setters.Add(new Setter { Property = Label.FontAttributesProperty, Value = FontAttributes.Bold }); } - else if (Device.RuntimePlatform == Device.UWP) + else if (Device.RuntimePlatform == Device.WinUI) { defaultLabelClass.Setters.Add(new Setter { Property = Label.HorizontalOptionsProperty, Value = LayoutOptions.Start }); defaultLabelClass.Setters.Add(new Setter { Property = Label.HorizontalTextAlignmentProperty, Value = TextAlignment.Start }); diff --git a/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs b/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs index 67986a18a899..09db7c7e1718 100644 --- a/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs +++ b/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs @@ -139,11 +139,13 @@ bool TryGetValueForPlatform(out object value) value = Tizen; return true; } +#pragma warning disable CS0618 // Type or member is obsolete if (Device.RuntimePlatform == Device.UWP && UWP != s_notset) { value = UWP; return true; } +#pragma warning restore CS0618 // Type or member is obsolete if (Device.RuntimePlatform == Device.WPF && WPF != s_notset) { value = WPF; diff --git a/src/Controls/src/Xaml/XamlParser.cs b/src/Controls/src/Xaml/XamlParser.cs index 4df10bdb2d30..cb3b8eed11af 100644 --- a/src/Controls/src/Xaml/XamlParser.cs +++ b/src/Controls/src/Xaml/XamlParser.cs @@ -297,7 +297,7 @@ static IList PrefixesToIgnore(IList> xmlns) if (targetPlatform != Device.RuntimePlatform) { // Special case for Windows backward compatibility - if (targetPlatform == "Windows" && Device.RuntimePlatform == Device.UWP) + if (targetPlatform == "Windows" && Device.RuntimePlatform == Device.WinUI) continue; prefixes.Add(prefix); diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs index 6c7cbdbbb1ca..c65c3cd8ce38 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs @@ -54,7 +54,7 @@ public string VersionString public Version Version => Utils.ParseVersion(VersionString); - public DevicePlatform Platform => DevicePlatform.UWP; + public DevicePlatform Platform => DevicePlatform.WinUI; public DeviceIdiom Idiom { diff --git a/src/Essentials/src/Types/DevicePlatform.shared.cs b/src/Essentials/src/Types/DevicePlatform.shared.cs index c59581374c09..21c3f7d14455 100644 --- a/src/Essentials/src/Types/DevicePlatform.shared.cs +++ b/src/Essentials/src/Types/DevicePlatform.shared.cs @@ -27,6 +27,8 @@ namespace Microsoft.Maui.Essentials /// public static DevicePlatform UWP { get; } = new DevicePlatform(nameof(UWP)); + public static DevicePlatform WinUI { get; } = new DevicePlatform(nameof(WinUI)); + /// public static DevicePlatform watchOS { get; } = new DevicePlatform(nameof(watchOS)); From cb40ae2acccf4acb16c442ad625045de3cc9db01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez=20Ruiz?= Date: Thu, 3 Mar 2022 17:40:26 +0100 Subject: [PATCH 04/13] Allow to use UWP target on XAML --- src/Controls/src/Core/Device.cs | 2 +- .../src/Xaml/MarkupExtensions/OnPlatformExtension.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Controls/src/Core/Device.cs b/src/Controls/src/Core/Device.cs index 4ca7c49a5609..4de784611720 100644 --- a/src/Controls/src/Core/Device.cs +++ b/src/Controls/src/Core/Device.cs @@ -21,7 +21,7 @@ public static class Device /// public const string Android = "Android"; /// - [Obsolete("Use WinUI instead")] + [Obsolete] internal const string UWP = "UWP"; /// internal const string macOS = "macOS"; diff --git a/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs b/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs index 09db7c7e1718..00902a8fe304 100644 --- a/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs +++ b/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs @@ -17,7 +17,7 @@ public class OnPlatformExtension : IMarkupExtension internal object macOS { get; set; } = s_notset; public object MacCatalyst { get; set; } = s_notset; public object Tizen { get; set; } = s_notset; - internal object UWP { get; set; } = s_notset; + public object UWP { get; set; } = s_notset; internal object WPF { get; set; } = s_notset; public object WinUI { get; set; } = s_notset; @@ -140,7 +140,7 @@ bool TryGetValueForPlatform(out object value) return true; } #pragma warning disable CS0618 // Type or member is obsolete - if (Device.RuntimePlatform == Device.UWP && UWP != s_notset) + if (Device.RuntimePlatform == Device.WinUI && UWP != s_notset) { value = UWP; return true; @@ -151,7 +151,7 @@ bool TryGetValueForPlatform(out object value) value = WPF; return true; } - if (Device.RuntimePlatform == Device.WinUI && WinUI != s_notset) + if (Device.RuntimePlatform == Device.WinUI && WinUI != s_notset) { value = WinUI; return true; From b60b313aecf25f069faa718c741d866c58d2b9ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez=20Ruiz?= Date: Thu, 3 Mar 2022 17:55:52 +0100 Subject: [PATCH 05/13] Fix build errors --- .../ControlGallery/src/Core/GalleryPages/ButtonGallery.cs | 2 +- .../src/Core/GalleryPages/CellsGalleries/ProductViewCell.cs | 2 +- .../src/Core/GalleryPages/ImageSourcesGallery.cs | 2 +- .../ControlGallery/src/Core/GalleryPages/LabelGallery.cs | 2 +- .../SwipeViewGalleries/CustomSwipeItemGallery.cs | 2 +- src/Compatibility/ControlGallery/src/Core/TestCases.cs | 2 +- .../ControlGallery/src/Core/XamStore/StoreShell.xaml.cs | 2 +- .../ControlGallery/src/Issues.Shared/Bugzilla22229.xaml.cs | 2 +- .../ControlGallery/src/Issues.Shared/Issue1683.cs | 6 +++--- .../ControlGallery/src/Issues.Shared/Issue1705_2.cs | 2 +- .../ControlGallery/src/Issues.Shared/Issue2482.cs | 2 +- .../ControlGallery/src/Issues.Shared/Issue3343.cs | 2 +- .../ControlGallery/src/Issues.Shared/Issue5132.cs | 2 +- .../ControlGallery/src/Issues.Shared/Issue6491.cs | 2 +- .../ControlGallery/src/Issues.Shared/Issue773.cs | 2 +- .../ControlGallery/src/Issues.Shared/Issue8801.cs | 2 +- .../src/Xaml/MarkupExtensions/OnPlatformExtension.cs | 2 +- 17 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Compatibility/ControlGallery/src/Core/GalleryPages/ButtonGallery.cs b/src/Compatibility/ControlGallery/src/Core/GalleryPages/ButtonGallery.cs index c0a99209c411..9744e12a1ca1 100644 --- a/src/Compatibility/ControlGallery/src/Core/GalleryPages/ButtonGallery.cs +++ b/src/Compatibility/ControlGallery/src/Core/GalleryPages/ButtonGallery.cs @@ -42,7 +42,7 @@ public ButtonGallery() case Device.Android: fontName = "sans-serif-light"; break; - case Device.UWP: + case Device.WinUI: fontName = "Comic Sans MS"; break; } diff --git a/src/Compatibility/ControlGallery/src/Core/GalleryPages/CellsGalleries/ProductViewCell.cs b/src/Compatibility/ControlGallery/src/Core/GalleryPages/CellsGalleries/ProductViewCell.cs index 84315b4fd1f5..275c13256122 100644 --- a/src/Compatibility/ControlGallery/src/Core/GalleryPages/CellsGalleries/ProductViewCell.cs +++ b/src/Compatibility/ControlGallery/src/Core/GalleryPages/CellsGalleries/ProductViewCell.cs @@ -22,7 +22,7 @@ public ProductCellView(string text) var frame = new Frame { Content = _stack, - BackgroundColor = new[] { Device.Android, Device.UWP }.Contains(Device.RuntimePlatform) ? new Color(0.2f) : new Color(1) + BackgroundColor = new[] { Device.Android, Device.WinUI }.Contains(Device.RuntimePlatform) ? new Color(0.2f) : new Color(1) }; _timeLabel = new Label { diff --git a/src/Compatibility/ControlGallery/src/Core/GalleryPages/ImageSourcesGallery.cs b/src/Compatibility/ControlGallery/src/Core/GalleryPages/ImageSourcesGallery.cs index a337ec98b564..b94561606f01 100644 --- a/src/Compatibility/ControlGallery/src/Core/GalleryPages/ImageSourcesGallery.cs +++ b/src/Compatibility/ControlGallery/src/Core/GalleryPages/ImageSourcesGallery.cs @@ -57,7 +57,7 @@ static Picker CreateImageSourcePicker(string title, Action> on case Device.iOS: fontFamily = "Ionicons"; break; - case Device.UWP: + case Device.WinUI: fontFamily = "Assets/Fonts/ionicons.ttf#ionicons"; break; case Device.Android: diff --git a/src/Compatibility/ControlGallery/src/Core/GalleryPages/LabelGallery.cs b/src/Compatibility/ControlGallery/src/Core/GalleryPages/LabelGallery.cs index e6e5fc003d22..34a8a5c05bbf 100644 --- a/src/Compatibility/ControlGallery/src/Core/GalleryPages/LabelGallery.cs +++ b/src/Compatibility/ControlGallery/src/Core/GalleryPages/LabelGallery.cs @@ -87,7 +87,7 @@ public LabelGallery() case Device.Android: fontName = "sans-serif-light"; break; - case Device.UWP: + case Device.WinUI: fontName = "Comic Sans MS"; break; } diff --git a/src/Compatibility/ControlGallery/src/Core/GalleryPages/SwipeViewGalleries/CustomSwipeItemGallery.cs b/src/Compatibility/ControlGallery/src/Core/GalleryPages/SwipeViewGalleries/CustomSwipeItemGallery.cs index b7c0e4c86ee2..244623cc31be 100644 --- a/src/Compatibility/ControlGallery/src/Core/GalleryPages/SwipeViewGalleries/CustomSwipeItemGallery.cs +++ b/src/Compatibility/ControlGallery/src/Core/GalleryPages/SwipeViewGalleries/CustomSwipeItemGallery.cs @@ -17,7 +17,7 @@ public CustomSwipeItemGallery() } }; - if (Device.RuntimePlatform != Device.UWP) + if (Device.RuntimePlatform != Device.WinUI) { layout.Children.Add(GalleryBuilder.NavButton("SwipeItemView Gallery", () => new CustomSwipeItemViewGallery(), Navigation)); layout.Children.Add(GalleryBuilder.NavButton("CustomSwipeItem Size Gallery", () => new CustomSizeSwipeViewGallery(), Navigation)); diff --git a/src/Compatibility/ControlGallery/src/Core/TestCases.cs b/src/Compatibility/ControlGallery/src/Core/TestCases.cs index 8037515e78d8..f2f7379503f9 100644 --- a/src/Compatibility/ControlGallery/src/Core/TestCases.cs +++ b/src/Compatibility/ControlGallery/src/Core/TestCases.cs @@ -363,7 +363,7 @@ public static NavigationPage GetTestCases() default: page.Title = "Test Cases"; break; - case Device.UWP: + case Device.WinUI: page.Title = "Tests"; break; } diff --git a/src/Compatibility/ControlGallery/src/Core/XamStore/StoreShell.xaml.cs b/src/Compatibility/ControlGallery/src/Core/XamStore/StoreShell.xaml.cs index 3098977e416a..ae8c05560d7d 100644 --- a/src/Compatibility/ControlGallery/src/Core/XamStore/StoreShell.xaml.cs +++ b/src/Compatibility/ControlGallery/src/Core/XamStore/StoreShell.xaml.cs @@ -23,7 +23,7 @@ protected override void Init() case Device.iOS: fontFamily = "Ionicons"; break; - case Device.UWP: + case Device.WinUI: fontFamily = "Assets/Fonts/ionicons.ttf#ionicons"; break; case Device.Android: diff --git a/src/Compatibility/ControlGallery/src/Issues.Shared/Bugzilla22229.xaml.cs b/src/Compatibility/ControlGallery/src/Issues.Shared/Bugzilla22229.xaml.cs index c81c06881833..40bdbebb21fd 100644 --- a/src/Compatibility/ControlGallery/src/Issues.Shared/Bugzilla22229.xaml.cs +++ b/src/Compatibility/ControlGallery/src/Issues.Shared/Bugzilla22229.xaml.cs @@ -30,7 +30,7 @@ public Bugzilla22229() case Device.Android: _prefix = ""; break; - case Device.UWP: + case Device.WinUI: _prefix = "Assets/"; break; } diff --git a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue1683.cs b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue1683.cs index df548c1392ce..78a2d0b418a2 100644 --- a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue1683.cs +++ b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue1683.cs @@ -41,7 +41,7 @@ protected override void Init() KeyboardFlags spellCheckForUwp = KeyboardFlags.None; - if (Device.RuntimePlatform == Device.UWP) + if (Device.RuntimePlatform == Device.WinUI) { spellCheckForUwp = KeyboardFlags.Spellcheck; } @@ -62,12 +62,12 @@ protected override void Init() inputViews.Add(new EntryKeyboardFlags() { ClassId = "CustomRendererCapitalizeSentence", FlagsToSet = KeyboardFlags.CapitalizeSentence, FlagsToTestFor = KeyboardFlags.CapitalizeSentence }); inputViews.Add(new EntryKeyboardFlags() { ClassId = "CustomRendererCapitalizeWord", FlagsToSet = KeyboardFlags.CapitalizeWord, FlagsToTestFor = KeyboardFlags.CapitalizeWord }); - if (Device.RuntimePlatform != Device.UWP) + if (Device.RuntimePlatform != Device.WinUI) { inputViews.Add(new EntryKeyboardFlags() { ClassId = "CustomRendererCapitalizeCharacter", FlagsToSet = KeyboardFlags.CapitalizeCharacter }); } - if (Device.RuntimePlatform == Device.UWP) + if (Device.RuntimePlatform == Device.WinUI) { layout.Children.Add(new Label() { Text = "Capitalization settings only work when using touch keyboard" }); layout.Children.Add(new Label() { Text = "Character doesn't do anything on UWP" }); diff --git a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue1705_2.cs b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue1705_2.cs index cc3356c1a6d0..9a174917d081 100644 --- a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue1705_2.cs +++ b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue1705_2.cs @@ -42,7 +42,7 @@ public Issue1705_2() Children.Add(_page2); Children.Add(_page3); - if (Device.RuntimePlatform == Device.UWP) + if (Device.RuntimePlatform == Device.WinUI) Children.Add(new HeaderIconsControlPage(this) { Title = "UWPSpecifics" }); } } diff --git a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue2482.cs b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue2482.cs index e51ca23377c3..33f6b9093df9 100644 --- a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue2482.cs +++ b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue2482.cs @@ -93,7 +93,7 @@ protected override void Init() layout.Children.Add(_result); layout.Children.Add(button); - if (Device.RuntimePlatform == Device.UWP) + if (Device.RuntimePlatform == Device.WinUI) layout.Children.Add(new Label { Text = "\xE76E", FontFamily = "Segoe MDL2 Assets", FontSize = 32 }); Content = layout; diff --git a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue3343.cs b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue3343.cs index 1308f565c3c2..1b35430d47a5 100644 --- a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue3343.cs +++ b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue3343.cs @@ -42,7 +42,7 @@ protected override void Init() entry2Label2.SetBinding(Label.TextProperty, new Binding(nameof(Entry.SelectionLength), stringFormat: "SelectionLength: {0}", source: entry2)); // When the Entry is in a NavPage, the Entry doesn't get first focus on UWP - string uwp_instructions = Device.RuntimePlatform == Device.UWP ? "Press Tab to focus the first entry. " : ""; + string uwp_instructions = Device.RuntimePlatform == Device.WinUI ? "Press Tab to focus the first entry. " : ""; Content = new StackLayout() { diff --git a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue5132.cs b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue5132.cs index 1563941ed7ea..c3f4c0066063 100644 --- a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue5132.cs +++ b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue5132.cs @@ -51,7 +51,7 @@ static string DefaultFontFamily() case Device.iOS: fontFamily = "Ionicons"; break; - case Device.UWP: + case Device.WinUI: fontFamily = "Assets/Fonts/ionicons.ttf#ionicons"; break; case Device.Android: diff --git a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue6491.cs b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue6491.cs index 9ccd606ede8e..e2836af7c500 100644 --- a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue6491.cs +++ b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue6491.cs @@ -34,7 +34,7 @@ protected override void Init() FontFamily = "FontAwesome5Free-Solid" }; - if (Device.RuntimePlatform == Device.UWP) + if (Device.RuntimePlatform == Device.WinUI) ((FontImageSource)button.ImageSource).FontFamily = "Assets/Fonts/fa-solid-900.ttf#Font Awesome 5 Free"; stack.Children.Add(label); diff --git a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue773.cs b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue773.cs index afa4a2869de5..8b3ed72b76c3 100644 --- a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue773.cs +++ b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue773.cs @@ -118,7 +118,7 @@ public CannotScrollRepro() { BackgroundColor = Colors.Aqua, Orientation = ScrollOrientation.Horizontal, - HeightRequest = Device.RuntimePlatform == Device.UWP ? 80 : 44, + HeightRequest = Device.RuntimePlatform == Device.WinUI ? 80 : 44, Content = buttonStack }); diff --git a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue8801.cs b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue8801.cs index 7ad919359770..67d62fe5a918 100644 --- a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue8801.cs +++ b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue8801.cs @@ -110,7 +110,7 @@ public PopupStackLayout() HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Start, Orientation = this.Orientation, - WidthRequest = Device.RuntimePlatform == Device.UWP ? 20 : 50, + WidthRequest = Device.RuntimePlatform == Device.WinUI ? 20 : 50, }; this.SetBinding(HeightRequestProperty, new Binding(nameof(Height), BindingMode.OneWay, source: showButton)); diff --git a/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs b/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs index 00902a8fe304..5d7b4e847577 100644 --- a/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs +++ b/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs @@ -151,7 +151,7 @@ bool TryGetValueForPlatform(out object value) value = WPF; return true; } - if (Device.RuntimePlatform == Device.WinUI && WinUI != s_notset) + if (Device.RuntimePlatform == Device.WinUI && WinUI != s_notset) { value = WinUI; return true; From 1ba358c3c2dfd1fcd61e21986dd048b3901ced83 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 4 Mar 2022 01:51:27 +0800 Subject: [PATCH 06/13] comments --- src/Controls/src/Core/Device.cs | 2 +- src/Essentials/src/Types/DevicePlatform.shared.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Controls/src/Core/Device.cs b/src/Controls/src/Core/Device.cs index c3feb48b6d19..3f8420646ec0 100644 --- a/src/Controls/src/Core/Device.cs +++ b/src/Controls/src/Core/Device.cs @@ -24,7 +24,7 @@ public static class Device [Obsolete("Use Essentials.DevicePlatform.Android instead.")] public const string Android = "Android"; /// - [Obsolete("Use Essentials.DevicePlatform.UWP instead.")] + [Obsolete("Use Essentials.DevicePlatform.WinUI instead.")] internal const string UWP = "UWP"; /// [Obsolete("Use Essentials.DevicePlatform.macOS instead.")] diff --git a/src/Essentials/src/Types/DevicePlatform.shared.cs b/src/Essentials/src/Types/DevicePlatform.shared.cs index 9758eaed2ead..09b08de730c0 100644 --- a/src/Essentials/src/Types/DevicePlatform.shared.cs +++ b/src/Essentials/src/Types/DevicePlatform.shared.cs @@ -25,6 +25,7 @@ namespace Microsoft.Maui.Essentials public static DevicePlatform Tizen { get; } = new DevicePlatform(nameof(Tizen)); /// + [Obsolete("Use WinUI instead.")] public static DevicePlatform UWP { get; } = new DevicePlatform(nameof(UWP)); public static DevicePlatform WinUI { get; } = new DevicePlatform(nameof(WinUI)); From d985331e281dd9a534b2f34be7917dc006b165c8 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 4 Mar 2022 02:05:28 +0800 Subject: [PATCH 07/13] UWP == WinUI --- src/Controls/src/Core/Device.cs | 2 +- src/Controls/src/Core/OnPlatform.cs | 3 ++- .../src/Xaml/MarkupExtensions/OnPlatformExtension.cs | 7 +++++-- src/Essentials/src/Types/DevicePlatform.shared.cs | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Controls/src/Core/Device.cs b/src/Controls/src/Core/Device.cs index 3f8420646ec0..08b9afcc2ac0 100644 --- a/src/Controls/src/Core/Device.cs +++ b/src/Controls/src/Core/Device.cs @@ -25,7 +25,7 @@ public static class Device public const string Android = "Android"; /// [Obsolete("Use Essentials.DevicePlatform.WinUI instead.")] - internal const string UWP = "UWP"; + public const string UWP = WinUI; /// [Obsolete("Use Essentials.DevicePlatform.macOS instead.")] internal const string macOS = "macOS"; diff --git a/src/Controls/src/Core/OnPlatform.cs b/src/Controls/src/Core/OnPlatform.cs index 34720bdea2d1..5794802ce200 100644 --- a/src/Controls/src/Core/OnPlatform.cs +++ b/src/Controls/src/Core/OnPlatform.cs @@ -36,7 +36,8 @@ public static implicit operator T(OnPlatform onPlatform) { if (onPlat.Platform == null) continue; - if (!onPlat.Platform.Contains(DeviceInfo.Platform.ToString())) + if (!onPlat.Platform.Contains(DeviceInfo.Platform.ToString()) || + (!onPlat.Platform.Contains("UWP") && DeviceInfo.Platform == DevicePlatform.WinUI)) continue; if (s_valueConverter == null) continue; diff --git a/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs b/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs index 4d90b06f0581..a72fb2e966e1 100644 --- a/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs +++ b/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs @@ -18,6 +18,7 @@ public class OnPlatformExtension : IMarkupExtension internal object macOS { get; set; } = s_notset; public object MacCatalyst { get; set; } = s_notset; public object Tizen { get; set; } = s_notset; + [Obsolete("Use WinUI instead.")] public object UWP { get; set; } = s_notset; internal object WPF { get; set; } = s_notset; public object WinUI { get; set; } = s_notset; @@ -34,8 +35,10 @@ public object ProvideValue(IServiceProvider serviceProvider) && macOS == s_notset && MacCatalyst == s_notset && Tizen == s_notset +#pragma warning disable CS0618 // Type or member is obsolete && UWP == s_notset - && WPF == s_notset +#pragma warning restore CS0618 // Type or member is obsolete + && WPF == s_notset && WinUI == s_notset && Default == s_notset) { @@ -140,7 +143,7 @@ bool TryGetValueForPlatform(out object value) value = Tizen; return true; } - if (Device.RuntimePlatform == Device.WinUI && WinUI != s_notset) + if (DeviceInfo.Platform == DevicePlatform.WinUI && WinUI != s_notset) { value = WinUI; return true; diff --git a/src/Essentials/src/Types/DevicePlatform.shared.cs b/src/Essentials/src/Types/DevicePlatform.shared.cs index 09b08de730c0..bb47cf495ee4 100644 --- a/src/Essentials/src/Types/DevicePlatform.shared.cs +++ b/src/Essentials/src/Types/DevicePlatform.shared.cs @@ -26,7 +26,7 @@ namespace Microsoft.Maui.Essentials /// [Obsolete("Use WinUI instead.")] - public static DevicePlatform UWP { get; } = new DevicePlatform(nameof(UWP)); + public static DevicePlatform UWP { get; } = WinUI; public static DevicePlatform WinUI { get; } = new DevicePlatform(nameof(WinUI)); From b3fc708e35a97b8d08e6e60326cc1ccdbaa14ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez=20Ruiz?= Date: Thu, 3 Mar 2022 19:19:47 +0100 Subject: [PATCH 08/13] Fix Build errors --- src/Essentials/src/FilePicker/FilePicker.uwp.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Essentials/src/FilePicker/FilePicker.uwp.cs b/src/Essentials/src/FilePicker/FilePicker.uwp.cs index 8ff9b0186f9a..cf0db521f516 100644 --- a/src/Essentials/src/FilePicker/FilePicker.uwp.cs +++ b/src/Essentials/src/FilePicker/FilePicker.uwp.cs @@ -71,31 +71,31 @@ public partial class FilePickerFileType static FilePickerFileType PlatformImageFileType() => new FilePickerFileType(new Dictionary> { - { DevicePlatform.UWP, FileSystem.Extensions.AllImage } + { DevicePlatform.WinUI, FileSystem.Extensions.AllImage } }); static FilePickerFileType PlatformPngFileType() => new FilePickerFileType(new Dictionary> { - { DevicePlatform.UWP, new[] { FileSystem.Extensions.Png } } + { DevicePlatform.WinUI, new[] { FileSystem.Extensions.Png } } }); static FilePickerFileType PlatformJpegFileType() => new FilePickerFileType(new Dictionary> { - { DevicePlatform.UWP, FileSystem.Extensions.AllJpeg } + { DevicePlatform.WinUI, FileSystem.Extensions.AllJpeg } }); static FilePickerFileType PlatformVideoFileType() => new FilePickerFileType(new Dictionary> { - { DevicePlatform.UWP, FileSystem.Extensions.AllVideo } + { DevicePlatform.WinUI, FileSystem.Extensions.AllVideo } }); static FilePickerFileType PlatformPdfFileType() => new FilePickerFileType(new Dictionary> { - { DevicePlatform.UWP, new[] { FileSystem.Extensions.Pdf } } + { DevicePlatform.WinUI, new[] { FileSystem.Extensions.Pdf } } }); } } From e0ffb5d64b3bac392a700be20ef6fe511031a892 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 4 Mar 2022 02:22:16 +0800 Subject: [PATCH 09/13] Added more tests --- .../MarkupExpressionParserTests.cs | 2 + .../tests/Xaml.UnitTests/OnPlatformTests.cs | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/Controls/tests/Xaml.UnitTests/MarkupExpressionParserTests.cs b/src/Controls/tests/Xaml.UnitTests/MarkupExpressionParserTests.cs index 1d4595c65398..2d8910000f0c 100644 --- a/src/Controls/tests/Xaml.UnitTests/MarkupExpressionParserTests.cs +++ b/src/Controls/tests/Xaml.UnitTests/MarkupExpressionParserTests.cs @@ -356,6 +356,8 @@ public void BindingWithStaticConverter() [TestCase("{OnPlatform Android=20, macOS=25}", "macOS", 25)] [TestCase("{OnPlatform Android=20, Tizen=25}", "Tizen", 25)] [TestCase("{OnPlatform Android=20, WinUI=25}", "WinUI", 25)] + [TestCase("{OnPlatform Android=20, UWP=25}", "WinUI", 25)] + [TestCase("{OnPlatform Android=20, WinUI=25, UWP=20}", "WinUI", 25)] [TestCase("{OnPlatform Android=20, UWP=25}", "UWP", 25)] [TestCase("{OnPlatform Android=20, WPF=25}", "WPF", 25)] [TestCase("{OnPlatform 20}", "Android", 20)] diff --git a/src/Controls/tests/Xaml.UnitTests/OnPlatformTests.cs b/src/Controls/tests/Xaml.UnitTests/OnPlatformTests.cs index 03c0b1fff7d4..036c187cc675 100644 --- a/src/Controls/tests/Xaml.UnitTests/OnPlatformTests.cs +++ b/src/Controls/tests/Xaml.UnitTests/OnPlatformTests.cs @@ -94,6 +94,51 @@ public void TypeConverterAndDerivedTypes() image = new Image().LoadFromXaml(xaml); Assert.AreEqual("icon_twitter.png", (image.Source as FileImageSource).File); } + + [Test] + public void UWPisWinUI() + { + var xaml = @" + + + + icon_twitter.png + icon_twitter.png + Images/icon_twitter.png + + + "; + + Image image; + + mockDeviceInfo.Platform = DevicePlatform.WinUI; + image = new Image().LoadFromXaml(xaml); + Assert.AreEqual("Images/icon_twitter.png", (image.Source as FileImageSource).File); + } + + [Test] + public void ChecksPreferWinUI() + { + var xaml = @" + + + + icon_twitter.png + icon_twitter.png + Images/icon_twitter.png + Images/icon_twitter_preferred.png + + + "; + + Image image; + + mockDeviceInfo.Platform = DevicePlatform.WinUI; + image = new Image().LoadFromXaml(xaml); + Assert.AreEqual("Images/icon_twitter_preferred.png", (image.Source as FileImageSource).File); + } } [TestFixture] From 5024ace4297d6bc7b8109e398d9c76771b753c42 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 4 Mar 2022 02:27:44 +0800 Subject: [PATCH 10/13] fix --- src/Controls/src/Core/DeviceStateTrigger.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controls/src/Core/DeviceStateTrigger.cs b/src/Controls/src/Core/DeviceStateTrigger.cs index 47b577d265f0..401d5d760841 100644 --- a/src/Controls/src/Core/DeviceStateTrigger.cs +++ b/src/Controls/src/Core/DeviceStateTrigger.cs @@ -35,7 +35,7 @@ void UpdateState() SetActive(DeviceInfo.Platform == DevicePlatform.Android); else if (device == DevicePlatform.iOS) SetActive(DeviceInfo.Platform == DevicePlatform.iOS); - else if (device == DevicePlatform.WinUI) + else if (device == DevicePlatform.WinUI || device == DevicePlatform.Create("UWP")) SetActive(DeviceInfo.Platform == DevicePlatform.WinUI); } } From fcbd6302d6223a0e755db74b33804089c3da9962 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 4 Mar 2022 02:29:26 +0800 Subject: [PATCH 11/13] vbnm --- src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs b/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs index a72fb2e966e1..3374f587f709 100644 --- a/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs +++ b/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs @@ -149,7 +149,7 @@ bool TryGetValueForPlatform(out object value) return true; } #pragma warning disable CS0618 // Type or member is obsolete - if (DeviceInfo.Platform == DevicePlatform.UWP && UWP != s_notset) + if (DeviceInfo.Platform == DevicePlatform.WinUI && UWP != s_notset) { value = UWP; return true; From f84545914a6bd1990b1614b00e131d843494a61d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez=20Ruiz?= Date: Thu, 3 Mar 2022 20:12:19 +0100 Subject: [PATCH 12/13] More fixes --- src/Essentials/samples/Samples/ViewModel/FilePickerViewModel.cs | 2 +- src/Essentials/test/DeviceTests/Tests/DeviceInfo_Tests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Essentials/samples/Samples/ViewModel/FilePickerViewModel.cs b/src/Essentials/samples/Samples/ViewModel/FilePickerViewModel.cs index 41661fa4fa0e..f65a27b81ecd 100644 --- a/src/Essentials/samples/Samples/ViewModel/FilePickerViewModel.cs +++ b/src/Essentials/samples/Samples/ViewModel/FilePickerViewModel.cs @@ -90,7 +90,7 @@ async void DoPickCustomType() { { DevicePlatform.iOS, new[] { "public.my.comic.extension" } }, // or general UTType values { DevicePlatform.Android, new[] { "application/comics" } }, - { DevicePlatform.UWP, new[] { ".cbr", ".cbz" } }, + { DevicePlatform.WinUI, new[] { ".cbr", ".cbz" } }, { DevicePlatform.Tizen, new[] { "*/*" } }, { DevicePlatform.macOS, new[] { "cbr", "cbz" } }, // or general UTType values }); diff --git a/src/Essentials/test/DeviceTests/Tests/DeviceInfo_Tests.cs b/src/Essentials/test/DeviceTests/Tests/DeviceInfo_Tests.cs index 8718e7ed77cb..2d1cb963f064 100644 --- a/src/Essentials/test/DeviceTests/Tests/DeviceInfo_Tests.cs +++ b/src/Essentials/test/DeviceTests/Tests/DeviceInfo_Tests.cs @@ -70,7 +70,7 @@ public void AppPackageName_Is_Correct() public void Platform_Is_Correct() { #if WINDOWS_UWP || WINDOWS - Assert.Equal(DevicePlatform.UWP, DeviceInfo.Platform); + Assert.Equal(DevicePlatform.WinUI, DeviceInfo.Platform); #elif __IOS__ Assert.Equal(DevicePlatform.iOS, DeviceInfo.Platform); #elif __ANDROID__ From e71a945d86dd5a5bf547b8c11986d01ee0f6f2ce Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 4 Mar 2022 03:16:48 +0800 Subject: [PATCH 13/13] things --- src/Controls/src/Core/Device.cs | 2 +- src/Controls/src/Core/OnPlatform.cs | 25 ++++++++++++------- .../MarkupExtensions/OnPlatformExtension.cs | 5 ++++ .../MarkupExpressionParserTests.cs | 6 ----- .../src/Types/DevicePlatform.shared.cs | 2 +- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/Controls/src/Core/Device.cs b/src/Controls/src/Core/Device.cs index 08b9afcc2ac0..d8ceae7aad8f 100644 --- a/src/Controls/src/Core/Device.cs +++ b/src/Controls/src/Core/Device.cs @@ -25,7 +25,7 @@ public static class Device public const string Android = "Android"; /// [Obsolete("Use Essentials.DevicePlatform.WinUI instead.")] - public const string UWP = WinUI; + public const string UWP = "WinUI"; /// [Obsolete("Use Essentials.DevicePlatform.macOS instead.")] internal const string macOS = "macOS"; diff --git a/src/Controls/src/Core/OnPlatform.cs b/src/Controls/src/Core/OnPlatform.cs index 5794802ce200..9bd436cfa3f9 100644 --- a/src/Controls/src/Core/OnPlatform.cs +++ b/src/Controls/src/Core/OnPlatform.cs @@ -32,16 +32,23 @@ public T Default public static implicit operator T(OnPlatform onPlatform) { - foreach (var onPlat in onPlatform.Platforms) + if (s_valueConverter != null) { - if (onPlat.Platform == null) - continue; - if (!onPlat.Platform.Contains(DeviceInfo.Platform.ToString()) || - (!onPlat.Platform.Contains("UWP") && DeviceInfo.Platform == DevicePlatform.WinUI)) - continue; - if (s_valueConverter == null) - continue; - return (T)s_valueConverter.Convert(onPlat.Value, typeof(T), null, null); + foreach (var onPlat in onPlatform.Platforms) + { + if (onPlat.Platform == null) + continue; + if (!onPlat.Platform.Contains(DeviceInfo.Platform.ToString())) + continue; + return (T)s_valueConverter.Convert(onPlat.Value, typeof(T), null, null); + } + + // fallback for UWP + foreach (var onPlat in onPlatform.Platforms) + { + if (onPlat.Platform != null && onPlat.Platform.Contains("UWP") && DeviceInfo.Platform == DevicePlatform.WinUI) + return (T)s_valueConverter.Convert(onPlat.Value, typeof(T), null, null); + } } return onPlatform.hasDefault ? onPlatform.@default : default(T); diff --git a/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs b/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs index 3374f587f709..0d81892cc6ff 100644 --- a/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs +++ b/src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs @@ -154,6 +154,11 @@ bool TryGetValueForPlatform(out object value) value = UWP; return true; } + if (DeviceInfo.Platform == DevicePlatform.Create("UWP") && UWP != s_notset) + { + value = UWP; + return true; + } #pragma warning restore CS0618 // Type or member is obsolete if (DeviceInfo.Platform == DevicePlatform.Create("WPF") && WPF != s_notset) { diff --git a/src/Controls/tests/Xaml.UnitTests/MarkupExpressionParserTests.cs b/src/Controls/tests/Xaml.UnitTests/MarkupExpressionParserTests.cs index 2d8910000f0c..f245e50bb65c 100644 --- a/src/Controls/tests/Xaml.UnitTests/MarkupExpressionParserTests.cs +++ b/src/Controls/tests/Xaml.UnitTests/MarkupExpressionParserTests.cs @@ -352,22 +352,16 @@ public void BindingWithStaticConverter() [TestCase("{OnPlatform 20, Android=23}", "Android", 23)] [TestCase("{OnPlatform Android=20, iOS=25}", "iOS", 25)] [TestCase("{OnPlatform Android=20, MacCatalyst=25}", "MacCatalyst", 25)] - [TestCase("{OnPlatform Android=20, GTK=25}", "GTK", 25)] - [TestCase("{OnPlatform Android=20, macOS=25}", "macOS", 25)] [TestCase("{OnPlatform Android=20, Tizen=25}", "Tizen", 25)] [TestCase("{OnPlatform Android=20, WinUI=25}", "WinUI", 25)] [TestCase("{OnPlatform Android=20, UWP=25}", "WinUI", 25)] [TestCase("{OnPlatform Android=20, WinUI=25, UWP=20}", "WinUI", 25)] [TestCase("{OnPlatform Android=20, UWP=25}", "UWP", 25)] - [TestCase("{OnPlatform Android=20, WPF=25}", "WPF", 25)] [TestCase("{OnPlatform 20}", "Android", 20)] [TestCase("{OnPlatform 20}", "iOS", 20)] - [TestCase("{OnPlatform 20}", "GTK", 20)] - [TestCase("{OnPlatform 20}", "macOS", 20)] [TestCase("{OnPlatform 20}", "Tizen", 20)] [TestCase("{OnPlatform 20}", "WinUI", 20)] [TestCase("{OnPlatform 20}", "UWP", 20)] - [TestCase("{OnPlatform 20}", "WPF", 20)] [TestCase("{OnPlatform 20}", "Foo", 20)] [TestCase("{OnPlatform Android=23, Default=20}", "Foo", 20)] public void OnPlatformExtension(string markup, string platform, int expected) diff --git a/src/Essentials/src/Types/DevicePlatform.shared.cs b/src/Essentials/src/Types/DevicePlatform.shared.cs index bb47cf495ee4..9f8f0f101798 100644 --- a/src/Essentials/src/Types/DevicePlatform.shared.cs +++ b/src/Essentials/src/Types/DevicePlatform.shared.cs @@ -26,7 +26,7 @@ namespace Microsoft.Maui.Essentials /// [Obsolete("Use WinUI instead.")] - public static DevicePlatform UWP { get; } = WinUI; + public static DevicePlatform UWP { get; } = new DevicePlatform(nameof(WinUI)); public static DevicePlatform WinUI { get; } = new DevicePlatform(nameof(WinUI));