Merge pull request #18369 from unoplatform/dev/mazi/closing-singlewindow

fix: Do not destroy the singleton Window for single-window targets
This commit is contained in:
Jérôme Laban 2024-10-03 22:57:14 -04:00 коммит произвёл GitHub
Родитель 4a4d515f80 ff0b18352a
Коммит 9817a077de
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 77 добавлений и 8 удалений

Просмотреть файл

@ -0,0 +1,16 @@
<Page
x:Class="UITests.Microsoft_UI_Windowing.SingleWindowClose"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:UITests.Microsoft_UI_Windowing"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Microsoft.UI.Xaml.Controls"
x:DefaultBindMode="TwoWay"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">
<StackPanel Padding="8" Spacing="8">
<TextBlock Text="This sample is only relevant to Android and iOS." x:Name="LogTextBlock" />
</StackPanel>
</Page>

Просмотреть файл

@ -0,0 +1,35 @@
using System;
using System.Threading.Tasks;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using SamplesApp;
using Uno.Disposables;
using Uno.UI.Common;
using Uno.UI.Samples.Controls;
using Uno.UI.Samples.UITests.Helpers;
using Windows.Graphics;
#if !WINDOWS_UWP && !WINAPPSDK
using Uno.UI.Xaml;
using Uno.UI.Xaml.Controls;
using WinUICoreServices = Uno.UI.Xaml.Core.CoreServices;
#endif
namespace UITests.Microsoft_UI_Windowing;
[Sample(
"Windowing",
IsManualTest = true,
Description =
"- On Android and iOS, try to back out of this app to the main screen and reopen the app via its icon. " +
"You should see the Samples app UI load normally - not a blank screen and the app should also not crash. \r\n" +
"- On Android and iOS, try to back out of this app and then activate it by opening an URI like uno-samples-test:something. " +
"You should see the Samples app UI load normally - not a blank screen and the app should also not crash. ")]
public sealed partial class SingleWindowClose : Page
{
public SingleWindowClose()
{
this.InitializeComponent();
}
}

Просмотреть файл

@ -42,6 +42,10 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="$(MSBuildThisFileDirectory)Microsoft_UI_Windowing\SingleWindowClose.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Microsoft_UI_Windowing\OverlappedPresenterTests.xaml"> <Page Include="$(MSBuildThisFileDirectory)Microsoft_UI_Windowing\OverlappedPresenterTests.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
@ -5496,6 +5500,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Windowing\AppWindowClosing.xaml.cs"> <Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Windowing\AppWindowClosing.xaml.cs">
<DependentUpon>AppWindowClosing.xaml</DependentUpon> <DependentUpon>AppWindowClosing.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Windowing\SingleWindowClose.xaml.cs">
<DependentUpon>SingleWindowClose.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Windowing\OverlappedPresenterTests.xaml.cs"> <Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Windowing\OverlappedPresenterTests.xaml.cs">
<DependentUpon>OverlappedPresenterTests.xaml</DependentUpon> <DependentUpon>OverlappedPresenterTests.xaml</DependentUpon>
</Compile> </Compile>

Просмотреть файл

@ -80,7 +80,7 @@ internal abstract class BaseWindowImplementation : IWindowImplementation
public virtual void Activate() public virtual void Activate()
{ {
if (_isClosed) if (NativeWindowFactory.SupportsMultipleWindows && _isClosed)
{ {
throw new InvalidOperationException("Cannot reactivate a closed window."); throw new InvalidOperationException("Cannot reactivate a closed window.");
} }
@ -318,10 +318,18 @@ internal abstract class BaseWindowImplementation : IWindowImplementation
// Window.PrepareToClose(); // Window.PrepareToClose();
// set these to null before marking window as closed as they fail if called after m_bIsClosed is set if (NativeWindowFactory.SupportsMultipleWindows)
// because they check if window is closed already {
Window.SetTitleBar(null); // set these to null before marking window as closed as they fail if called after m_bIsClosed is set
Window.Content = null; // because they check if window is closed already
Window.SetTitleBar(null);
Window.Content = null;
}
else
{
// Just reset the window to not shown state so it can be reactivated
_wasShown = false;
}
// _windowChrome.SetDesktopWindow(null); // _windowChrome.SetDesktopWindow(null);
@ -336,8 +344,11 @@ internal abstract class BaseWindowImplementation : IWindowImplementation
RaiseWindowVisibilityChangedEvent(false); RaiseWindowVisibilityChangedEvent(false);
} }
// Close native window, cleanup, and unregister from hwnd mapping from DXamlCore if (NativeWindowFactory.SupportsMultipleWindows)
Shutdown(); {
// Close native window, cleanup, and unregister from hwnd mapping from DXamlCore
Shutdown();
}
return true; return true;
} }