Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expander #478

Merged
merged 47 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
7931a05
Expander initial commit
VladislavAntonyuk Jul 5, 2022
59ebeab
Add Command and CommandParameter
VladislavAntonyuk Jul 5, 2022
8da32c7
Merge branch 'main' into Expander
VladislavAntonyuk Jul 17, 2022
e5e8420
Detect cell and force update size
VladislavAntonyuk Jul 17, 2022
ffca17a
Merge remote-tracking branch 'origin/Expander' into Expander
VladislavAntonyuk Jul 17, 2022
a32c2af
Expander2
VladislavAntonyuk Jul 17, 2022
cd41764
Merge branch 'main' into Expander
VladislavAntonyuk Aug 3, 2022
c4085c5
Register Expander page
VladislavAntonyuk Aug 3, 2022
0b9a9a0
Merge branch 'main' into Expander
VladislavAntonyuk Aug 4, 2022
7838c9c
Merge branch 'main' into Expander
TheCodeTraveler Aug 5, 2022
ec3119e
Merge branch 'main' into Expander
TheCodeTraveler Aug 5, 2022
8bec61d
Merge branch 'main' into Expander
VladislavAntonyuk Aug 14, 2022
81664cd
Remove Expander Handler
VladislavAntonyuk Aug 17, 2022
5bfce0d
Fix formatting
VladislavAntonyuk Aug 17, 2022
d103126
Remove animation
VladislavAntonyuk Aug 17, 2022
a02d27b
Merge branch 'main' into Expander
VladislavAntonyuk Aug 17, 2022
19d0942
Use StackLayout instead of Grid because it wraps content
VladislavAntonyuk Aug 18, 2022
75f5789
Add docs
VladislavAntonyuk Aug 18, 2022
0f79a1b
Update samples
VladislavAntonyuk Aug 18, 2022
b694395
Fix Expander content is not wrapped
VladislavAntonyuk Sep 1, 2022
93e69ad
Merge branch 'main' into Expander
VladislavAntonyuk Sep 1, 2022
3b3d651
Fix tests
VladislavAntonyuk Sep 2, 2022
6817a47
Merge remote-tracking branch 'origin/Expander' into Expander
VladislavAntonyuk Sep 2, 2022
e8dd4c2
Merge branch 'main' into Expander
VladislavAntonyuk Sep 2, 2022
d4acfde
Merge branch 'main' into Expander
TheCodeTraveler Sep 14, 2022
680ce9d
Merge branch 'main' into Expander
VladislavAntonyuk Sep 15, 2022
1e5f911
listview resize
VladislavAntonyuk Sep 15, 2022
a63686c
Merge branch 'main' into Expander
VladislavAntonyuk Sep 21, 2022
600ec4a
Merge branch 'main' into Expander
TheCodeTraveler Oct 12, 2022
f1729c2
Merge branch 'main' into Expander
VladislavAntonyuk Oct 20, 2022
8b8917c
Fix formatting
VladislavAntonyuk Oct 20, 2022
3c6fe52
Merge branch 'main' into Expander
VladislavAntonyuk Oct 20, 2022
5e5fb12
Merge branch 'main' into Expander
TheCodeTraveler Nov 1, 2022
e8f5d23
Remove incorrect namespace
TheCodeTraveler Nov 5, 2022
422aaf5
Update Sample, Use Static Methods
TheCodeTraveler Nov 6, 2022
29acda6
Update ExpanderPageCS.cs
TheCodeTraveler Nov 6, 2022
79668f3
Ensure Command Fires
TheCodeTraveler Nov 6, 2022
4696d39
Remove Children Before Creating New Grid
TheCodeTraveler Nov 6, 2022
9c882bb
Add `InvalidEnumArgumentException` Test
TheCodeTraveler Nov 6, 2022
38096ff
Avoid Re-initializing Grid
TheCodeTraveler Nov 6, 2022
5205600
Merge branch 'main' into Expander
TheCodeTraveler Nov 6, 2022
51400bc
Merge branch 'main' into Expander
VladislavAntonyuk Nov 8, 2022
6f35264
Merge branch 'main' into Expander
VladislavAntonyuk Nov 8, 2022
41b3bb6
Fixes Expander crash when Header or Content is null
VladislavAntonyuk Nov 8, 2022
cd17f0b
Merge branch 'main' into Expander
pictos Nov 8, 2022
8002dae
Add `Title`
TheCodeTraveler Nov 8, 2022
5f719c7
Disable `ListView` + `CollectionView` support
TheCodeTraveler Nov 8, 2022
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
1 change: 1 addition & 0 deletions samples/CommunityToolkit.Maui.Sample/AppShell.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public partial class AppShell : Shell
CreateViewModelMapping<AvatarViewShapesPage, AvatarViewShapesViewModel, ViewsGalleryPage, ViewsGalleryViewModel>(),
CreateViewModelMapping<AvatarViewSizesPage, AvatarViewSizesViewModel, ViewsGalleryPage, ViewsGalleryViewModel>(),
CreateViewModelMapping<DrawingViewPage, DrawingViewViewModel, ViewsGalleryPage, ViewsGalleryViewModel>(),
CreateViewModelMapping<ExpanderPage, ExpanderViewModel, ViewsGalleryPage, ViewsGalleryViewModel>(),
CreateViewModelMapping<MultiplePopupPage, MultiplePopupViewModel, ViewsGalleryPage, ViewsGalleryViewModel>(),
CreateViewModelMapping<PopupAnchorPage, PopupAnchorViewModel, ViewsGalleryPage, ViewsGalleryViewModel>(),
CreateViewModelMapping<PopupPositionPage, PopupPositionViewModel, ViewsGalleryPage, ViewsGalleryViewModel>(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0-ios;net6.0-android;net6.0-maccatalyst</TargetFrameworks>
Expand Down Expand Up @@ -60,8 +60,15 @@
<ProjectReference Include="..\..\src\CommunityToolkit.Maui.Analyzers.CodeFixes\CommunityToolkit.Maui.Analyzers.CodeFixes.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<PropertyGroup Condition="$(TargetFramework.Contains('-android'))">
<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))=='android'">
<RuntimeIdentifiers>android-arm;android-arm64;android-x86;android-x64</RuntimeIdentifiers>
</PropertyGroup>

