Skip to content

Commit

Permalink
Remove unsupported targets in Device class (#4491)
Browse files Browse the repository at this point in the history
* Remove unsupported targets in Device class

* Fixed broken tests

* Deprecate UWP target

* Allow to use UWP target on XAML

* Fix build errors

* comments

* UWP == WinUI

* Fix Build errors

* Added more tests

* fix

* vbnm

* More fixes

* things

Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
  • Loading branch information
jsuarezruiz and mattleibow committed Mar 3, 2022
1 parent b915256 commit fefa81f
Show file tree
Hide file tree
Showing 39 changed files with 172 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static Picker CreateImageSourcePicker(string title, Action<Func<ImageSource>> on
case Device.iOS:
fontFamily = "Ionicons";
break;
case Device.UWP:
case Device.WinUI:
fontFamily = "Assets/Fonts/ionicons.ttf#ionicons";
break;
case Device.Android:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public LabelGallery()
case Device.Android:
fontName = "sans-serif-light";
break;
case Device.UWP:
case Device.WinUI:
fontName = "Comic Sans MS";
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/Compatibility/ControlGallery/src/Core/TestCases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public static NavigationPage GetTestCases()
default:
page.Title = "Test Cases";
break;
case Device.UWP:
case Device.WinUI:
page.Title = "Tests";
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Bugzilla22229()
case Device.Android:
_prefix = "";
break;
case Device.UWP:
case Device.WinUI:
_prefix = "Assets/";
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected override void Init()

KeyboardFlags spellCheckForUwp = KeyboardFlags.None;

if (DeviceInfo.Platform == DevicePlatform.UWP)
if (DeviceInfo.Platform == DevicePlatform.WinUI)
{
spellCheckForUwp = KeyboardFlags.Spellcheck;
}
Expand All @@ -63,12 +63,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 (DeviceInfo.Platform == DevicePlatform.UWP)
if (DeviceInfo.Platform == DevicePlatform.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" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Issue1705_2()
Children.Add(_page2);
Children.Add(_page3);

if (DeviceInfo.Platform == DevicePlatform.UWP)
if (DeviceInfo.Platform == DevicePlatform.WinUI)
Children.Add(new HeaderIconsControlPage(this) { Title = "UWPSpecifics" });
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected override void Init()
layout.Children.Add(_result);
layout.Children.Add(button);

if (DeviceInfo.Platform == DevicePlatform.UWP)
if (DeviceInfo.Platform == DevicePlatform.WinUI)
layout.Children.Add(new Label { Text = "\xE76E", FontFamily = "Segoe MDL2 Assets", FontSize = 32 });

Content = layout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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 = DeviceInfo.Platform == DevicePlatform.UWP ? "Press Tab to focus the first entry. " : "";
string uwp_instructions = DeviceInfo.Platform == DevicePlatform.WinUI ? "Press Tab to focus the first entry. " : "";

Content = new StackLayout()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override void Init()
FontFamily = "FontAwesome5Free-Solid"
};

if (DeviceInfo.Platform == DevicePlatform.UWP)
if (DeviceInfo.Platform == DevicePlatform.WinUI)
((FontImageSource)button.ImageSource).FontFamily = "Assets/Fonts/fa-solid-900.ttf#Font Awesome 5 Free";

stack.Children.Add(label);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public CannotScrollRepro()
{
BackgroundColor = Colors.Aqua,
Orientation = ScrollOrientation.Horizontal,
HeightRequest = DeviceInfo.Platform == DevicePlatform.UWP ? 80 : 44,
HeightRequest = DeviceInfo.Platform == DevicePlatform.WinUI ? 80 : 44,
Content = buttonStack
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public PopupStackLayout()
HorizontalOptions = LayoutOptions.Start,
VerticalOptions = LayoutOptions.Start,
Orientation = this.Orientation,
WidthRequest = DeviceInfo.Platform == DevicePlatform.UWP ? 20 : 50,
WidthRequest = DeviceInfo.Platform == DevicePlatform.WinUI ? 20 : 50,
};

this.SetBinding(HeightRequestProperty, new Binding(nameof(Height), BindingMode.OneWay, source: showButton));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ static string DefaultFontFamily()
var fontFamily = "";
if (DeviceInfo.Platform == DevicePlatform.iOS)
fontFamily = "Ionicons";
else if (DeviceInfo.Platform == DevicePlatform.UWP)
else if (DeviceInfo.Platform == DevicePlatform.WinUI)
fontFamily = "Assets/Fonts/ionicons.ttf#ionicons";
else
fontFamily = "fonts/ionicons.ttf#";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ static string DefaultFontFamily()
var fontFamily = "";
if (DeviceInfo.Platform == DevicePlatform.iOS)
fontFamily = "Ionicons";
else if (DeviceInfo.Platform == DevicePlatform.UWP)
else if (DeviceInfo.Platform == DevicePlatform.WinUI)
fontFamily = "Assets/Fonts/ionicons.ttf#ionicons";
else
fontFamily = "fonts/ionicons.ttf#";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public GroupedReorderingGallery(IItemsLayout itemsLayout)
Text = "Reordering of grouped sources is not supported on Windows!",
FontSize = 24,
FontAttributes = FontAttributes.Bold,
IsVisible = (DeviceInfo.Platform == DevicePlatform.UWP),
IsVisible = (DeviceInfo.Platform == DevicePlatform.WinUI),
BackgroundColor = Colors.Red
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async void UpdateItemsSourceType(ItemsSourceGenerator generator, ItemsSourceType
{
generator.GenerateItems(itemsSourceType);

if (DeviceInfo.Platform == DevicePlatform.UWP && !(collectionView.ItemsSource is INotifyCollectionChanged))
if (DeviceInfo.Platform == DevicePlatform.WinUI && !(collectionView.ItemsSource is INotifyCollectionChanged))
{
await DisplayAlert("Warning!", "Reordering on UWP/WinUI only works with ObservableCollections!", "OK");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CustomSwipeItemGallery()
}
};

if (DeviceInfo.Platform != DevicePlatform.UWP)
if (DeviceInfo.Platform != DevicePlatform.WinUI)
{
layout.Children.Add(GalleryBuilder.NavButton("SwipeItemView Gallery", () => new CustomSwipeItemViewGallery(), Navigation));
layout.Children.Add(GalleryBuilder.NavButton("CustomSwipeItem Size Gallery", () => new CustomSizeSwipeViewGallery(), Navigation));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static string DefaultFontFamily()
var fontFamily = "";
if (DeviceInfo.Platform == DevicePlatform.iOS)
fontFamily = "Ionicons";
else if (DeviceInfo.Platform == DevicePlatform.UWP)
else if (DeviceInfo.Platform == DevicePlatform.WinUI)
fontFamily = "Assets/Fonts/ionicons.ttf#ionicons";
else
fontFamily = "fonts/ionicons.ttf#";
Expand Down
17 changes: 17 additions & 0 deletions src/Controls/samples/Controls.Sample/Pages/Core/DevicePage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<views:BasePage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Pages.DevicePage"
xmlns:views="clr-namespace:Maui.Controls.Sample.Pages.Base"
Title="Device">
<ContentPage.Content>
<StackLayout
HorizontalOptions="Center">
<Label
Text="{OnPlatform Default='Default Platform', Android='Android', iOS='iOS', MacCatalyst='MacCatalyst', Tizen='Tizen', WinUI='WinUI'}" />
<Label
Text="{OnIdiom Default='Default Idiom', Phone='Phone', Tablet='Tablet', Desktop='Desktop', TV='TV', Watch='Watch'}" />
</StackLayout>
</ContentPage.Content>
</views:BasePage>
10 changes: 10 additions & 0 deletions src/Controls/samples/Controls.Sample/Pages/Core/DevicePage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Maui.Controls.Sample.Pages
{
public partial class DevicePage
{
public DevicePage()
{
InitializeComponent();
}
}
}
10 changes: 1 addition & 9 deletions src/Controls/samples/Controls.Sample/Pages/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</views:BasePage.Resources>
<ScrollView>
<Grid
RowDefinitions="150, *, Auto, Auto"
RowDefinitions="150, *, Auto"
RowSpacing="0">
<!-- HEADER -->
<Image
Expand Down Expand Up @@ -118,14 +118,6 @@
Grid.Row="2"
Text="Microsoft Corporation © 2021"
Style="{StaticResource FooterStyle}" />
<StackLayout Orientation="Horizontal" Grid.Row="3" HorizontalOptions="Center">
<Label
Text="{OnPlatform Default='Default Platform', Android='Android', iOS='iOS', macOS='macOS', MacCatalyst='MacCatalyst', Tizen='Tizen', UWP='UWP'}"
Style="{StaticResource FooterStyle}" />
<Label
Text="{OnIdiom Default='Default Idiom', Phone='Phone', Tablet='Tablet', Desktop='Desktop', TV='TV', Watch='Watch'}"
Style="{StaticResource FooterStyle}" />
</StackLayout>
</Grid>
</ScrollView>
</views:BasePage>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public class CoreViewModel : BaseGalleryViewModel

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(DispatcherPage), "Dispatcher",
"Managing UI thread access with dispatchers and timers."),

Expand Down
12 changes: 7 additions & 5 deletions src/Controls/src/Core/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@ public static class Device
[Obsolete("Use Essentials.DevicePlatform.Android instead.")]
public const string Android = "Android";
/// <include file="../../docs/Microsoft.Maui.Controls/Device.xml" path="//Member[@MemberName='UWP']/Docs" />
[Obsolete("Use Essentials.DevicePlatform.UWP instead.")]
public const string UWP = "UWP";
[Obsolete("Use Essentials.DevicePlatform.WinUI instead.")]
public const string UWP = "WinUI";
/// <include file="../../docs/Microsoft.Maui.Controls/Device.xml" path="//Member[@MemberName='macOS']/Docs" />
[Obsolete("Use Essentials.DevicePlatform.macOS instead.")]
public const string macOS = "macOS";
internal const string macOS = "macOS";
/// <include file="../../docs/Microsoft.Maui.Controls/Device.xml" path="//Member[@MemberName='GTK']/Docs" />
[Obsolete("Use Essentials.DevicePlatform.GTK instead.")]
public const string GTK = "GTK";
internal const string GTK = "GTK";
/// <include file="../../docs/Microsoft.Maui.Controls/Device.xml" path="//Member[@MemberName='Tizen']/Docs" />
[Obsolete("Use Essentials.DevicePlatform.Tizen instead.")]
public const string Tizen = "Tizen";
[Obsolete("Use Essentials.DevicePlatform.WinUI instead.")]
public const string WinUI = "WinUI";
/// <include file="../../docs/Microsoft.Maui.Controls/Device.xml" path="//Member[@MemberName='WPF']/Docs" />
[Obsolete("Use Essentials.DevicePlatform.WPF instead.")]
public const string WPF = "WPF";
internal const string WPF = "WPF";
[Obsolete("Use Essentials.DevicePlatform.MacCatalyst instead.")]
public const string MacCatalyst = "MacCatalyst";
[Obsolete("Use Essentials.DevicePlatform.tvOS instead.")]
Expand Down
4 changes: 2 additions & 2 deletions src/Controls/src/Core/DeviceStateTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void UpdateState()
SetActive(DeviceInfo.Platform == DevicePlatform.Android);
else if (device == DevicePlatform.iOS)
SetActive(DeviceInfo.Platform == DevicePlatform.iOS);
else if (device == DevicePlatform.UWP)
SetActive(DeviceInfo.Platform == DevicePlatform.UWP);
else if (device == DevicePlatform.WinUI || device == DevicePlatform.Create("UWP"))
SetActive(DeviceInfo.Platform == DevicePlatform.WinUI);
}
}
}
24 changes: 16 additions & 8 deletions src/Controls/src/Core/OnPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,23 @@ public T Default

public static implicit operator T(OnPlatform<T> onPlatform)
{
foreach (var onPlat in onPlatform.Platforms)
if (s_valueConverter != null)
{
if (onPlat.Platform == null)
continue;
if (!onPlat.Platform.Contains(DeviceInfo.Platform.ToString()))
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);
Expand Down
Loading

0 comments on commit fefa81f

Please sign in to comment.