Skip to content

Commit

Permalink
Add tab page and custom nav bar (#40)
Browse files Browse the repository at this point in the history
* #27 supporting platform base theme and dynamic navbar

* #27 adding hosted tab page and support dynamic navbar

* #27 supporting dynamic navigation bar

* #27 fix navbar conflict and selected tab

* remove default nav to shell

* remove useless files

* add develop branch for build
  • Loading branch information
OmidID authored Sep 7, 2024
1 parent d0d88d9 commit 0ccd2f8
Show file tree
Hide file tree
Showing 70 changed files with 1,246 additions and 658 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET
name: CI

on:
push:
branches: [ "main" ]
branches: [ "main", "develop" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "develop" ]

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions src/AvaloniaInside.Shell/AvaloniaInside.Shell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</PropertyGroup>
<ItemGroup>
<AvaloniaResource Include="Assets\**" />
<AvaloniaResource Include="**\*.axaml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
Expand Down
49 changes: 24 additions & 25 deletions src/AvaloniaInside.Shell/BindingNavigate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@
using System.Threading.Tasks;
using System.Windows.Input;

namespace AvaloniaInside.Shell
namespace AvaloniaInside.Shell;

[TypeConverter(typeof(BindingNavigateConverter))]
public class BindingNavigate : AvaloniaObject, ICommand
{
[TypeConverter(typeof(BindingNavigateConverter))]
public class BindingNavigate : AvaloniaObject, ICommand
{
private bool _singletonCanExecute = true;
private EventHandler? _singletonCanExecuteChanged;
private bool _singletonCanExecute = true;
private EventHandler? _singletonCanExecuteChanged;

public AvaloniaObject? Sender { get; internal set; }
public string Path { get; set; }
public NavigateType? Type { get; set; }
public IPageTransition? Transition { get; set; }
public AvaloniaObject? Sender { get; internal set; }
public string Path { get; set; }

Check warning on line 19 in src/AvaloniaInside.Shell/BindingNavigate.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Path' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public NavigateType? Type { get; set; }
public IPageTransition? Transition { get; set; }

public event EventHandler? CanExecuteChanged
{
add => _singletonCanExecuteChanged += value;
remove => _singletonCanExecuteChanged -= value;
}
public event EventHandler? CanExecuteChanged
{
add => _singletonCanExecuteChanged += value;
remove => _singletonCanExecuteChanged -= value;
}

public bool CanExecute(object? parameter) => _singletonCanExecute;
public void Execute(object? parameter) => ExecuteAsync(parameter, CancellationToken.None);
public bool CanExecute(object? parameter) => _singletonCanExecute;
public void Execute(object? parameter) => ExecuteAsync(parameter, CancellationToken.None);

Check warning on line 30 in src/AvaloniaInside.Shell/BindingNavigate.cs

View workflow job for this annotation

GitHub Actions / build

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

public async Task ExecuteAsync(object? parameter, CancellationToken cancellationToken)
{
public async Task ExecuteAsync(object? parameter, CancellationToken cancellationToken)
{
if (Sender is not Visual visual) return;
if (visual.FindAncestorOfType<ShellView>() is not { } shell) return;

Expand Down Expand Up @@ -63,9 +63,8 @@ await shell.Navigator.NavigateAsync(
}
}

public static implicit operator BindingNavigate(string path) => new BindingNavigate
{
Path = path
};
}
}
public static implicit operator BindingNavigate(string path) => new BindingNavigate
{
Path = path
};
}
3 changes: 1 addition & 2 deletions src/AvaloniaInside.Shell/BindingNavigateConverter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Avalonia.Media;
using System;
using System;
using System.ComponentModel;
using System.Globalization;

Expand Down
189 changes: 4 additions & 185 deletions src/AvaloniaInside.Shell/Default.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,192 +3,11 @@

<Styles.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key='Light'>
<SolidColorBrush x:Key='AppBackground' Color="{OnPlatform White, iOS=Black}"></SolidColorBrush>
<SolidColorBrush x:Key='PageBackground'>White</SolidColorBrush>
</ResourceDictionary>
<ResourceDictionary x:Key='Dark'>
<SolidColorBrush x:Key='AppBackground'>Black</SolidColorBrush>
<SolidColorBrush x:Key='PageBackground'>Black</SolidColorBrush>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="Theme/Default/Colors.axaml"></ResourceInclude>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Styles.Resources>

<Style Selector="NavigationBar">
<Setter Property="Template">
<ControlTemplate TargetType="NavigationBar">
<Border Background="{TemplateBinding Background}"
Padding="{TemplateBinding Padding}"
Margin="{TemplateBinding Margin}"
MinHeight="35">
<Grid RowDefinitions="Auto,*">
<Border Grid.Row="0"
Height="{TemplateBinding TopSafeSpace}"
IsVisible="{TemplateBinding ApplyTopSafePadding}"></Border>
<Button Name="PART_ActionButton"
HorizontalAlignment="Left"
VerticalAlignment="Center"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Width="35"
Grid.Row="1">
</Button>
<TransitioningContentControl Grid.Row="1" Name="PART_Header" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TransitioningContentControl Grid.Row="1" Name="PART_Items" HorizontalAlignment="Right" VerticalAlignment="Center" />
</Grid>
</Border>
</ControlTemplate>
</Setter>
</Style>

<Style Selector="ShellView">
<Setter Property="Template">
<ControlTemplate>
<Panel Background="{TemplateBinding Background}">
<SplitView Name="PART_SplitView" DisplayMode="Inline">
<SplitView.Pane>
<SideMenu Name="PART_SideMenu"
SelectedItem="{TemplateBinding SideMenuSelectedItem, Mode=TwoWay}"
Header="{TemplateBinding SideMenuHeader}"
Footer="{TemplateBinding SideMenuFooter}"
Contents="{TemplateBinding SideMenuContents}"
ContentsTemplate="{TemplateBinding SideMenuContentsTemplate}">
</SideMenu>
</SplitView.Pane>

<Grid RowDefinitions="Auto,*,Auto">
<NavigationBar Name="PART_NavigationBar"
TopSafePadding="{TemplateBinding TopSafePadding}"
TopSafeSpace="{TemplateBinding TopSafeSpace}"
ApplyTopSafePadding="{TemplateBinding ApplyTopSafePadding}"/>
<StackContentView Name="PART_ContentView"
Grid.Row="1"
PageTransition="{TemplateBinding DefaultPageTransition}"></StackContentView>
<Border Grid.Row="2"
IsVisible="{TemplateBinding ApplyBottomSafePadding}"
Height="{TemplateBinding BottomSafeSpace}">
<Border.Styles>
<Style Selector="Border[IsVisible=True]">
<Setter Property="RenderTransform" Value="scaleY(1)"></Setter>
</Style>
<Style Selector="Border[IsVisible=False]">
<Setter Property="RenderTransform" Value="scaleY(0)"></Setter>
</Style>
</Border.Styles>
</Border>
</Grid>
</SplitView>

<Rectangle IsVisible="{Binding ElementName=PART_Modal, Path=HasContent}"
Opacity="0.5">
<Rectangle.Fill>
<VisualBrush
TileMode="Tile"
SourceRect="0,0,8,8"
DestinationRect="0,0,8,8"
Stretch="UniformToFill">
<VisualBrush.Visual>
<Canvas Width="8" Height="8">
<Rectangle Fill="Black" Width="8" Height="8"></Rectangle>
<Line StartPoint="0,0" EndPoint="8,8" Stroke="#55555555" StrokeThickness="1" />
<Line StartPoint="0,8" EndPoint="8,0" Stroke="#55555555" StrokeThickness="1" />
</Canvas>
</VisualBrush.Visual>
</VisualBrush>
</Rectangle.Fill>
</Rectangle>

<StackContentView Name="PART_Modal"
IsVisible="{Binding ElementName=PART_Modal, Path=HasContent}"
PageTransition="{TemplateBinding ModalPageTransition}">
</StackContentView>
</Panel>
</ControlTemplate>
</Setter>
<Setter Property="SideMenuContentsTemplate">
<DataTemplate>
<ContentPresenter Content="{Binding .}"></ContentPresenter>
</DataTemplate>
</Setter>
</Style>

<Style Selector="SideMenu">
<Setter Property="Template">
<ControlTemplate>
<Grid RowDefinitions="Auto,*,Auto">
<ContentPresenter Name="PART_Header"
ContentTemplate="{TemplateBinding HeaderTemplate}"
Content="{TemplateBinding Header}"></ContentPresenter>
<ScrollViewer Grid.Row="1">
<StackPanel Orientation="Vertical">
<ListBox Name="PART_Items"
ItemsSource="{TemplateBinding Items}"
SelectedItem="{TemplateBinding SelectedItem, Mode=TwoWay}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="22" Spacing="8">
<Image Source="{Binding Icon}"
IsVisible="{Binding !!Icon}"
VerticalAlignment="Center"></Image>
<TextBlock Text="{Binding Title}"
VerticalAlignment="Center"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ItemsControl Name="PART_Contents"
ItemsSource="{TemplateBinding Contents}"
ItemTemplate="{TemplateBinding ContentsTemplate}" />
</StackPanel>
</ScrollViewer>
<ContentPresenter Grid.Row="2"
Name="PART_Footer"
ContentTemplate="{TemplateBinding FooterTemplate}"
Content="{TemplateBinding Footer}"></ContentPresenter>
</Grid>
</ControlTemplate>
</Setter>
</Style>

<Style Selector="Button.BackButton">
<Setter Property="Template">
<ControlTemplate>
<Viewbox Stretch="UniformToFill">
<Canvas Width="16" Height="16" Margin="5" Background="#00000000">
<Line StartPoint="7,2" EndPoint="2,8" StrokeThickness="3" Stroke="{DynamicResource ButtonForeground}"></Line>
<Line StartPoint="2,6" EndPoint="7,12" StrokeThickness="3" Stroke="{DynamicResource ButtonForeground}"></Line>
</Canvas>
</Viewbox>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="Button.SideMenuButton">
<Setter Property="RenderTransform" Value="rotate(180deg)" />
<Setter Property="Template">
<ControlTemplate>
<Viewbox Stretch="UniformToFill">
<Canvas Width="16" Height="16" Margin="5" Background="#00000000">
<Line StartPoint="1,4" EndPoint="15,4" StrokeThickness="3" Stroke="{DynamicResource ButtonForeground}"></Line>
<Line StartPoint="1,8" EndPoint="15,8" StrokeThickness="3" Stroke="{DynamicResource ButtonForeground}"></Line>
<Line StartPoint="1,12" EndPoint="15,12" StrokeThickness="3" Stroke="{DynamicResource ButtonForeground}"></Line>
</Canvas>
</Viewbox>
</ControlTemplate>
</Setter>
</Style>

<Style Selector="Page">
<Setter Property="Background" Value="{DynamicResource PageBackground}" />
</Style>

<Style Selector="ShellView">
<Setter Property="Background" Value="{DynamicResource AppBackground}" />
</Style>
<StyleInclude Source="/Theme/Default/Controls.axaml" />
</Styles>
14 changes: 7 additions & 7 deletions src/AvaloniaInside.Shell/DefaultNavigationUpdateStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;

namespace AvaloniaInside.Shell;

Expand All @@ -21,15 +21,14 @@ public DefaultNavigationUpdateStrategy(IPresenterProvider presenterProvider)
public async Task UpdateChangesAsync(
ShellView shellView,
NavigationStackChanges changes,
List<object> newInstances,
NavigateType navigateType,
object? argument,
bool hasArgument,
CancellationToken cancellationToken)
{
var isSame = changes.Previous == changes.Front;

foreach (var instance in newInstances)
foreach (var instance in changes.NewNavigationChains.Select(s => s.Instance))
{
if (instance is INavigationLifecycle navigationLifecycle)
await navigationLifecycle.InitialiseAsync(cancellationToken);
Expand Down Expand Up @@ -80,14 +79,15 @@ private async Task InvokeRemoveAsync(ShellView shellView,

private void SubscribeForUpdateIfNeeded(object? instance)
{
if (instance is not SelectingItemsControl selectingItemsControl) return;
selectingItemsControl.SelectionChanged += SelectingItemsControlOnSelectionChanged;
if (HostedItemsHelper.GetSelectableHostedItems(instance) is {} hosted)
hosted.SelectionChanged += SelectingItemsControlOnSelectionChanged;

}

private void UnSubscribeForUpdateIfNeeded(object instance)
{
if (instance is not SelectingItemsControl selectingItemsControl) return;
selectingItemsControl.SelectionChanged -= SelectingItemsControlOnSelectionChanged;
if (HostedItemsHelper.GetSelectableHostedItems(instance) is {} hosted)
hosted.SelectionChanged -= SelectingItemsControlOnSelectionChanged;
}

private void SelectingItemsControlOnSelectionChanged(object? sender, SelectionChangedEventArgs e)
Expand Down
Loading

0 comments on commit 0ccd2f8

Please sign in to comment.