Skip to content

Commit

Permalink
Switch tab initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
BurkusCat committed Oct 5, 2023
1 parent 1ad86b8 commit 9cbe493
Show file tree
Hide file tree
Showing 20 changed files with 344 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,6 @@ healthchecksdb

# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/

# Meteor
.meteor/
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,9 @@ The below are some things of note that may help prevent issues from arising:
# Contributing 💁‍♀️
Contributions are very welcome! Please see the [contributing guide](CONTRIBUTING.MD) to get started.

[![NuGet release](https://github.com/BurkusCat/Burkus.Mvvm.Maui/actions/workflows/release-nuget.yml/badge.svg)](https://github.com/BurkusCat/Burkus.Mvvm.Maui/actions/workflows/release-nuget.yml)
[![Build for CI](https://github.com/BurkusCat/Burkus.Mvvm.Maui/actions/workflows/ci.yml/badge.svg)](https://github.com/BurkusCat/Burkus.Mvvm.Maui/actions/workflows/ci.yml)
[![Build Demo App for CI](https://github.com/BurkusCat/Burkus.Mvvm.Maui/actions/workflows/ci-demo-app.yml/badge.svg)](https://github.com/BurkusCat/Burkus.Mvvm.Maui/actions/workflows/ci-demo-app.yml)
# License 🪪
The project is distributed under the [MIT license](LICENSE). Contributors do not need to sign a CLA.
24 changes: 24 additions & 0 deletions samples/DemoApp/DemoApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,21 @@
<Compile Update="Views\ChangeUsernamePage.xaml.cs">
<DependentUpon>ChangeUsernamePage.xaml</DependentUpon>
</Compile>
<Compile Update="Views\Tabs\CharlieTabPage.xaml.cs">
<DependentUpon>CharlieTabPage.xaml</DependentUpon>
</Compile>
<Compile Update="Views\Tabs\BetaTabPage.xaml.cs">
<DependentUpon>BetaTabPage.xaml</DependentUpon>
</Compile>
<Compile Update="Views\Tabs\DemoTabsPage.xaml.cs">
<DependentUpon>DemoTabsPage.xaml</DependentUpon>
</Compile>
<Compile Update="Views\RegisterPage.xaml.cs">
<DependentUpon>RegisterPage.xaml</DependentUpon>
</Compile>
<Compile Update="Views\Tabs\AlphaTabPage.xaml.cs">
<DependentUpon>AlphaTabPage.xaml</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
Expand All @@ -72,12 +84,24 @@
<MauiXaml Update="Views\HomePage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</MauiXaml>
<MauiXaml Update="Views\Tabs\CharlieTabPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</MauiXaml>
<MauiXaml Update="Views\Tabs\BetaTabPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</MauiXaml>
<MauiXaml Update="Views\Tabs\DemoTabsPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</MauiXaml>
<MauiXaml Update="Views\RegisterPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</MauiXaml>
<MauiXaml Update="Views\LoginPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</MauiXaml>
<MauiXaml Update="Views\Tabs\AlphaTabPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</MauiXaml>
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions samples/DemoApp/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static MauiApp CreateMauiApp()
public static MauiAppBuilder RegisterViewModels(this MauiAppBuilder mauiAppBuilder)
{
mauiAppBuilder.Services.AddTransient<ChangeUsernameViewModel>();
mauiAppBuilder.Services.AddTransient<DemoTabsViewModel>();
mauiAppBuilder.Services.AddTransient<HomeViewModel>();
mauiAppBuilder.Services.AddTransient<LoginViewModel>();
mauiAppBuilder.Services.AddTransient<RegisterViewModel>();
Expand All @@ -49,6 +50,7 @@ public static MauiAppBuilder RegisterViewModels(this MauiAppBuilder mauiAppBuild
public static MauiAppBuilder RegisterViews(this MauiAppBuilder mauiAppBuilder)
{
mauiAppBuilder.Services.AddTransient<ChangeUsernamePage>();
mauiAppBuilder.Services.AddTransient<DemoTabsPage>();
mauiAppBuilder.Services.AddTransient<HomePage>();
mauiAppBuilder.Services.AddTransient<LoginPage>();
mauiAppBuilder.Services.AddTransient<RegisterPage>();
Expand Down
58 changes: 58 additions & 0 deletions samples/DemoApp/ViewModels/DemoTabsViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using DemoApp.Views;

namespace DemoApp.ViewModels;

public partial class DemoTabsViewModel : BaseViewModel
{
#region Constructors

public DemoTabsViewModel(
INavigationService navigationService)
: base(navigationService)
{
}

#endregion Constructors

#region Commands

/// <summary>
/// Navigate back to the homepage.
/// </summary>
[RelayCommand]
private async Task GoBack()
{
await navigationService.Pop();
}

/// <summary>
/// Navigate to Alpha tab page.
/// </summary>
[RelayCommand]
private async Task SwitchToAlphaTabPage()
{
await navigationService.SelectTab<AlphaTabPage>();
}

/// <summary>
/// Navigate to Beta tab page.
/// </summary>
[RelayCommand]
private async Task SwitchToBetaTabPage()
{
await navigationService.SelectTab<BetaTabPage>();
}

/// <summary>
/// Navigate to Charlie tab page.
/// </summary>
[RelayCommand]
private async Task SwitchToCharlieTabPage()
{
await navigationService.SelectTab<CharlieTabPage>();
}

#endregion Commands
}
9 changes: 9 additions & 0 deletions samples/DemoApp/ViewModels/HomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,14 @@ private async Task ChangeUsernameWithAnimation()
await navigationService.Push<ChangeUsernamePage>(navigationParameters);
}

/// <summary>
/// Navigate to the example tabbed page.
/// </summary>
[RelayCommand]
private async Task GoToTabbedPageDemo()
{
await navigationService.Push<DemoTabsPage>();
}

#endregion Commands
}
9 changes: 8 additions & 1 deletion samples/DemoApp/Views/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Grid
Margin="15"
MaximumWidthRequest="600"
RowDefinitions="*,Auto,Auto,Auto,*"
RowDefinitions="*,Auto,Auto,Auto,Auto,*"
RowSpacing="10">
<Label
Grid.Row="0"
Expand All @@ -38,6 +38,13 @@
MaximumWidthRequest="400"
Text="Change Username (no animation)"
VerticalOptions="Start" />
<Button
Grid.Row="4"
Margin="0,20,0,0"
Command="{Binding GoToTabbedPageDemoCommand}"
MaximumWidthRequest="400"
Text="Tabbed Page demo"
VerticalOptions="Start" />
</Grid>
</ScrollView>
</ContentPage>
46 changes: 46 additions & 0 deletions samples/DemoApp/Views/Tabs/AlphaTabPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="DemoApp.Views.AlphaTabPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:burkus="http://burkus.co.uk"
xmlns:vm="clr-namespace:DemoApp.ViewModels"
Title="Alpha"
x:DataType="vm:DemoTabsViewModel">
<ScrollView>
<Grid
Margin="15"
MaximumWidthRequest="600"
RowDefinitions="*,Auto,Auto,*"
RowSpacing="10">
<Label
Grid.Row="0"
FontAttributes="Bold"
FontSize="20"
HorizontalOptions="CenterAndExpand"
Text="Alpha"
VerticalOptions="CenterAndExpand" />
<Button
Grid.Row="1"
Margin="0,20,0,0"
Command="{Binding SwitchToBetaTabPageCommand}"
MaximumWidthRequest="300"
Text="Switch to Beta"
VerticalOptions="Start" />
<Button
Grid.Row="2"
Margin="0,20,0,0"
Command="{Binding SwitchToCharlieTabPageCommand}"
MaximumWidthRequest="300"
Text="Switch to Charlie"
VerticalOptions="Start" />
<Button
Grid.Row="3"
Margin="0,20,0,0"
Command="{Binding GoBackCommand}"
MaximumWidthRequest="300"
Text="Go Back"
VerticalOptions="Start" />
</Grid>
</ScrollView>
</ContentPage>
9 changes: 9 additions & 0 deletions samples/DemoApp/Views/Tabs/AlphaTabPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DemoApp.Views;

public partial class AlphaTabPage : ContentPage
{
public AlphaTabPage()
{
InitializeComponent();
}
}
46 changes: 46 additions & 0 deletions samples/DemoApp/Views/Tabs/BetaTabPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="DemoApp.Views.BetaTabPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:burkus="http://burkus.co.uk"
xmlns:vm="clr-namespace:DemoApp.ViewModels"
Title="Beta"
x:DataType="vm:DemoTabsViewModel">
<ScrollView>
<Grid
Margin="15"
MaximumWidthRequest="600"
RowDefinitions="*,Auto,Auto,*"
RowSpacing="10">
<Label
Grid.Row="0"
FontAttributes="Bold"
FontSize="20"
HorizontalOptions="CenterAndExpand"
Text="Beta"
VerticalOptions="CenterAndExpand" />
<Button
Grid.Row="1"
Margin="0,20,0,0"
Command="{Binding SwitchToAlphaTabPageCommand}"
MaximumWidthRequest="300"
Text="Switch to Alpha"
VerticalOptions="Start" />
<Button
Grid.Row="2"
Margin="0,20,0,0"
Command="{Binding SwitchToCharlieTabPageCommand}"
MaximumWidthRequest="300"
Text="Switch to Charlie"
VerticalOptions="Start" />
<Button
Grid.Row="3"
Margin="0,20,0,0"
Command="{Binding GoBackCommand}"
MaximumWidthRequest="300"
Text="Go Back"
VerticalOptions="Start" />
</Grid>
</ScrollView>
</ContentPage>
9 changes: 9 additions & 0 deletions samples/DemoApp/Views/Tabs/BetaTabPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DemoApp.Views;

public partial class BetaTabPage : ContentPage
{
public BetaTabPage()
{
InitializeComponent();
}
}
46 changes: 46 additions & 0 deletions samples/DemoApp/Views/Tabs/CharlieTabPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="DemoApp.Views.CharlieTabPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:burkus="http://burkus.co.uk"
xmlns:vm="clr-namespace:DemoApp.ViewModels"
Title="Charlie"
x:DataType="vm:DemoTabsViewModel">
<ScrollView>
<Grid
Margin="15"
MaximumWidthRequest="600"
RowDefinitions="*,Auto,Auto,*"
RowSpacing="10">
<Label
Grid.Row="0"
FontAttributes="Bold"
FontSize="20"
HorizontalOptions="CenterAndExpand"
Text="Charlie"
VerticalOptions="CenterAndExpand" />
<Button
Grid.Row="1"
Margin="0,20,0,0"
Command="{Binding SwitchToAlphaTabPageCommand}"
MaximumWidthRequest="300"
Text="Switch to Alpha"
VerticalOptions="Start" />
<Button
Grid.Row="2"
Margin="0,20,0,0"
Command="{Binding SwitchToBetaTabPageCommand}"
MaximumWidthRequest="300"
Text="Switch to Beta"
VerticalOptions="Start" />
<Button
Grid.Row="3"
Margin="0,20,0,0"
Command="{Binding GoBackCommand}"
MaximumWidthRequest="300"
Text="Go Back"
VerticalOptions="Start" />
</Grid>
</ScrollView>
</ContentPage>
9 changes: 9 additions & 0 deletions samples/DemoApp/Views/Tabs/CharlieTabPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DemoApp.Views;

public partial class CharlieTabPage : ContentPage
{
public CharlieTabPage()
{
InitializeComponent();
}
}
15 changes: 15 additions & 0 deletions samples/DemoApp/Views/Tabs/DemoTabsPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage
x:Class="DemoApp.Views.DemoTabsPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:burkus="http://burkus.co.uk"
xmlns:views="clr-namespace:DemoApp.Views;assembly=DemoApp"
xmlns:vm="clr-namespace:DemoApp.ViewModels"
Title="Tabbed Page"
x:DataType="vm:DemoTabsViewModel"
BindingContext="{burkus:ResolveBindingContext x:TypeArguments=vm:DemoTabsViewModel}">
<views:AlphaTabPage Title="Alpha" />
<views:BetaTabPage Title="Beta" />
<views:CharlieTabPage Title="Charlie" />
</TabbedPage>
9 changes: 9 additions & 0 deletions samples/DemoApp/Views/Tabs/DemoTabsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DemoApp.Views;

public partial class DemoTabsPage : TabbedPage
{
public DemoTabsPage()
{
InitializeComponent();
}
}
8 changes: 8 additions & 0 deletions src/Abstractions/INavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,12 @@ Task ResetStackAndPush<T>()
/// <returns>A completed task</returns>
Task ResetStackAndPush<T>(NavigationParameters navigationParameters)
where T : Page;

/// <summary>
/// When within a <see cref="TabbedPage"/>, use this method to select a tab.
/// </summary>
/// <typeparam name="T">Type of Page</typeparam>
/// <returns>A completed task</returns>
Task SelectTab<T>()
where T : Page;
}
Loading

0 comments on commit 9cbe493

Please sign in to comment.