Skip to content
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
7 changes: 2 additions & 5 deletions samples/Sample.Avalonia.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia;
using Avalonia.iOS;
using Avalonia.Media;
using Avalonia.ReactiveUI;
using Foundation;
using UIKit;
using ReactiveUI.Avalonia;

namespace Sample.Avalonia.iOS
{
Expand Down
73 changes: 36 additions & 37 deletions samples/Sample.Avalonia/Views/EView.axaml
Original file line number Diff line number Diff line change
@@ -1,51 +1,50 @@
<UserControl
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d"
x:Class="Sample.Avalonia.Views.EView"
x:DataType="vm:EViewModel"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:an="https://github.com/NeverMorewd/AsyncNavigation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:Sample.Common"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d"
x:DataType="vm:EViewModel">
<DockPanel LastChildFill="True">
<Border
HorizontalAlignment="Stretch"
xmlns:vm="using:Sample.Common"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DockPanel LastChildFill="True">
<Border
Background="DarkOrange"
BorderBrush="LemonChiffon"
BorderThickness="1"
DockPanel.Dock="Top">
<StackPanel>
<TextBlock Text="{Binding Name}" />
<TextBlock>
InstanceNumber:
<Run
DockPanel.Dock="Top"
HorizontalAlignment="Stretch">
<StackPanel>
<TextBlock Text="{Binding Name}" />
<TextBlock>
InstanceNumber:<Run
FontSize="15"
FontWeight="Bold"
Foreground="Blue"
Text="{Binding InstanceNumber}" />
</TextBlock>
<Button Classes="UnloadView"/>
<Button Classes="CloseDialog"/>
<ItemsControl ItemsSource="{Binding HeavyItems}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<DockPanel LastChildFill="True">
<ComboBox Width="50" />
<Expander Width="50" />
<DatePicker Width="50" />
</DockPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
</Border>
</DockPanel>
</TextBlock>
<Button Classes="UnloadView" />
<Button Classes="CloseDialog" />
<ItemsControl ItemsSource="{Binding HeavyItems}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<DockPanel LastChildFill="True">
<ComboBox Width="50" />
<Expander Width="50" />
<DatePicker Width="50" />
</DockPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
</Border>
</DockPanel>
</UserControl>
16 changes: 11 additions & 5 deletions samples/Sample.Common/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public partial class MainWindowViewModel : ViewModelBase
private readonly IRegionManager _regionManager;
private readonly IDialogService _dialogService;
private readonly IRegistrationTracker _registrationTracker;
private readonly IRouter _router;
private readonly IRouter? _router;

public MainWindowViewModel(IRegionManager regionManager,
IDialogService dialogService,
IRegistrationTracker registrationTracker,
IRouter router)
IRouter? router = null)
{
_router = router;
_regionManager = regionManager;
Expand All @@ -35,16 +35,22 @@ public MainWindowViewModel(IRegionManager regionManager,
});

Views = _registrationTracker.TryGetViews(out var views) ? [.. views] : [];
foreach (var mappedNavigation in _router.Routes)

if (_router is not null)
{
Views.Add(mappedNavigation.Path);
foreach (var mappedNavigation in _router.Routes)
{
Views.Add(mappedNavigation.Path);
}
Views.Add("/Tab/Tab_A");
}
Views.Add("/Tab/Tab_A");

