Skip to content

Commit

Permalink
Merge pull request #973 from unoplatform/dev/nr/navbackissue
Browse files Browse the repository at this point in the history
fix: Preventing recreation of pages when navigating back
  • Loading branch information
nickrandolph authored Dec 7, 2022
2 parents fccfa38 + 64e7e70 commit 1e3c16e
Show file tree
Hide file tree
Showing 22 changed files with 230 additions and 38 deletions.
3 changes: 2 additions & 1 deletion samples/Playground/Playground.Shared/Views/VMPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
mc:Ignorable="d"
xmlns:ui="using:Uno.Toolkit.UI"
xmlns:uen="using:Uno.Extensions.Navigation.UI"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
NavigationCacheMode="Required">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand Down
6 changes: 3 additions & 3 deletions src/Uno.Extensions.Logging/HostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public static IHostBuilder UseLogging(
#pragma warning disable CA1416 // Validate platform compatibility: The net6.0 version is not used on older versions of OS
builder.AddProvider(new global::Uno.Extensions.Logging.OSLogLoggerProvider());
#pragma warning restore CA1416 // Validate platform compatibility
#else
#elif NET6_0_OR_GREATER // Console isn't supported on all Xamarin targets, so only adding for net6.0 and above
builder.AddConsole();
#endif
builder.AddDebug();
#elif __WASM__
builder.AddProvider(new global::Uno.Extensions.Logging.WebAssembly.WebAssemblyConsoleLoggerProvider());
#elif __WASM__
builder.AddProvider(new global::Uno.Extensions.Logging.WebAssembly.WebAssemblyConsoleLoggerProvider());
#endif
configure?.Invoke(context, builder);
})
Expand Down
11 changes: 0 additions & 11 deletions src/Uno.Extensions.Navigation.UI/Navigators/FrameNavigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,6 @@ private async void FrameGoBack(object? parameter, RouteInfo? previousMapping)
try
{
Control.Navigated -= Frame_Navigated;
if (parameter is not null)
{
if (Logger.IsEnabled(LogLevel.Debug)) Logger.LogDebugMessage($"Replacing last backstack item to inject parameter '{parameter.GetType().Name}'");
// If a parameter is being sent back, we need to replace
// the last frame on the backstack with one that has the correct
// parameter value. This value can be extracted via the OnNavigatedTo method
var entry = Control.BackStack.Last();
var newEntry = new PageStackEntry(entry.SourcePageType, parameter, entry.NavigationTransitionInfo);
Control.BackStack.Remove(entry);
Control.BackStack.Add(newEntry);
}
if (Logger.IsEnabled(LogLevel.Debug)) Logger.LogDebugMessage($"Invoking Frame.GoBack");
Control.GoBack();

Expand Down
4 changes: 2 additions & 2 deletions testing/TestHarness/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@
<PropertyGroup Condition="'$(_IsIOS)' == 'true'">
<MtouchExtraArgs>$(MtouchExtraArgs) --registrar=static</MtouchExtraArgs>
</PropertyGroup>

<Import Project="..\src\crosstargeting_override.props" Condition="exists('..\src\crosstargeting_override.props')" />
<Import Project="$(MSBuildThisFileDirectory)..\..\src\crosstargeting_override.props" Condition="exists('$(MSBuildThisFileDirectory)..\..\src\crosstargeting_override.props')" />
</Project>
1 change: 1 addition & 0 deletions testing/TestHarness/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<PackageVersion Include="SkiaSharp.HarfBuzz" Version="2.88.3" />
<PackageVersion Include="SkiaSharp.Skottie" Version="2.88.3" />
<PackageVersion Include="SkiaSharp.Views" Version="2.88.3" />
<PackageVersion Include="SkiaSharp.Views.Uno" Version="2.88.3" />
<PackageVersion Include="SkiaSharp.Views.Uno.WinUI" Version="2.88.3" />
<PackageVersion Include="SkiaSharp.Views.WPF" Version="2.88.3" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.2.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" />
<PackageReference Include="CommunityToolkit.Mvvm" />
<PackageReference Include="IdentityModel.OidcClient" />
<PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI" />
<PackageReference Include="Microsoft.Identity.Client" />
Expand All @@ -81,12 +81,12 @@
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
<PackageReference Include="Refit" />
<PackageReference Include="Refit.HttpClientFactory"/>
<PackageReference Include="Refit.HttpClientFactory" />
<PackageReference Include="System.Text.Json" />
<PackageReference Include="Uno.Material" />
<PackageReference Include="Uno.Toolkit.UI.Material" />
<PackageReference Include="Uno.Toolkit.UI"/>
<PackageReference Include="Uno.UI.MSAL" />
<PackageReference Include="Uno.Toolkit.UI.Material" />
<PackageReference Include="Uno.Toolkit.UI" />
<PackageReference Include="Uno.UI.MSAL" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
Expand Down Expand Up @@ -156,6 +156,7 @@
<ProjectReference Include="..\TestHarness.Core\TestHarness.Core.csproj" />
</ItemGroup>
<Import Project="..\TestHarness.Shared\TestHarness.Shared.projitems" Label="Shared" />
<Import Project="..\..\..\src\Uno.Extensions.Core.Generators\buildTransitive\Uno.Extensions.Core.props" />
<Import Project="..\..\..\src\Uno.Extensions.Reactive.Generator\buildTransitive\Uno.Extensions.Reactive.props" />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Target Name="Issue3897Workaround" Condition=" '$(ManagedDesignTimeBuild)' == 'True' " AfterTargets="_RemoveLegacyDesigner">
Expand All @@ -164,4 +165,4 @@
<Compile Remove="$(_AndroidResourceDesignerFile)" />
</ItemGroup>
</Target>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@
<ProjectReference Include="..\TestHarness.Core\TestHarness.Core.csproj" />
</ItemGroup>
<Import Project="..\TestHarness.Shared\TestHarness.Shared.projitems" Label="Shared" />
<Import Project="..\..\..\src\Uno.Extensions.Core.Generators\buildTransitive\Uno.Extensions.Core.props" />
<Import Project="..\..\..\src\Uno.Extensions.Reactive.Generator\buildTransitive\Uno.Extensions.Reactive.props" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@
<ProjectReference Include="..\TestHarness.Core\TestHarness.Core.csproj" />
</ItemGroup>
<Import Project="..\TestHarness.Shared\TestHarness.Shared.projitems" Label="Shared" />
<Import Project="..\..\..\src\Uno.Extensions.Core.Generators\buildTransitive\Uno.Extensions.Core.props" />
<Import Project="..\..\..\src\Uno.Extensions.Reactive.Generator\buildTransitive\Uno.Extensions.Reactive.props" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@
<ProjectReference Include="..\TestHarness.Core\TestHarness.Core.csproj" />
</ItemGroup>
<Import Project="..\TestHarness.Shared\TestHarness.Shared.projitems" Label="Shared" />
<Import Project="..\..\..\src\Uno.Extensions.Core.Generators\buildTransitive\Uno.Extensions.Core.props" />
<Import Project="..\..\..\src\Uno.Extensions.Reactive.Generator\buildTransitive\Uno.Extensions.Reactive.props" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@
<ProjectReference Include="..\TestHarness.Core\TestHarness.Core.csproj" />
</ItemGroup>
<Import Project="..\TestHarness.Shared\TestHarness.Shared.projitems" Label="Shared" />
<Import Project="..\..\..\src\Uno.Extensions.Core.Generators\buildTransitive\Uno.Extensions.Core.props" />
<Import Project="..\..\..\src\Uno.Extensions.Reactive.Generator\buildTransitive\Uno.Extensions.Reactive.props" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
<PackageReference Include="Refit" />
<PackageReference Include="Refit.HttpClientFactory" />
<PackageReference Include="Refit.HttpClientFactory" />
<PackageReference Include="System.Text.Json" />
<PackageReference Include="Uno.Material" />
<PackageReference Include="Uno.Toolkit.UI.Material" />
Expand Down Expand Up @@ -198,6 +198,7 @@
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<Import Project="..\..\..\src\Uno.Extensions.Core.Generators\buildTransitive\Uno.Extensions.Core.props" />
<Import Project="..\..\..\src\Uno.Extensions.Reactive.Generator\buildTransitive\Uno.Extensions.Reactive.props" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net5.0</TargetFramework>
<NoWarn>$(NoWarn);NU1701</NoWarn>
<AssemblyName>TestHarnessApp</AssemblyName>
<ImplicitUsings>disable</ImplicitUsings>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<MonoRuntimeDebuggerEnabled>true</MonoRuntimeDebuggerEnabled>
Expand Down Expand Up @@ -91,5 +92,6 @@
<ProjectReference Include="..\TestHarness.Core\TestHarness.Core.csproj" />
</ItemGroup>
<Import Project="..\TestHarness.Shared\TestHarness.Shared.projitems" Label="Shared" />
<Import Project="..\..\..\src\Uno.Extensions.Reactive.Generator\buildTransitive\Uno.Extensions.Reactive.props" />
<Import Project="..\..\..\src\Uno.Extensions.Core.Generators\buildTransitive\Uno.Extensions.Core.props" />
<Import Project="..\..\..\src\Uno.Extensions.Reactive.Generator\buildTransitive\Uno.Extensions.Reactive.props" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,18 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" />
<PackageReference Include="IdentityModel.OidcClient" />
<PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI" />
<PackageReference Include="Microsoft.Identity.Client" />
<PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI" />
<PackageReference Include="Microsoft.Identity.Client" />
<PackageReference Include="Uno.UI" />
<PackageReference Include="Uno.UI.RemoteControl" Condition="'$(Configuration)'=='Debug'" />
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
<PackageReference Include="Refit" />
<PackageReference Include="Refit.HttpClientFactory" />
<PackageReference Include="System.Text.Json" />
<PackageReference Include="Uno.Material" />
<PackageReference Include="Uno.Toolkit.UI.Material" />
<PackageReference Include="Uno.Toolkit.UI.Material" />
<PackageReference Include="Uno.Toolkit.UI" />
<PackageReference Include="Uno.UI.MSAL" />
<PackageReference Include="Uno.Extensions.Logging.OSLog" />
Expand Down Expand Up @@ -225,9 +225,10 @@
<ProjectReference Include="..\TestHarness.Core\TestHarness.Core.csproj" />
</ItemGroup>
<Import Project="..\TestHarness.Shared\TestHarness.Shared.projitems" Label="Shared" />
<Import Project="..\..\..\src\Uno.Extensions.Core.Generators\buildTransitive\Uno.Extensions.Core.props" />
<Import Project="..\..\..\src\Uno.Extensions.Reactive.Generator\buildTransitive\Uno.Extensions.Reactive.props" />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<PropertyGroup>
<MtouchExtraArgs>$(MtouchExtraArgs) --registrar=static</MtouchExtraArgs>
</PropertyGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" />
<PackageReference Include="IdentityModel.OidcClient" />
<PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI" />
<PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI" />
<PackageReference Include="Microsoft.Identity.Client" />
<PackageReference Include="Uno.UI" />
<PackageReference Include="Uno.UI.RemoteControl" Condition="'$(Configuration)'=='Debug'" />
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
<PackageReference Include="Refit" />
<PackageReference Include="Refit.HttpClientFactory" />
<PackageReference Include="Refit.HttpClientFactory" />
<PackageReference Include="System.Text.Json" />
<PackageReference Include="Uno.Material" />
<PackageReference Include="Uno.Toolkit.UI.Material" />
<PackageReference Include="Uno.Toolkit.UI" />
<PackageReference Include="Uno.UI.MSAL" />
<PackageReference Include="Uno.UI.MSAL" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Uno.Extensions.Authentication.Oidc\Uno.Extensions.Authentication.Oidc.UI.csproj" />
Expand Down Expand Up @@ -156,6 +156,7 @@
</BundleResource>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.CSharp.targets" />
<Import Project="..\..\..\src\Uno.Extensions.Core.Generators\buildTransitive\Uno.Extensions.Core.props" />
<Import Project="..\..\..\src\Uno.Extensions.Reactive.Generator\buildTransitive\Uno.Extensions.Reactive.props" />
<Target Name="VS16Mac_RemoveSystemMemory" BeforeTargets="ResolveAssemblyReferences">
<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@
<PropertyGroup Condition="'$(_IsIOS)' == 'true'">
<MtouchExtraArgs>$(MtouchExtraArgs) --registrar=static</MtouchExtraArgs>
</PropertyGroup>


<Import Project="..\..\..\src\Uno.Extensions.Core.Generators\buildTransitive\Uno.Extensions.Core.props" />
<Import Project="..\..\..\src\Uno.Extensions.Reactive.Generator\buildTransitive\Uno.Extensions.Reactive.props" />
<Import Project="..\TestHarness.Shared\TestHarness.Shared.projitems" Label="Shared" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace TestHarness.Ext.Navigation.Storage;
[ReactiveBindable(false)]
public partial class StorageOneViewModel : ObservableObject
{
private readonly Random _random = new Random();
private readonly INavigator _navigator;
private readonly IServiceProvider _services;
private readonly IEnumerable<INamedInstance<IKeyValueStorage>> _storage;
Expand Down Expand Up @@ -105,8 +106,8 @@ public async Task PerfTest()
var keyValues = new List<(string Key, string Value)>();
for (int i = 0; i < keyCount; i++)
{
var key = GenerateString(Random.Shared.Next(0, 100));
var value = GenerateString(Random.Shared.Next(0, 1000));
var key = GenerateString(_random.Next(0, 100));
var value = GenerateString(_random.Next(0, 1000));
keyValues.Add((key, value));
}

Expand All @@ -123,7 +124,7 @@ public async Task PerfTest()
var max = (5 * keyCount);
for (int i = 0; i < max; i++)
{
var key = Random.Shared.Next(0, keyCount);
var key = _random.Next(0, keyCount);
var val = await _selectedStorage.GetAsync<string>(keyValues[key].Key, CancellationToken.None);
if (i % 20 == 0)
{
Expand All @@ -149,7 +150,7 @@ public string GenerateString(int size)
char[] chars = new char[size];
for (int i = 0; i < size; i++)
{
chars[i] = Alphabet[Random.Shared.Next(Alphabet.Length)];
chars[i] = Alphabet[_random.Next(Alphabet.Length)];
}
return new string(chars);
}
Expand Down
2 changes: 2 additions & 0 deletions testing/TestHarness/TestHarness.Shared/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
global using Window = Microsoft.UI.Xaml.Window;
global using LaunchActivatedEventArgs = Microsoft.UI.Xaml.LaunchActivatedEventArgs;
global using Application = Microsoft.UI.Xaml.Application;
global using ToggleButton = Microsoft.UI.Xaml.Controls.Primitives.ToggleButton;
#else
global using Windows.System;
global using Windows.UI.Xaml;
Expand All @@ -57,4 +58,5 @@
global using Window = Windows.UI.Xaml.Window;
global using LaunchActivatedEventArgs = Windows.ApplicationModel.Activation.LaunchActivatedEventArgs;
global using Application = Windows.UI.Xaml.Application;
global using ToggleButton = Windows.UI.Xaml.Controls.Primitives.ToggleButton;
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<ProjectReference Include="..\..\..\src\Uno.Extensions.Http.Refit\Uno.Extensions.Http.Refit.csproj" />
<ProjectReference Include="..\TestHarness.Core\TestHarness.Core.csproj" />
</ItemGroup>
<Import Project="..\..\..\src\Uno.Extensions.Core.Generators\buildTransitive\Uno.Extensions.Core.props" />
<Import Project="..\..\..\src\Uno.Extensions.Reactive.Generator\buildTransitive\Uno.Extensions.Reactive.props" />
<Import Project="..\TestHarness.Shared\TestHarness.Shared.projitems" Label="Shared" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<ProjectReference Include="..\..\..\src\Uno.Extensions.Http.Refit\Uno.Extensions.Http.Refit.csproj" />
<ProjectReference Include="..\TestHarness.Core\TestHarness.Core.csproj" />
</ItemGroup>
<Import Project="..\..\..\src\Uno.Extensions.Core.Generators\buildTransitive\Uno.Extensions.Core.props" />
<Import Project="..\..\..\src\Uno.Extensions.Reactive.Generator\buildTransitive\Uno.Extensions.Reactive.props" />
<Import Project="..\TestHarness.Shared\TestHarness.Shared.projitems" Label="Shared" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<ProjectReference Include="..\..\..\src\Uno.Extensions.Storage\Uno.Extensions.Storage.csproj" />
<ProjectReference Include="..\TestHarness.Core\TestHarness.Core.csproj" />
</ItemGroup>
<Import Project="..\..\..\src\Uno.Extensions.Core.Generators\buildTransitive\Uno.Extensions.Core.props" />
<Import Project="..\..\..\src\Uno.Extensions.Reactive.Generator\buildTransitive\Uno.Extensions.Reactive.props" />
<Import Project="..\TestHarness.Shared\TestHarness.Shared.projitems" Label="Shared" Condition="Exists('..\TestHarness.Shared\TestHarness.Shared.projitems')" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" RuntimeFrameworkVersion="10.0.22000.25" />
<FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" TargetingPackVersion="10.0.22000.25" />
</ItemGroup>
<Import Project="..\..\..\src\Uno.Extensions.Core.Generators\buildTransitive\Uno.Extensions.Core.props" />
<Import Project="..\..\..\src\Uno.Extensions.Reactive.Generator\buildTransitive\Uno.Extensions.Reactive.props" />
<Import Project="..\TestHarness.Shared\TestHarness.Shared.projitems" Label="Shared" />
</Project>
Loading

0 comments on commit 1e3c16e

Please sign in to comment.