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

Net8 upgrade #102

Merged
merged 3 commits into from
Jan 14, 2024
Merged
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
29 changes: 24 additions & 5 deletions Mopups/Mopups.Maui/Mopups.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>

<TargetFrameworks>net7.0;net7.0-ios;net7.0-maccatalyst;;net7.0-android33.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks>net8.0;net8.0-maccatalyst;net8.0-ios;net8.0-android34.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>

<!-- iOS, Android, MacCatalyst -->
<UseMaui>true</UseMaui>
Expand All @@ -27,12 +27,14 @@
<Authors>Tyson Hooker,Maksym Koshovyi,Aswin P G, Kirill Lyubimov, Martijn Van Dijk, Shane Neuville</Authors>
<Company>$(CompanyName)</Company>
<PackageTags>Mopups;Popups;Maui;rg;Xamarin;ios;android;Windows;MacOS;Mopups;Dialogs;macos;windows</PackageTags>
<Version>1.2.0</Version>
<Version>1.3.0</Version>
<Title>Mopups (Maui Popups)</Title>
<PackageReleaseNotes>Finally did a release that should support Windows
Added in previous work for awaitable popups directly into this repo under prebaked.</PackageReleaseNotes>
<PackageReleaseNotes>Added in several fixes from the community (THANKYOU!)

Upgraded to .NET 8</PackageReleaseNotes>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PublishAot>True</PublishAot>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-android|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -80,6 +82,23 @@ Added in previous work for awaitable popups directly into this repo under prebak
<PlatformTarget>AnyCPU</PlatformTarget>
<Deterministic>False</Deterministic>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-ios|AnyCPU'">
<EnableSGenConc>True</EnableSGenConc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-ios|AnyCPU'">
<EnableSGenConc>True</EnableSGenConc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android34.0|AnyCPU'">
<AndroidLinkTool>r8</AndroidLinkTool>
<RunAOTCompilation>True</RunAOTCompilation>
<EnableLLVM>True</EnableLLVM>
<AndroidEnableProfiledAot>True</AndroidEnableProfiledAot>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android34.0|AnyCPU'">
<RunAOTCompilation>True</RunAOTCompilation>
<EnableLLVM>True</EnableLLVM>
<AndroidEnableProfiledAot>True</AndroidEnableProfiledAot>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AsyncAwaitBestPractices" Version="6.0.4" />
</ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions Mopups/Mopups.Maui/Pages/PopupPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public bool DisableAndroidAccessibilityHandling

public PopupPage()
{
//BackgroundColor = Color.FromArgb("#80000000");
BackgroundColor = Colors.Transparent;
}

protected override bool OnBackButtonPressed()
Expand Down Expand Up @@ -284,7 +284,7 @@ protected virtual bool OnBackgroundClicked()
return CloseWhenBackgroundIsClicked;
}