this.WhenAnyValue(vm => vm.SelectedView)
.WhereNotNull()
.Subscribe(target =>
{
/// If the target starts with "/", we consider it a path navigation.
/// This logic can be customized based on your routing conventions.
if (target.StartsWith("/",StringComparison.OrdinalIgnoreCase))
{
AsyncPathNavigateAndForget(target);
Expand Down
57 changes: 35 additions & 22 deletions samples/Sample.FrontDialog/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Avalonia.Markup.Xaml;
using Microsoft.Extensions.DependencyInjection;
using Sample.Common;
using System;
using System.Diagnostics;

namespace Sample.FrontDialog;

Expand All @@ -15,34 +17,45 @@ public override void Initialize()
AvaloniaXamlLoader.Load(this);
}

public async override void OnFrameworkInitializationCompleted()
public override async void OnFrameworkInitializationCompleted()
{
var services = new ServiceCollection();
services.AddNavigationSupport()
.AddSingleton<MainWindowViewModel>()
try
{
var services = new ServiceCollection();
#pragma warning disable IL2026
services
.AddNavigationSupport()
.AddSingletonWitAllMembers<MainWindowViewModel>()
#pragma warning restore IL2026
.RegisterDialogWindow<DialogWindow, FrontDialogViewModel>("DialogWindow");
var sp = services.BuildServiceProvider();

var sp = services.BuildServiceProvider();

var dialogService = sp.GetRequiredService<IDialogService>();
await dialogService.FrontShowWindowAsync("DialogWindow", result =>
{
if (result.Result == AsyncNavigation.Core.DialogButtonResult.Done)
var dialogService = sp.GetRequiredService<IDialogService>();
await dialogService.FrontShowWindowAsync("DialogWindow", result =>
{
var win = new MainWindow
if (result.Result == AsyncNavigation.Core.DialogButtonResult.Done)
{
DataContext = sp.GetRequiredService<MainWindowViewModel>()
};
return win;
}
else
{
if (Current?.ApplicationLifetime is IControlledApplicationLifetime applicationLifetime)
var win = new MainWindow
{
DataContext = sp.GetRequiredService<MainWindowViewModel>()
};
return win;
}
else
{
applicationLifetime.Shutdown();
if (Current?.ApplicationLifetime is IControlledApplicationLifetime applicationLifetime)
{
applicationLifetime.Shutdown();
}
return null;
}
return null;
}
});
base.OnFrameworkInitializationCompleted();
});
base.OnFrameworkInitializationCompleted();
}
catch (Exception e)
{
Debug.WriteLine(e);
}
}
}
23 changes: 14 additions & 9 deletions samples/Sample.FrontDialog/MainWindow.axaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Sample.FrontDialog.MainWindow"
WindowStartupLocation="CenterScreen"
Title="Sample.FrontDialog">
I am the MainWindow
<Window
x:Class="Sample.FrontDialog.MainWindow"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="Sample.FrontDialog"
d:DesignHeight="450"
d:DesignWidth="800"
WindowStartupLocation="CenterScreen"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
mc:Ignorable="d">
I am the MainWindow
</Window>
2 changes: 1 addition & 1 deletion samples/Sample.FrontDialog/Sample.FrontDialog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.7" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
<PackageReference Include="ReactiveUI.Avalonia" Version="11.3.8" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions samples/Sample.InfinityNavigation/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using AsyncNavigation.Abstractions;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Microsoft.Extensions.DependencyInjection;
using ReactiveUI;
using Sample.Common;
using Sample.InfinityNavigation.Views;

Expand All @@ -20,8 +18,10 @@ public override void Initialize()
public override void OnFrameworkInitializationCompleted()
{
var services = new ServiceCollection();
#pragma warning disable IL2026
services.AddNavigationSupport()
.RegisterView<InfinityView, InfinityViewModel>(nameof(InfinityView));
#pragma warning restore IL2026

var sp = services.BuildServiceProvider();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<PublishAot>true</PublishAot>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<IsTrimmable>true</IsTrimmable>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>

<ItemGroup>
<AvaloniaResource Include="Assets\**" />
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/AsyncNavigation/DependencyInjectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ private static IServiceCollection RegisterViewModelAndView<TView, TViewModel, TA
return services;
}

