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

.NET 9 Support #148

Open
wants to merge 6 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
18 changes: 18 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project>
<PropertyGroup>
<MauiVersion>9.0.30</MauiVersion>
<SkipValidateMauiImplicitPackageReferences>true</SkipValidateMauiImplicitPackageReferences>

<NetVersion>9</NetVersion>

<StandardTargetFramework>net$(NetVersion).0</StandardTargetFramework>
<IosTargetFramework>net$(NetVersion).0-ios</IosTargetFramework>
<AndroidTargetFramework>net$(NetVersion).0-android</AndroidTargetFramework>
<MacTargetFramework>net$(NetVersion).0-maccatalyst</MacTargetFramework>
<WindowsTargetFramework>net$(NetVersion).0-windows10.0.19041.0</WindowsTargetFramework>

<MauiPlatformTargetFrameworks>$(StandardTargetFramework);$(AndroidTargetFramework);$(IosTargetFramework);$(MacTargetFramework)</MauiPlatformTargetFrameworks>
<MauiPlatformTargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(StandardTargetFramework);$(AndroidTargetFramework);$(IosTargetFramework);$(MacTargetFramework);$(WindowsTargetFramework)</MauiPlatformTargetFrameworks>
</PropertyGroup>

</Project>
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
-->
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="CommunityToolkit.Maui" Version="7.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageVersion Include="CommunityToolkit.Maui" Version="11.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Debug" Version="9.0.1" />
<PackageVersion Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageVersion Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
<PackageVersion Include="The49.Maui.Insets" Version="1.0.0-alpha7" />
Expand Down
2 changes: 2 additions & 0 deletions The49.Maui.BottomSheet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "The49.Maui.BottomSheet", "s
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8A921141-CFBB-4A46-8C99-9D3D3F36333B}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
global.json = global.json
EndProjectSection
EndProject
Global
Expand Down
4 changes: 3 additions & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"sdk": {
"version": "8.0.100"
"version": "9.0.101",
"rollForward": "latestFeature",
"allowPrerelease": false
}
}
7 changes: 4 additions & 3 deletions sample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
namespace The49.Maui.BottomSheet.Sample;

namespace The49.Maui.BottomSheet.Sample;

public partial class App : Application
{
public App()
{
InitializeComponent();

MainPage = new AppShell();
}

protected override Window CreateWindow(IActivationState? activationState) => new(new AppShell());
}
22 changes: 15 additions & 7 deletions sample/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private void OpenRatioSheet()
var page = new SimplePage();
page.Detents = new DetentsCollection()
{
new RatioDetent() { Ratio = .6f },
new RatioDetent() { Ratio = .8f },
};
page.ShowAsync(Window);
}
Expand All @@ -287,11 +287,11 @@ private void OpenHeightSheet()
page.ShowAsync(Window);
}

void OpenTextSizing()
void OpenTextSizing()
{
var p = new TextSheet();

p.ShowAsync(Window);
p.ShowAsync(Window);
}

void OpenDismissed()
Expand Down Expand Up @@ -442,12 +442,20 @@ void OpenCustomizeBehavior()

private void list_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var item = (DemoEntry)list.SelectedItem;
if (item == null)
if (sender is not CollectionView collectionView)
{
return;
}
item.Command.Execute(null);

var item = collectionView.SelectedItem as DemoEntry;

if (item is not null)
{
item.Command.Execute(null);
}

// Unselect so we can tap the same row multiple times!
collectionView.SelectedItem = null;
}

void list_Scrolled(object sender, ItemsViewScrolledEventArgs e)
Expand Down
9 changes: 5 additions & 4 deletions sample/The49.Maui.BottomSheet.Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks>$(MauiPlatformTargetFrameworks);</TargetFrameworks>
<OutputType Condition="'$(TargetFramework)' != '$(StandardTargetFramework)'">Exe</OutputType>

<OutputType>Exe</OutputType>
<RootNamespace>The49.Maui.BottomSheet.Sample</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>annotations</Nullable>

<MauiEnableXamlCBindingWithSourceCompilation>true</MauiEnableXamlCBindingWithSourceCompilation>

<!-- Display name -->
<ApplicationTitle>The49.Maui.BottomSheet</ApplicationTitle>

Expand All @@ -21,7 +22,7 @@
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Models/ContentDetent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public override double GetHeight(BottomSheet page, double maxSheetHeight)
// HACK: from 'page.Window.Width' to 'page.Window?.Width ?? page.Width'
var r = page.Content.Measure(page.Window?.Width ?? page.Width - page.Padding.HorizontalThickness, maxSheetHeight);

return Math.Min(maxSheetHeight, r.Request.Height + page.Padding.VerticalThickness);
return Math.Min(maxSheetHeight, r.Height + page.Padding.VerticalThickness);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@

