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

Fix crash in .NET 9 #118

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions Maui.Tabs/Maui.Tabs.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks>net9.0</TargetFrameworks>
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's certainly ok to remove net6.0, since it's out of support already (at least regarding MAUI), but shouldn't one also add net8.0 here, as it currently is the only stable MAUI version with active support?

<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->
<RootNamespace>Sharpnado.Tabs</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<UseMaui>true</UseMaui>
<ImplicitUsings>enable</ImplicitUsings>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
Expand Down Expand Up @@ -128,6 +127,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)">
<PrivateAssets>all</PrivateAssets>
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="Sharpnado.TaskMonitor" Version="1.0.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164">
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion Tabs/Tabs/DelayedView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override void LoadView()
async () =>
{
View? view = null;
if (Device.RuntimePlatform == Device.Android)
if (DeviceInfo.Platform == DevicePlatform.Android)
{
await Task.Run(
() =>
Expand Down
63 changes: 27 additions & 36 deletions Tabs/Tabs/TabHostView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using Microsoft.Maui.Controls.Shapes;


#if !NET6_0_OR_GREATER
using Sharpnado.Shades;
Expand Down Expand Up @@ -122,7 +124,7 @@ public class TabHostView : Shadows
private const string Tag = nameof(TabHostView);

private readonly Grid _grid;
private readonly Frame _frame;
private readonly Border _border;
private List<TabItem> _selectableTabs = new();

private INotifyCollectionChanged _currentNotifyCollection;
Expand Down Expand Up @@ -154,20 +156,21 @@ public TabHostView()
BackgroundColor = BackgroundColor,
};

_frame = new Frame
_border = new Border
{
Padding = 0,
HasShadow = false,
IsClippedToBounds = true,
CornerRadius = CornerRadius,
StrokeShape = new RoundRectangle()
{
CornerRadius = CornerRadius,
},
#if NET6_0_OR_GREATER
BackgroundColor = Colors.Transparent,
#else
BackgroundColor = Color.Transparent,
#endif
HorizontalOptions = LayoutOptions.Fill,
VerticalOptions = LayoutOptions.Fill,
BorderColor = SegmentedOutlineColor,
Stroke = SegmentedOutlineColor,
};

UpdateTabType();
Expand Down Expand Up @@ -446,12 +449,12 @@ private TabItem CreateTabItem(object item)

private void UpdateSegmentedOutlineColor()
{
if (_frame == null)
if (_border == null)
{
return;
}

_frame.BorderColor = SegmentedOutlineColor;
_border.Stroke = SegmentedOutlineColor;
foreach (var separator in _grid.Children.Where(c => c is BoxView))
{

Expand All @@ -467,7 +470,7 @@ private void UpdateBackgroundColor()
{
if (IsSegmented)
{
if (_frame == null)
if (_border == null)
{
return;
}
Expand All @@ -477,7 +480,7 @@ private void UpdateBackgroundColor()
#else
_grid.BackgroundColor = Color.Transparent;
#endif
_frame.BackgroundColor = BackgroundColor;
_border.BackgroundColor = BackgroundColor;
return;
}

Expand All @@ -487,7 +490,7 @@ private void UpdateBackgroundColor()
}

#if NET6_0_OR_GREATER
_frame.BackgroundColor = Colors.Transparent;
_border.BackgroundColor = Colors.Transparent;
#else
_frame.BackgroundColor = Color.Transparent;
#endif
Expand All @@ -496,12 +499,15 @@ private void UpdateBackgroundColor()

private void UpdateCornerRadius()
{
if (_frame == null)
if (_border == null)
{
return;
}

_frame.CornerRadius = CornerRadius;
_border.StrokeShape = new RoundRectangle()
{
CornerRadius = CornerRadius,
};
}

private void AddSeparators()
Expand Down Expand Up @@ -583,8 +589,8 @@ private void UpdateTabType()

if (IsSegmented)
{
_frame.Content = _grid;
_frame.BackgroundColor = BackgroundColor;
_border.Content = _grid;
_border.BackgroundColor = BackgroundColor;

#if NET6_0_OR_GREATER
_grid.BackgroundColor = Colors.Transparent;
Expand All @@ -594,10 +600,10 @@ private void UpdateTabType()
}
else
{
_frame.Content = null;
_border.Content = null;

#if NET6_0_OR_GREATER
_frame.BackgroundColor = Colors.Transparent;
_border.BackgroundColor = Colors.Transparent;
#else
_frame.BackgroundColor = Color.Transparent;
#endif
Expand All @@ -619,7 +625,7 @@ private void UpdateTabType()

if (IsSegmented)
{
_scrollView.Content = _frame;
_scrollView.Content = _border;
}
else
{
Expand All @@ -645,7 +651,7 @@ private void UpdateTabType()
{
if (IsSegmented)
{
base.Content = _frame;
base.Content = _border;
}
else
{
Expand Down Expand Up @@ -707,23 +713,8 @@ private void AddTapCommand(TabItem tabItem)
return;
}

if (Device.RuntimePlatform == Device.UWP)
{
tabItem.GestureRecognizers.Add(
new TapGestureRecognizer { Command = TabItemTappedCommand, CommandParameter = tabItem });
}
else
{
#if NET6_0_OR_GREATER
Sharpnado.Tabs.Effects.TouchEffect.SetColor(tabItem, tabItem.SelectedTabColor);
Sharpnado.Tabs.Effects.Commands.SetTap(tabItem, TabItemTappedCommand);
Sharpnado.Tabs.Effects.Commands.SetTapParameter(tabItem, tabItem);
#else
ViewEffect.SetTouchFeedbackColor(tabItem, tabItem.SelectedTabColor);
TapCommandEffect.SetTap(tabItem, TabItemTappedCommand);
TapCommandEffect.SetTapParameter(tabItem, tabItem);
#endif
}
tabItem.GestureRecognizers.Add(
new TapGestureRecognizer { Command = TabItemTappedCommand, CommandParameter = tabItem });
}

private void OnChildAdded(TabItem tabItem, int index)
Expand Down