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

Remove unsupported targets in Device class #4491

Merged
merged 19 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> callback)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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 @@ -27,6 +27,9 @@ 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(EffectsPage), "Effects",
"Apply Effects to a View."),

Expand Down
9 changes: 5 additions & 4 deletions src/Controls/src/Core/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ public static class Device
/// <include file="../../docs/Microsoft.Maui.Controls/Device.xml" path="//Member[@MemberName='Android']/Docs" />
public const string Android = "Android";
/// <include file="../../docs/Microsoft.Maui.Controls/Device.xml" path="//Member[@MemberName='UWP']/Docs" />
public const string UWP = "UWP";
internal const string UWP = "UWP";
Redth marked this conversation as resolved.
Show resolved Hide resolved
/// <include file="../../docs/Microsoft.Maui.Controls/Device.xml" path="//Member[@MemberName='macOS']/Docs" />
public const string macOS = "macOS";
internal const string macOS = "macOS";
/// <include file="../../docs/Microsoft.Maui.Controls/Device.xml" path="//Member[@MemberName='GTK']/Docs" />
public const string GTK = "GTK";
internal const string GTK = "GTK";
/// <include file="../../docs/Microsoft.Maui.Controls/Device.xml" path="//Member[@MemberName='Tizen']/Docs" />
public const string Tizen = "Tizen";
/// <include file="../../docs/Microsoft.Maui.Controls/Device.xml" path="//Member[@MemberName='WPF']/Docs" />
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";

Expand Down
17 changes: 12 additions & 5 deletions src/Controls/src/Xaml/MarkupExtensions/OnPlatformExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down