private static IServiceCollection RegisterDialogWindowInternal<TWindow, TViewModel>(
private static IServiceCollection RegisterDialogWindowInternal<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]TWindow,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TViewModel>(
this IServiceCollection services,
string windowName,
Func<IServiceProvider, TViewModel>? viewModelBuilder = null)
Expand Down
10 changes: 10 additions & 0 deletions src/AsyncNavigation/NavigationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,14 @@ public override bool Equals(object? obj)
}
return base.Equals(obj);
}
public override int GetHashCode()
{
return HashCode.Combine(
MaxCachedViews,
MaxHistoryItems,
MaxReplayItems,
LoadingIndicatorDelay,
NavigationJobStrategy,
NavigationJobScope);
}
}
2 changes: 1 addition & 1 deletion tests/AsyncNavigation.Tests/Mocks/Dummy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
public class DummyNavigationViewModel : INavigationAware
{
public event AsyncEventHandler<AsyncEventArgs> AsyncRequestUnloadEvent;
public event AsyncEventHandler<AsyncEventArgs>? AsyncRequestUnloadEvent;

Check warning on line 12 in tests/AsyncNavigation.Tests/Mocks/Dummy.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-22.04)

The event 'DummyNavigationViewModel.AsyncRequestUnloadEvent' is never used

Check warning on line 12 in tests/AsyncNavigation.Tests/Mocks/Dummy.cs

View workflow job for this annotation

GitHub Actions / test (macos-13)

The event 'DummyNavigationViewModel.AsyncRequestUnloadEvent' is never used

Check warning on line 12 in tests/AsyncNavigation.Tests/Mocks/Dummy.cs

View workflow job for this annotation

GitHub Actions / test (windows-2022)

The event 'DummyNavigationViewModel.AsyncRequestUnloadEvent' is never used

public Task InitializeAsync(NavigationContext context)
{
Expand Down Expand Up @@ -44,7 +44,7 @@
{
public string Title => throw new NotImplementedException();

public event AsyncEventHandler<DialogCloseEventArgs>? RequestCloseAsync;

Check warning on line 47 in tests/AsyncNavigation.Tests/Mocks/Dummy.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-22.04)

The event 'DummyDialogViewModel.RequestCloseAsync' is never used

Check warning on line 47 in tests/AsyncNavigation.Tests/Mocks/Dummy.cs

View workflow job for this annotation

GitHub Actions / test (macos-13)

The event 'DummyDialogViewModel.RequestCloseAsync' is never used

Check warning on line 47 in tests/AsyncNavigation.Tests/Mocks/Dummy.cs

View workflow job for this annotation

GitHub Actions / test (windows-2022)

The event 'DummyDialogViewModel.RequestCloseAsync' is never used

public Task OnDialogClosedAsync(IDialogResult? dialogResult, CancellationToken cancellationToken)
{
Expand All @@ -69,8 +69,8 @@
{
public string Title => throw new NotImplementedException();

public event AsyncEventHandler<AsyncEventArgs>? AsyncRequestUnloadEvent;

Check warning on line 72 in tests/AsyncNavigation.Tests/Mocks/Dummy.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-22.04)

The event 'DummyComboViewModel.AsyncRequestUnloadEvent' is never used

Check warning on line 72 in tests/AsyncNavigation.Tests/Mocks/Dummy.cs

View workflow job for this annotation

GitHub Actions / test (macos-13)

The event 'DummyComboViewModel.AsyncRequestUnloadEvent' is never used

Check warning on line 72 in tests/AsyncNavigation.Tests/Mocks/Dummy.cs

View workflow job for this annotation

GitHub Actions / test (windows-2022)

The event 'DummyComboViewModel.AsyncRequestUnloadEvent' is never used
public event AsyncEventHandler<DialogCloseEventArgs>? RequestCloseAsync;

Check warning on line 73 in tests/AsyncNavigation.Tests/Mocks/Dummy.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-22.04)

The event 'DummyComboViewModel.RequestCloseAsync' is never used

Check warning on line 73 in tests/AsyncNavigation.Tests/Mocks/Dummy.cs

View workflow job for this annotation

GitHub Actions / test (macos-13)

The event 'DummyComboViewModel.RequestCloseAsync' is never used

Check warning on line 73 in tests/AsyncNavigation.Tests/Mocks/Dummy.cs

View workflow job for this annotation

GitHub Actions / test (windows-2022)

The event 'DummyComboViewModel.RequestCloseAsync' is never used

public Task InitializeAsync(NavigationContext context)
{
Expand Down
Loading