Skip to content

Commit

Permalink
fix package reference, add INavigation interface
Browse files Browse the repository at this point in the history
  • Loading branch information
emmauss committed Sep 21, 2023
1 parent 4926d19 commit b9aaf07
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Avalonia.Labs.Controls/Avalonia.Labs.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.0-preview8" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.0-preview8" />
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions src/Avalonia.Labs.Controls/Page/INavigation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Avalonia.Labs.Controls
{
public interface INavigation
{
object? Pop();
void Push(object page);
}
}
7 changes: 6 additions & 1 deletion src/Avalonia.Labs.Controls/Page/NavigationPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Avalonia.Labs.Controls
[TemplatePart("PART_BackButton", typeof(Button))]
[TemplatePart("PART_ForwardButton", typeof(Button))]
[TemplatePart("PART_ContentPresenter", typeof(TransitioningContentControl))]
public class NavigationPage : MultiPage
public class NavigationPage : MultiPage, INavigation
{
private Button? _backButton;

Expand Down Expand Up @@ -213,6 +213,8 @@ public void Push(object page)

if (page is Page p && !p.IsSet(TitleViewProperty))
{
p.Navigation = this;

SetTitleView(p, new Label()
{
Content = p.Title,
Expand Down Expand Up @@ -242,6 +244,9 @@ public void Push(object page)

UpdateActivePage();

if (old is Page p)
p.Navigation = null;

return old;
}

Expand Down
14 changes: 12 additions & 2 deletions src/Avalonia.Labs.Controls/Page/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public abstract class Page : TemplatedControl, IStyleable
public static readonly RoutedEvent<RoutedEventArgs> PageNavigationSystemBackButtonPressedEvent =
RoutedEvent.Register<Page, RoutedEventArgs>(nameof(PageNavigationSystemBackButtonPressed), RoutingStrategies.Bubble | RoutingStrategies.Tunnel);

public static readonly DirectProperty<Page, INavigation?> NavigationProperty = AvaloniaProperty.RegisterDirect<Page, INavigation?>(nameof(Navigation), o => o.Navigation, (o, v) => o.Navigation = v);

private INavigation? _navigation;

static Page()
{
PageNavigationSystemBackButtonPressedEvent.AddClassHandler<Page>((page, args) =>
Expand Down Expand Up @@ -57,6 +61,12 @@ public Page? ActiveChildPage
set => SetValue(ActiveChildPageProperty, value);
}

public INavigation? Navigation
{
get => _navigation;
set => SetAndRaise(NavigationProperty, ref _navigation, value);
}

public event EventHandler<RoutedEventArgs> PageNavigationSystemBackButtonPressed
{
add => AddHandler(PageNavigationSystemBackButtonPressedEvent, value);
Expand All @@ -74,9 +84,9 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
}
}

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

UpdateContentSafeAreaPadding();
}
Expand Down

0 comments on commit b9aaf07

Please sign in to comment.