<FrameLayout
android:id="@+id/design_bottom_sheet"
style="@style/Widget.Material3.BottomSheet.Modal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top"
app:layout_behavior="@string/bottom_sheet_behavior" />
app:behavior_hideable="false"
app:behavior_peekHeight="56dp"
android:background="@color/white"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

Expand Down
4 changes: 4 additions & 0 deletions src/Platforms/Android/Resources/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#FFFFFF</color>
</resources>
39 changes: 24 additions & 15 deletions src/Platforms/iOS/BottomSheetContainer.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
using CoreGraphics;
using Microsoft.Maui.Platform;
using Microsoft.Maui.Platform;
using UIKit;

namespace The49.Maui.BottomSheet;

internal class BottomSheetContainer : UIView
{
BottomSheet _sheet;
UIView _view;

// Can't get the sheet max height with large and medium detents
// custom detents are not supported on iOS 15
// can't use largestUndimmedIdentifier or selected detent with custom detents on iOS 16
// So I guess we'll just have to calculate the sheet height ourselves then
// This number was found by getting the full screen height, subtracting the sheet's UIView height and the top inset
// This seems to be the spacing iOS leaves at the top of the screen when a sheet is fullscreen
// TODO: Check if this is the same number for fullscreen sheets opened on top of another sheet
UIView _view;
// Can't get the sheet max height with large and medium detents
// custom detents are not supported on iOS 15
// can't use largestUndimmedIdentifier or selected detent with custom detents on iOS 16
// So I guess we'll just have to calculate the sheet height ourselves then
// This number was found by getting the full screen height, subtracting the sheet's UIView height and the top inset
// This seems to be the spacing iOS leaves at the top of the screen when a sheet is fullscreen
// TODO: Check if this is the same number for fullscreen sheets opened on top of another sheet
const int SheetTopSpacing = 10;

double CalculateTallestDetent(double heightConstraint)
{
var window = UIApplication.SharedApplication.KeyWindow;
var window = UIApplication.SharedApplication.KeyWindow;
var topPadding = window?.SafeAreaInsets.Top ?? 0;
var maximumDetentValue = heightConstraint - topPadding - SheetTopSpacing;
var maximumDetentValue = heightConstraint - topPadding - SheetTopSpacing;

return _sheet.GetEnabledDetents().Select(d => d.GetHeight(_sheet, maximumDetentValue)).Max();
}
Expand All @@ -37,9 +37,18 @@ public override void LayoutSubviews()
{
base.LayoutSubviews();
var h = CalculateTallestDetent(_sheet.Window.Height - BottomSheetManager.KeyboardHeight);
_view.Frame = new CGRect(0, 0, Bounds.Width, h);
_sheet.Arrange(_view.Frame.ToRectangle());
_sheet.Controller.Layout();

// Convert to int to roughly check whether heights match & avoid doing as a double...
var frameHeightInt = Convert.ToInt32(_view.Frame.Height);
var hInt = Convert.ToInt32(h);

// If we don't guard here, there will be an infinite layout loop for certain detents...
if (frameHeightInt != hInt)
{
_view.Frame = new CGRect(0, 0, Bounds.Width, h);
_sheet.Arrange(_view.Frame.ToRectangle());
_sheet.Controller.Layout();
}
}
}

35 changes: 16 additions & 19 deletions src/Platforms/iOS/BottomSheetControllerDelegate.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
using System.Runtime.Versioning;
using UIKit;

namespace The49.Maui.BottomSheet;

[SupportedOSPlatform("ios15.0")]
internal class BottomSheetControllerDelegate : UISheetPresentationControllerDelegate
{
BottomSheet _sheet;
using System.Runtime.Versioning;
using UIKit;

public BottomSheetControllerDelegate(BottomSheet sheet) : base()
{
_sheet = sheet;
}
namespace The49.Maui.BottomSheet;

[SupportedOSPlatform("ios15.0")]
internal class BottomSheetControllerDelegate(BottomSheet sheet) : UISheetPresentationControllerDelegate
{
public override void DidDismiss(UIPresentationController presentationController)
{
_sheet.CachedDetents.Clear();
_sheet.NotifyDismissed();
sheet.CachedDetents.Clear();
sheet.NotifyDismissed();
}

public override void DidChangeSelectedDetentIdentifier(UISheetPresentationController sheetPresentationController)
{
((BottomSheetHandler)_sheet.Handler).UpdateSelectedDetent(_sheet);
public override void DidChangeSelectedDetentIdentifier(UISheetPresentationController sheetPresentationController)
{
if (sheet.Handler is BottomSheetHandler bottomSheetHandler)
{
bottomSheetHandler.UpdateSelectedDetent(sheet);
}
}
}

Loading