<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('windows'))=='false' and $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))=='maccatalyst' and $(Configuration) == 'Debug'">
<RuntimeIdentifiers>maccatalyst-arm64;maccatalyst-x64</RuntimeIdentifiers>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-ios|AnyCPU'">
<CreatePackage>false</CreatePackage>
</PropertyGroup>
</Project>
3 changes: 2 additions & 1 deletion samples/CommunityToolkit.Maui.Sample/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static void RegisterViewsAndViewModels(in IServiceCollection services)
// Add Extensions Pages + ViewModels
services.AddTransientWithShellRoute<ColorAnimationExtensionsPage, ColorAnimationExtensionsViewModel>();

// Add ImageSources pages + ViewModels
// Add ImageSources Pages + ViewModels
services.AddTransientWithShellRoute<GravatarImageSourcePage, GravatarImageSourceViewModel>();

// Add Layouts Pages + ViewModels
Expand All @@ -146,6 +146,7 @@ static void RegisterViewsAndViewModels(in IServiceCollection services)

// Add Views Pages + ViewModels
services.AddTransientWithShellRoute<DrawingViewPage, DrawingViewViewModel>();
services.AddTransientWithShellRoute<ExpanderPage, ExpanderViewModel>();
services.AddTransientWithShellRoute<MultiplePopupPage, MultiplePopupViewModel>();
services.AddTransientWithShellRoute<PopupAnchorPage, PopupAnchorViewModel>();
services.AddTransientWithShellRoute<PopupPositionPage, PopupPositionViewModel>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<pages:BasePage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:Class="CommunityToolkit.Maui.Sample.Pages.Views.ExpanderPage"
xmlns:pages="clr-namespace:CommunityToolkit.Maui.Sample.Pages"
xmlns:viewModels="clr-namespace:CommunityToolkit.Maui.Sample.ViewModels.Views"
x:TypeArguments="viewModels:ExpanderViewModel"
x:DataType="viewModels:ExpanderViewModel"
Title="Expander">

<ScrollView>
<VerticalStackLayout Spacing="10">
<Button Text="Navigate to C# Sample" Clicked="GoToCSharpSampleClicked"/>

<Label Text="Simple expander" FontSize="24" FontAttributes="Bold"/>

<mct:Expander>
<mct:Expander.Header>
<Label Text="Simple Expander (Tap Me)" FontSize="16" FontAttributes="Bold"/>
</mct:Expander.Header>

<mct:Expander.Content BackgroundColor="LightGray">
<VerticalStackLayout>
<Label Text="Item 1"/>
<Label Text="Item 2"/>
</VerticalStackLayout>
</mct:Expander.Content>
</mct:Expander>

<Label Text="Multi-level expander" FontSize="24" FontAttributes="Bold"/>

<mct:Expander Direction="Up">
<mct:Expander.Header>
<Label Text="Multi-Level Expander (Tap Me)" FontSize="16" FontAttributes="Bold"/>
</mct:Expander.Header>
<mct:Expander.Content BackgroundColor="LightGray">
<mct:Expander Direction="Down" BackgroundColor="LightGray">
<mct:Expander.Header>
<Label Text="Nested Expander (Tap Me)" FontSize="14" FontAttributes="Bold"/>
</mct:Expander.Header>
<mct:Expander.Content>
<Label Text="Item 1" />
</mct:Expander.Content>
</mct:Expander>
</mct:Expander.Content>
</mct:Expander>

