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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ We welcome feedback, suggestions, and contributions from anyone who is intereste
To use AvaloniaInside.Shell in your Avalonia project, you can install the package via NuGet using the following command in the Package Manager Console:

```bash
dotnet add package AvaloniaInside.Shell --version 1.3.2
dotnet add package AvaloniaInside.Shell --version 1.3.2.2
```

Alternatively, you can also install the package through Visual Studio's NuGet Package Manager.
Expand Down
2 changes: 1 addition & 1 deletion src/AvaloniaInside.Shell/AvaloniaInside.Shell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Version>1.3.2</Version>
<Version>1.3.2.2</Version>
<Title>Shell view for Avalonia</Title>
<Description>Shell reduces the complexity of mobile/desktop application development by providing the fundamental features that most applications require</Description>
<Copyright>AvaloniaInside</Copyright>
Expand Down
2 changes: 2 additions & 0 deletions src/AvaloniaInside.Shell/INavigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public interface INavigator
{
Uri CurrentUri { get; }

event EventHandler<NaviagateEventArgs>? OnNavigate;

INavigationRegistrar Registrar { get; }

NavigationChain? CurrentChain { get; }
Expand Down
16 changes: 16 additions & 0 deletions src/AvaloniaInside.Shell/Navigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public partial class Navigator : INavigator
private bool _navigating;
private ShellView? _shellView;

public event EventHandler<NaviagateEventArgs>? OnNavigate;

public ShellView ShellView => _shellView ?? throw new ArgumentNullException(nameof(ShellView));

public Uri CurrentUri => _stack.Current?.Uri ?? Registrar.RootUri;
Expand Down Expand Up @@ -154,6 +156,20 @@ await _updateStrategy.UpdateChangesAsync(
await fromPage.OnNavigateAsync(args, cancellationToken);
}

// Fire the OnNavigate event for external subscribers
OnNavigate?.Invoke(this, new NaviagateEventArgs
{
Sender = sender,
From = fromPage,
To = _stack.Current?.Instance,
FromUri = origin,
ToUri = newUri,
Argument = argument,
Navigate = finalNavigateType,
WithAnimation = withAnimation,
OverrideTransition = overrideTransition
});

_navigating = false;
}

Expand Down
13 changes: 11 additions & 2 deletions src/AvaloniaInside.Shell/StackContentView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,17 @@

// Bring to front if exists in collection
if (Children.Contains(control))
Children.Remove(control);
Children.Add(control);
{
var currentIndex = Children.IndexOf(control);
if (currentIndex != Children.Count - 1)
{
Children.Move(currentIndex, Children.Count - 1);
}
}
else
{
Children.Add(control);
}

await OnContentUpdateAsync(control, cancellationToken);
await UpdateCurrentViewAsync(current, control, navigateType, false, cancellationToken);
Expand Down Expand Up @@ -102,7 +111,7 @@
await UpdateCurrentViewAsync(view, to, navigateType, true, cancellationToken);
}

Children.Remove(view as Control);

Check warning on line 114 in src/AvaloniaInside.Shell/StackContentView.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'bool AvaloniaList<Control>.Remove(Control item)'.

Check warning on line 114 in src/AvaloniaInside.Shell/StackContentView.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'bool AvaloniaList<Control>.Remove(Control item)'.
await OnContentUpdateAsync(CurrentView, cancellationToken);

RaisePropertyChanged(CurrentViewProperty, current, CurrentView);
Expand Down
27 changes: 13 additions & 14 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Avalonia" Version="11.3.0"/>
<PackageVersion Include="Avalonia.Desktop" Version="11.3.0" />
<PackageVersion Include="Avalonia.Android" Version="11.3.0" />
<PackageVersion Include="Avalonia.iOS" Version="11.3.0" />
<PackageVersion Include="Avalonia.Browser" Version="11.3.0" />
<PackageVersion Include="Avalonia.Themes.Fluent" Version="11.3.0"/>
<PackageVersion Include="Avalonia.ReactiveUI" Version="11.3.0" />
<PackageVersion Include="Avalonia.Diagnostics" Version="11.3.0" />
<PackageVersion Include="Avalonia.Themes.Fluent" Version="11.3.0" />
<PackageVersion Include="Avalonia.Fonts.Inter" Version="11.3.0" />
<PackageVersion Include="Avalonia" Version="11.3.5"/>
<PackageVersion Include="Avalonia.Desktop" Version="11.3.5" />
<PackageVersion Include="Avalonia.Android" Version="11.3.5" />
<PackageVersion Include="Avalonia.iOS" Version="11.3.5" />
<PackageVersion Include="Avalonia.Browser" Version="11.3.5" />
<PackageVersion Include="Avalonia.Themes.Fluent" Version="11.3.5" />
<PackageVersion Include="Avalonia.ReactiveUI" Version="11.3.5" />
<PackageVersion Include="Avalonia.Diagnostics" Version="11.3.5" />
<PackageVersion Include="Avalonia.Fonts.Inter" Version="11.3.5" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Projektanker.Icons.Avalonia" Version="8.3.0" />
<PackageVersion Include="Projektanker.Icons.Avalonia.FontAwesome" Version="8.3.0" />
<PackageVersion Include="Xamarin.AndroidX.Core.SplashScreen" Version="1.0.1.15" />
<PackageVersion Include="ReactiveUI" Version="20.2.45" />
<PackageVersion Include="Projektanker.Icons.Avalonia" Version="9.6.2" />
<PackageVersion Include="Projektanker.Icons.Avalonia.FontAwesome" Version="9.6.2" />
<PackageVersion Include="Xamarin.AndroidX.Core.SplashScreen" Version="1.0.1.17" />
<PackageVersion Include="ReactiveUI" Version="21.0.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
Icon="/Assets/avalonia-logo.ico"
Title="ShellExample"
Width="450">
<views:MainView />
<views:MainView x:Name="MainView" />
</Window>
32 changes: 32 additions & 0 deletions src/Example/ShellExample/ShellExample/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using AvaloniaInside.Shell;

namespace ShellExample.Views;

Expand All @@ -11,4 +13,34 @@ public MainWindow()
InitializeComponent();
}

protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);

// Subscribe to navigation events to update window title
if (MainView.Navigator != null)
{
MainView.Navigator.OnNavigate += OnNavigate;
}
}

protected override void OnUnloaded(RoutedEventArgs e)
{
// Unsubscribe from navigation events
if (MainView.Navigator != null)
{
MainView.Navigator.OnNavigate -= OnNavigate;
}

base.OnUnloaded(e);
}

private void OnNavigate(object? sender, NaviagateEventArgs e)
{
if (e.To is AvaloniaObject targetView)
{
var header = NavigationBar.GetHeader(targetView) as string;
Title = header ?? "Shell Example";
}
}
}
Loading