internal void SendBackgroundClick()
internal bool SendBackgroundClick()
{
BackgroundClicked?.Invoke(this, EventArgs.Empty);
if (BackgroundClickedCommand?.CanExecute(BackgroundClickedCommandParameter) == true)
Expand All @@ -294,6 +294,8 @@ internal void SendBackgroundClick()
if (OnBackgroundClicked())
{
MopupService.Instance.RemovePageAsync(this).SafeFireAndForget();
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ public class PopupPageHandler : PageHandler

public PopupPageHandler()
{
this.SetMauiContext(MauiApplication.Current.Application.Windows[0].Handler.MauiContext);
SetMauiContext(MauiApplication.Current.Application.Windows[0].Handler.MauiContext);
}

public PopupPageHandler(IMauiContext context)
{
SetMauiContext(context);
}

protected override void ConnectHandler(ContentViewGroup platformView)
Expand Down
20 changes: 13 additions & 7 deletions Mopups/Mopups.Maui/Platforms/Android/Impl/AndroidMopups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ public static bool SendBackPressed(Action? backPressedHandler = null)

public Task AddAsync(PopupPage page)
{
HandleAccessibility(true, page.DisableAndroidAccessibilityHandling);
HandleAccessibility(true, page.DisableAndroidAccessibilityHandling, page.Parent as Page);

page.Parent = MauiApplication.Current.Application.Windows[0].Content as Element;
var AndroidNativeView = IPopupPlatform.GetOrCreateHandler<PopupPageHandler>(page).PlatformView as Android.Views.View;
DecoreView?.AddView(AndroidNativeView);
page.Parent ??= MauiApplication.Current.Application.Windows[0].Content as Element;

return PostAsync(AndroidNativeView);
var handler = page.Handler ??= new PopupPageHandler(page.Parent.Handler.MauiContext);

var androidNativeView = handler.PlatformView as Android.Views.View;
var decoreView = Platform.CurrentActivity?.Window?.DecorView as FrameLayout;

decoreView?.AddView(androidNativeView);

return PostAsync(androidNativeView);
}

public Task RemoveAsync(PopupPage page)
Expand All @@ -51,7 +57,7 @@ public Task RemoveAsync(PopupPage page)

if (renderer != null)
{
HandleAccessibility(false, page.DisableAndroidAccessibilityHandling);
HandleAccessibility(false, page.DisableAndroidAccessibilityHandling, page.Parent as Page);

DecoreView?.RemoveView(renderer.PlatformView as Android.Views.View);
renderer.DisconnectHandler(); //?? no clue if works
Expand All @@ -65,7 +71,7 @@ public Task RemoveAsync(PopupPage page)

//! important keeps reference to pages that accessibility has applied to. This is so accessibility can be removed properly when popup is removed. #https://github.com/LuckyDucko/Mopups/issues/93
readonly List<Android.Views.View?> views = new();
void HandleAccessibility(bool showPopup, bool disableAccessibilityHandling)
void HandleAccessibility(bool showPopup, bool disableAccessibilityHandling, Page? mainPage = null)
{
if (disableAccessibilityHandling)
{
Expand All @@ -74,7 +80,7 @@ void HandleAccessibility(bool showPopup, bool disableAccessibilityHandling)

if (showPopup)
{
Page? mainPage = Application.Current?.MainPage;
mainPage ??= Application.Current?.MainPage;

if (mainPage is null)
{
Expand Down
6 changes: 5 additions & 1 deletion Mopups/Mopups.Maui/Platforms/iOS/Handler/PopupPageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ public class PopupPageHandler : PageHandler
{
public PopupPageHandler()
{
this.SetMauiContext(MauiUIApplicationDelegate.Current.Application.Windows[0].Handler.MauiContext); //Still a hack?
SetMauiContext(MauiUIApplicationDelegate.Current.Application.Windows[0].Handler.MauiContext); //Still a hack?
}

public PopupPageHandler(IMauiContext context)
{
SetMauiContext(context); //Still a hack?
}
protected override Microsoft.Maui.Platform.ContentView CreatePlatformView()
{
return base.CreatePlatformView();
Expand Down
13 changes: 13 additions & 0 deletions Mopups/Mopups.Maui/Platforms/iOS/PopupWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace Mopups.Platforms.iOS
{
internal class PopupWindow : UIWindow
{

private bool _stop = false;
public PopupWindow(IntPtr handle) : base(handle)
{
}
Expand All @@ -24,6 +26,12 @@ public PopupWindow(UIWindowScene uiWindowScene) : base(uiWindowScene)

public override UIView HitTest(CGPoint point, UIEvent? uievent)
{

if (_stop)
{
return base.HitTest(point, uievent);
}

var platformHandler = (PopupPageRenderer?)RootViewController;
var renderer = platformHandler?.Handler;
var hitTestResult = base.HitTest(point, uievent);
Expand All @@ -36,6 +44,11 @@ public override UIView HitTest(CGPoint point, UIEvent? uievent)

if ((formsElement.BackgroundInputTransparent || formsElement.CloseWhenBackgroundIsClicked ) && renderer?.PlatformView == hitTestResult)
{
if (formsElement.CloseWhenBackgroundIsClicked)
{
_stop = true;
}

formsElement.SendBackgroundClick();
if (formsElement.BackgroundInputTransparent)
{
Expand Down
6 changes: 2 additions & 4 deletions Mopups/Mopups.Maui/Platforms/iOS/iOSMopups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,21 @@ internal class iOSMopups : IPopupPlatform
// It's necessary because GC in Xamarin.iOS 13 removes all UIWindow if there are not any references to them. See #459
private readonly List<UIWindow> _windows = new List<UIWindow>();

private static bool IsiOS9OrNewer => UIDevice.CurrentDevice.CheckSystemVersion(9, 0);

private static bool IsiOS13OrNewer => UIDevice.CurrentDevice.CheckSystemVersion(13, 0);

public bool IsSystemAnimationEnabled => true;

public Task AddAsync(PopupPage page)
{
page.Parent = Application.Current.MainPage;
page.Parent ??= Application.Current?.MainPage;

page.DescendantRemoved += HandleChildRemoved;

var keyWindow = GetKeyWindow(UIApplication.SharedApplication);
if (keyWindow?.WindowLevel == UIWindowLevel.Normal)
keyWindow.WindowLevel = -1;

var handler = (PopupPageHandler)IPopupPlatform.GetOrCreateHandler<PopupPageHandler>(page);
var handler = (page.Handler ??= new PopupPageHandler(page.Parent.Handler.MauiContext)) as PopupPageHandler;

PopupWindow window;

Expand Down
3 changes: 1 addition & 2 deletions SampleMaui/Platforms/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true" android:theme="@style/AppTheme"></application>
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:supportsRtl="true" android:theme="@style/AppTheme"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
4 changes: 2 additions & 2 deletions SampleMaui/SampleMopups.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>

<TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks>net8.0-maccatalyst;net8.0-ios;net8.0-android</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>

<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net7.0-tizen</TargetFrameworks> -->
Expand Down
Loading