<Label Text="Expander in ListView" FontSize="24" FontAttributes="Bold"/>

<ListView ItemsSource="{Binding ContentCreators}"
HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<mct:Expander x:DataType="viewModels:ContentCreator"
ExpandedChanged="Expander_ExpandedChanged">
<mct:Expander.Header>
<Label Text="{Binding Name}"/>
</mct:Expander.Header>
<mct:Expander.Content>
<VerticalStackLayout>
<Label Text="{Binding Resource}"/>
<Image Source="{Binding Image}"
WidthRequest="100"
HeightRequest="100"/>
</VerticalStackLayout>
</mct:Expander.Content>
</mct:Expander>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

<Label Text="Expander in CollectionView" FontSize="24" FontAttributes="Bold"/>

<CollectionView ItemsSource="{Binding ContentCreators}">
<CollectionView.ItemTemplate>
<DataTemplate>
<mct:Expander x:DataType="viewModels:ContentCreator"
ExpandedChanged="Expander_ExpandedChanged">
<mct:Expander.Header>
<Label Text="{Binding Name}"/>
</mct:Expander.Header>
<mct:Expander.Content>
<VerticalStackLayout>
<Label Text="{Binding Resource}" HorizontalOptions="Center"/>
<Image Source="{Binding Image}"
WidthRequest="100"
HeightRequest="100"/>
</VerticalStackLayout>
</mct:Expander.Content>
</mct:Expander>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</ScrollView>
</pages:BasePage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Maui.Sample.ViewModels.Views;

namespace CommunityToolkit.Maui.Sample.Pages.Views;

public partial class ExpanderPage : BasePage<ExpanderViewModel>
{
public ExpanderPage(ExpanderViewModel viewModel) : base(viewModel)
{
InitializeComponent();
}

async void Expander_ExpandedChanged(object sender, Core.ExpandedChangedEventArgs e)
{
var collapsedText = e.IsExpanded ? "expanded" : "collapsed";
await Toast.Make($"Expander is {collapsedText}").Show(CancellationToken.None);
}

async void GoToCSharpSampleClicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new ExpanderPageCS());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using CommunityToolkit.Maui.Core;
using CommunityToolkit.Maui.Views;
using CommunityToolkit.Maui.Markup;

namespace CommunityToolkit.Maui.Sample.Pages.Views;

