Skip to content

Commit

Permalink
fix: Add Sextant.Avalonia to sln (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
worldbeater authored Feb 28, 2021
1 parent e2f766f commit 7680dbc
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 95 deletions.
9 changes: 5 additions & 4 deletions src/Sextant.Avalonia/DependencyResolverMixins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// See the LICENSE file in the project root for full license information.

using System;

using Splat;

namespace Sextant.Avalonia
Expand All @@ -19,7 +20,7 @@ public static class DependencyResolverMixins
/// <param name="dependencyResolver">The dependency resolver.</param>
/// <param name="navigationViewFactory">The navigation view factory.</param>
/// <typeparam name="TView">The view type.</typeparam>
/// <returns>The dependency resolver.</returns>
/// <returns>The dependency resolver for builder use.</returns>
public static IMutableDependencyResolver RegisterNavigationView<TView>(
this IMutableDependencyResolver dependencyResolver,
Func<TView> navigationViewFactory)
Expand All @@ -35,9 +36,9 @@ public static IMutableDependencyResolver RegisterNavigationView<TView>(
/// <summary>
/// Resolves navigation view from a dependency resolver.
/// </summary>
/// <param name="dependencyResolver"></param>
/// <param name="contract"></param>
/// <returns>The dependency resolver.</returns>
/// <param name="dependencyResolver">The dependency resolver.</param>
/// <param name="contract">Optional contract.</param>
/// <returns>The dependency resolver for builder use.</returns>
public static IView GetNavigationView(
this IReadonlyDependencyResolver dependencyResolver,
string? contract = null) =>
Expand Down
108 changes: 108 additions & 0 deletions src/Sextant.Avalonia/Navigation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright (c) 2021 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive.Linq;

using Avalonia.Animation;
using Avalonia.ReactiveUI;

using DynamicData.Aggregation;
using DynamicData.Binding;

using ReactiveUI;

namespace Sextant.Avalonia
{
/// <summary>
/// A view used within navigation in Sextant with Avalonia.
/// </summary>
public sealed partial class NavigationView
{
/// <summary>
/// This class represents a single navigation layer.
/// </summary>
private class Navigation
{
private readonly ObservableCollection<IViewFor> _navigationStack = new ObservableCollection<IViewFor>();
private readonly IPageTransition _transition;

/// <summary>
/// Initializes a new instance of the <see cref="Navigation"/> class.
/// </summary>
public Navigation()
{
var navigationStackObservable = _navigationStack
.ToObservableChangeSet()
.Publish()
.RefCount();

navigationStackObservable
.Select(_ => _navigationStack.LastOrDefault())
.Subscribe(page => Control.Content = page);

CountChanged = navigationStackObservable.Count().AsObservable();
_transition = Control.PageTransition;
}

/// <summary>
/// Gets a value indicating whether the control is visible.
/// </summary>
public bool IsVisible => _navigationStack.Count > 1;

/// <summary>
/// Gets a the page count.
/// </summary>
public IObservable<int> CountChanged { get; }

/// <summary>
/// Gets the control responsible for rendering the current view.
/// </summary>
public TransitioningContentControl Control { get; } = new TransitioningContentControl();

/// <summary>
/// Toggles the animations.
/// </summary>
/// <param name="enable">Returns true if we are enabling the animations.</param>
public void ToggleAnimations(bool enable) => Control.PageTransition = enable ? _transition : null;

/// <summary>
/// Adds a <see cref="IViewFor"/> to the navigation stack.
/// </summary>
/// <param name="view">The view to add to the navigation stack.</param>
/// <param name="resetStack">Defines if we should reset the navigation stack.</param>
public void Push(IViewFor view, bool resetStack = false)
{
if (resetStack)
{
_navigationStack.Clear();
}

_navigationStack.Add(view);
}

/// <summary>
/// Removes the last <see cref="IViewFor"/> from the navigation stack.
/// </summary>
public void Pop()
{
var indexToRemove = _navigationStack.Count - 1;
_navigationStack.RemoveAt(indexToRemove);
}

/// <summary>
/// Removes all pages except the first one <see cref="IViewFor"/> from the navigation stack.
/// </summary>
public void PopToRoot()
{
var view = _navigationStack[0];
_navigationStack.Clear();
_navigationStack.Add(view);
}
}
}
}
94 changes: 4 additions & 90 deletions src/Sextant.Avalonia/NavigationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,24 @@
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Linq;

using Avalonia;
using Avalonia.Animation;
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.ReactiveUI;
using Avalonia.Styling;
using DynamicData.Aggregation;
using DynamicData.Binding;

using ReactiveUI;
using Sextant;

namespace Sextant.Avalonia
{
/// <summary>
/// The <see cref="IView"/> implementation for Avalonia.
/// </summary>
public sealed class NavigationView : ContentControl, IStyleable, IView
public sealed partial class NavigationView : ContentControl, IStyleable, IView
{
private readonly Navigation _modalNavigation = new Navigation();
private readonly Navigation _pageNavigation = new Navigation();
Expand Down Expand Up @@ -56,7 +52,7 @@ public NavigationView()
{
_modalNavigation.Control
},
[!Panel.BackgroundProperty] =
[!Panel.BackgroundProperty] =
_modalNavigation
.CountChanged
.Select(count => count > 0 ? new SolidColorBrush(Colors.Transparent) : null)
Expand Down Expand Up @@ -144,87 +140,5 @@ private IViewFor LocateView(IViewModel viewModel, string? contract)
view.ViewModel = viewModel;
return view;
}

/// <summary>
/// This class represents a single navigation layer.
/// </summary>
private class Navigation
{
private readonly ObservableCollection<IViewFor> _navigationStack = new ObservableCollection<IViewFor>();
private readonly IPageTransition _transition;

/// <summary>
/// Initializes a new instance of the <see cref="Navigation"/> helper.
/// </summary>
public Navigation()
{
var navigationStackObservable = _navigationStack
.ToObservableChangeSet()
.Publish()
.RefCount();

navigationStackObservable
.Select(_ => _navigationStack.LastOrDefault())
.Subscribe(page => Control.Content = page);

CountChanged = navigationStackObservable.Count().AsObservable();
_transition = Control.PageTransition;
}

/// <summary>
/// Toggles the animations.
/// </summary>
/// <param name="enable">Returns true if we are enabling the animations.</param>
public void ToggleAnimations(bool enable) => Control.PageTransition = enable ? _transition : null;

/// <summary>
/// Gets a bool indicating whether the control is visible.
/// </summary>
public bool IsVisible => _navigationStack.Count > 1;

/// <summary>
/// Publishes new values when page count changes.
/// </summary>
public IObservable<int> CountChanged { get; }

/// <summary>
/// The control responsible for rendering the current view.
/// </summary>
public TransitioningContentControl Control { get; } = new TransitioningContentControl();

/// <summary>
/// Adds a <see cref="IViewFor"/> to the navigation stack.
/// </summary>
/// <param name="view">The view to add to the navigation stack.</param>
/// <param name="resetStack">Defines if we should reset the navigation stack.</param>
public void Push(IViewFor view, bool resetStack = false)
{
if (resetStack)
{
_navigationStack.Clear();
}

_navigationStack.Add(view);
}

/// <summary>
/// Removes the last <see cref="IViewFor"/> from the navigation stack.
/// </summary>
public void Pop()
{
var indexToRemove = _navigationStack.Count - 1;
_navigationStack.RemoveAt(indexToRemove);
}

/// <summary>
/// Removes all pages except the first one <see cref="IViewFor"/> from the navigation stack.
/// </summary>
public void PopToRoot()
{
var view = _navigationStack[0];
_navigationStack.Clear();
_navigationStack.Add(view);
}
}
}
}
6 changes: 6 additions & 0 deletions src/Sextant.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sextant.Plugins.Popup", "Se
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sextant.Plugins.Popup.Tests", "Sextant.Plugins.Popup.Tests\Sextant.Plugins.Popup.Tests.csproj", "{BD186721-EE51-40B2-A546-91EDDE122998}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sextant.Avalonia", "Sextant.Avalonia\Sextant.Avalonia.csproj", "{A91CDEEB-C4D5-402B-9B42-D91E0151F30E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -68,6 +70,10 @@ Global
{BD186721-EE51-40B2-A546-91EDDE122998}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD186721-EE51-40B2-A546-91EDDE122998}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD186721-EE51-40B2-A546-91EDDE122998}.Release|Any CPU.Build.0 = Release|Any CPU
{A91CDEEB-C4D5-402B-9B42-D91E0151F30E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A91CDEEB-C4D5-402B-9B42-D91E0151F30E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A91CDEEB-C4D5-402B-9B42-D91E0151F30E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A91CDEEB-C4D5-402B-9B42-D91E0151F30E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.10",
"version": "2.11",
"publicReleaseRefSpec": [
"^refs/heads/main", // we release out of master
"^refs/heads/rel/\\d+\\.\\d+\\.\\d+" // we also release branches starting with rel/N.N.N
Expand Down

0 comments on commit 7680dbc

Please sign in to comment.