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

Match Catalyst Template to iOS for Shell Flyout Items #25056

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/Controls/src/Core/Shell/BaseShellItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, str
IgnoreSafeArea = true
};

if (DeviceInfo.Platform == DevicePlatform.WinUI)
if (OperatingSystem.IsWindows())
grid.ColumnSpacing = grid.RowSpacing = 0;

grid.Resources = new ResourceDictionary();
Expand Down Expand Up @@ -387,7 +387,7 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, str
var selectedState = new VisualState();
selectedState.Name = "Selected";

if (DeviceInfo.Platform != DevicePlatform.WinUI)
if (!OperatingSystem.IsWindows())
{
selectedState.Setters.Add(new Setter
{
Expand All @@ -406,19 +406,19 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, str

defaultGridClass.Setters.Add(new Setter { Property = VisualStateManager.VisualStateGroupsProperty, Value = groups });

if (DeviceInfo.Platform == DevicePlatform.Android)
if (OperatingSystem.IsAndroid())
defaultGridClass.Setters.Add(new Setter { Property = Grid.HeightRequestProperty, Value = 50 });
else
defaultGridClass.Setters.Add(new Setter { Property = Grid.HeightRequestProperty, Value = 44 });


ColumnDefinitionCollection columnDefinitions = new ColumnDefinitionCollection();

if (DeviceInfo.Platform == DevicePlatform.Android)
if (OperatingSystem.IsAndroid())
columnDefinitions.Add(new ColumnDefinition { Width = 54 });
else if (DeviceInfo.Platform == DevicePlatform.iOS)
else if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst())
columnDefinitions.Add(new ColumnDefinition { Width = 50 });
else if (DeviceInfo.Platform == DevicePlatform.WinUI)
else if (OperatingSystem.IsWindows())
columnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
else if (DeviceInfo.Platform == DevicePlatform.Tizen)
columnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
Expand All @@ -432,11 +432,11 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, str
var image = new Image();

double sizeRequest = -1;
if (DeviceInfo.Platform == DevicePlatform.Android)
if (OperatingSystem.IsAndroid())
sizeRequest = 24;
else if (DeviceInfo.Platform == DevicePlatform.iOS)
else if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst())
sizeRequest = 22;
else if (DeviceInfo.Platform == DevicePlatform.WinUI)
else if (OperatingSystem.IsWindows())
sizeRequest = 16;
else if (DeviceInfo.Platform == DevicePlatform.Tizen)
sizeRequest = 25;
Expand All @@ -447,7 +447,7 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, str
defaultImageClass.Setters.Add(new Setter() { Property = Image.WidthRequestProperty, Value = sizeRequest });
}

if (DeviceInfo.Platform == DevicePlatform.WinUI)
if (OperatingSystem.IsWindows())
{
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) });
Expand All @@ -464,7 +464,7 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, str

grid.Add(label, 1, 0);

if (DeviceInfo.Platform == DevicePlatform.Android)
if (OperatingSystem.IsAndroid())
{
object textColor;

Expand All @@ -482,12 +482,12 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, str
defaultLabelClass.Setters.Add(new Setter { Property = Label.FontFamilyProperty, Value = "sans-serif-medium" });
defaultLabelClass.Setters.Add(new Setter { Property = Label.MarginProperty, Value = new Thickness(20, 0, 0, 0) });
}
else if (DeviceInfo.Platform == DevicePlatform.iOS)
else if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst())
{
defaultLabelClass.Setters.Add(new Setter { Property = Label.FontSizeProperty, Value = 14 });
defaultLabelClass.Setters.Add(new Setter { Property = Label.FontAttributesProperty, Value = FontAttributes.Bold });
}
else if (DeviceInfo.Platform == DevicePlatform.WinUI)
else if (OperatingSystem.IsWindows())
{
defaultLabelClass.Setters.Add(new Setter { Property = Label.HorizontalOptionsProperty, Value = LayoutOptions.Start });
defaultLabelClass.Setters.Add(new Setter { Property = Label.HorizontalTextAlignmentProperty, Value = TextAlignment.Start });
Expand Down Expand Up @@ -537,6 +537,16 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, str
return grid;
});
}

#if NETSTANDARD
sealed class OperatingSystem
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right place for it? Do we need this in more places?

Copy link
Member Author

@PureWeen PureWeen Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe? The problem I ran into putting this into a more general place is that you start to get errors about "OperatingSystem" is defined in multiple places. Unfortunately, NS has the System.OperatingSystem type it just doesn't have anything useful for us.

Another thought I had was to just call it OperatingSystemNS and then add a special using at the top, which did work.

Not sure the cleverest way to make this reusable.

Maybe we add our own internal static? MAUIOS that we can use generally?

{
public static bool IsAndroid() => false;
public static bool IsIOS() => false;
public static bool IsMacCatalyst() => false;
public static bool IsWindows() => false;
}
#endif
}

public interface IQueryAttributable
Expand Down
Loading