public class ExpanderPageCS : ContentPage
{
public ExpanderPageCS()
{
Content = new VerticalStackLayout()
{
Spacing = 12,

Children =
{
new Label()
.Text("Expander C# Sample")
.Font(bold: true, size: 24)
.CenterHorizontal(),

new Picker() { ItemsSource = Enum.GetValues<ExpandDirection>(), Title = "Direction" }
.CenterHorizontal().TextCenter()
.Assign(out Picker picker),

new Expander
{
Header = new Label()
.Text("Expander (Tap Me)")
.Font(bold: true, size: 18),

Content = new VerticalStackLayout()
{
new Image()
.Source("https://avatars.githubusercontent.com/u/9011267?v=4")
.Size(120)
.Aspect(Aspect.AspectFit),

new Label()
.Text(".NET Multi-platform App UI (.NET MAUI) is a cross-platform framework for creating mobile and desktop apps with C# and XAML. Using .NET MAUI, you can develop apps that can run on Android, iOS, iPadOS, macOS, and Windows from a single shared codebase.")
.Font(italic: true)

}.Padding(10)

}.CenterHorizontal()
.Bind(Expander.DirectionProperty, nameof(Picker.SelectedIndex), source: picker, convert: (int selectedIndex) => Enum.IsDefined(typeof(ExpandDirection), selectedIndex) ? (ExpandDirection)selectedIndex : default)
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;

namespace CommunityToolkit.Maui.Sample.ViewModels.Views;

public partial class ExpanderViewModel : BaseViewModel
{
public ObservableCollection<ContentCreator> ContentCreators { get; } = new();

public ExpanderViewModel()
{
ContentCreators.Add(new ContentCreator("Brandon Minnick", "https://codetraveler.io/", "https://avatars.githubusercontent.com/u/13558917"));
ContentCreators.Add(new ContentCreator("Gerald Versluis", "https://blog.verslu.is/", "https://avatars.githubusercontent.com/u/939291"));
ContentCreators.Add(new ContentCreator("Kym Phillpotts", "https://kymphillpotts.com", "https://avatars.githubusercontent.com/u/1327346"));
ContentCreators.Add(new ContentCreator("Pedro Jesus", "https://github.com/pictos", "https://avatars.githubusercontent.com/u/20712372"));
ContentCreators.Add(new ContentCreator("Shaun Lawrence", "https://github.com/bijington", "https://avatars.githubusercontent.com/u/17139988"));
ContentCreators.Add(new ContentCreator("Vladislav Antonyuk", "https://vladislavantonyuk.azurewebsites.net", "https://avatars.githubusercontent.com/u/33021114"));
}
}

public record ContentCreator(string Name, string Resource, string Image);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CommunityToolkit.Maui.Sample.Models;
using CommunityToolkit.Maui.Sample.Models;
using CommunityToolkit.Maui.Sample.ViewModels.Views.AvatarView;

namespace CommunityToolkit.Maui.Sample.ViewModels.Views;
Expand All @@ -20,9 +20,10 @@ public ViewsGalleryViewModel()
SectionModel.Create<AvatarViewShapesViewModel>("AvatarView Shapes Page", Colors.Red, "A page demonstrating AvatarViews with various shape options."),
SectionModel.Create<AvatarViewSizesViewModel>("AvatarView Sizes Page", Colors.Red, "A page demonstrating AvatarViews with various size options."),
SectionModel.Create<DrawingViewViewModel>("DrawingView", Colors.Red, "DrawingView provides a canvas for users to \"paint\" on the screen. The drawing can also be captured and displayed as an Image."),
SectionModel.Create<ExpanderViewModel>("Expander Page", Colors.Red, "Expander allows collapse and expand content."),
SectionModel.Create<MultiplePopupViewModel>("Mutiple Popups Page", Colors.Red, "A page demonstrating multiple different Popups"),
SectionModel.Create<PopupPositionViewModel>("Custom Positioning Popup", Colors.Red, "Displays a basic popup anywhere on the screen using VerticalOptions and HorizontalOptions"),
SectionModel.Create<PopupAnchorViewModel>("Anchor Popup", Colors.Red, "Popups can be anchored to other view's on the screen"),
SectionModel.Create<PopupAnchorViewModel>("Anchor Popup", Colors.Red, "Popups can be anchored to other view's on the screen")
})
{
}
Expand Down
27 changes: 27 additions & 0 deletions src/CommunityToolkit.Maui.Core/Interfaces/IExpander.shared.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace CommunityToolkit.Maui.Core;

/// <summary>
/// Allows collapse and expand content.
/// </summary>
public interface IExpander : IContentView
{
/// <summary>
/// Expander header.
/// </summary>
public IView? Header { get; }

/// <summary>
/// Gets or sets expand direction.
/// </summary>
public ExpandDirection Direction { get; }

/// <summary>
/// Gets or sets Expander collapsible state.
/// </summary>
public bool IsExpanded { get; set; }

/// <summary>
/// Action when <see cref="IsExpanded"/> changes
/// </summary>
void ExpandedChanged(bool isExpanded);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CommunityToolkit.Maui.Core.Primitives;
namespace CommunityToolkit.Maui.Core;

/// <summary>
/// Visual Options for <see cref="CommunityToolkit.Maui.Core.Views.AlertView"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace CommunityToolkit.Maui.Core;

/// <summary>
/// Expander expand direction.
/// </summary>
public enum ExpandDirection
{
/// <summary>
/// Expander expands down
/// </summary>
Down,

/// <summary>
/// Expander expands up
/// </summary>
Up
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace CommunityToolkit.Maui.Core;

/// <summary>
/// Contains Expander IsExpanded state.
/// </summary>
public class ExpandedChangedEventArgs : EventArgs
{
/// <summary>
/// Initialize a new instance of <see cref="ExpandedChangedEventArgs"/>
/// </summary>
public ExpandedChangedEventArgs(bool isExpanded)
{
IsExpanded = isExpanded;
}

/// <summary>
/// True if Is Expanded.
/// </summary>
public bool IsExpanded { get; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using CommunityToolkit.Maui.Core;
using CommunityToolkit.Maui.Core.Extensions;
using CommunityToolkit.Maui.Core.Primitives;

namespace CommunityToolkit.Maui.Core.Views;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.ObjectModel;
using CommunityToolkit.Maui.Core;
using CommunityToolkit.Maui.Core.Views;
using FluentAssertions;
using Xunit;

namespace CommunityToolkit.Maui.UnitTests.Views.Expander;

public class ExpandedChangedEventArgsTests : BaseHandlerTest
{
[Theory]
[InlineData(true)]
[InlineData(false)]
public void IsExpandedShouldBeEqualInExpandedChangedEventArgs(bool isExpanded)
{
var eventArgs = new ExpandedChangedEventArgs(isExpanded);
eventArgs.IsExpanded.Should().Be(isExpanded);
}
}
Loading