-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Expander initial commit Add samples Fix BindingContext is null Android Expander iOS Configure Header Do not arrange content on expanded change More samples, fix Android InvalidateMeasure, add animation Animation Android. fix WIndows build Update sample Fix PR comments Fix Apple animation Fix pipeline Expander tests Summary * Add Command and CommandParameter * Detect cell and force update size * Expander2 * Register Expander page * Remove Expander Handler * Fix formatting * Remove animation * Use StackLayout instead of Grid because it wraps content * Add docs * Update samples * Fix Expander content is not wrapped * Fix tests * listview resize * Fix formatting * Remove incorrect namespace * Update Sample, Use Static Methods * Update ExpanderPageCS.cs * Ensure Command Fires * Remove Children Before Creating New Grid * Add `InvalidEnumArgumentException` Test * Avoid Re-initializing Grid * Fixes Expander crash when Header or Content is null * Add `Title` * Disable `ListView` + `CollectionView` support Co-authored-by: Brandon Minnick <[email protected]> Co-authored-by: Pedro Jesus <[email protected]>
- Loading branch information
1 parent
cda2fbe
commit 1ea488c
Showing
14 changed files
with
558 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?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> | ||
</VerticalStackLayout> | ||
</ScrollView> | ||
</pages:BasePage> |
23 changes: 23 additions & 0 deletions
23
samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
samples/CommunityToolkit.Maui.Sample/Pages/Views/Expander/ExpanderPageCS.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using CommunityToolkit.Maui.Core; | ||
using CommunityToolkit.Maui.Views; | ||
using CommunityToolkit.Maui.Markup; | ||
|
||
namespace CommunityToolkit.Maui.Sample.Pages.Views; | ||
|
||
public class ExpanderPageCS : ContentPage | ||
{ | ||
public ExpanderPageCS() | ||
{ | ||
Title = "Expander Page, C# UI"; | ||
|
||
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) | ||
} | ||
}; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
samples/CommunityToolkit.Maui.Sample/ViewModels/Views/ExpanderViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/CommunityToolkit.Maui.Core/Interfaces/IExpander.shared.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/CommunityToolkit.Maui.Core/Primitives/ExpandDirection.shared.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
20 changes: 20 additions & 0 deletions
20
src/CommunityToolkit.Maui.Core/Primitives/ExpandedChangedEventArgs.shared.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
19 changes: 19 additions & 0 deletions
19
src/CommunityToolkit.Maui.UnitTests/Views/Expander/ExpandedChangedEventArgsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/CommunityToolkit.Maui.UnitTests/Views/Expander/ExpanderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System.ComponentModel; | ||
using CommunityToolkit.Maui.Core; | ||
using CommunityToolkit.Maui.UnitTests.Mocks; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace CommunityToolkit.Maui.UnitTests.Views.Expander; | ||
|
||
public class ExpanderTests : BaseHandlerTest | ||
{ | ||
readonly Maui.Views.Expander expander = new(); | ||
|
||
[Fact] | ||
public void ExpanderShouldBeAssignedToIExpander() | ||
{ | ||
new Maui.Views.Expander().Should().BeAssignableTo<IExpander>(); | ||
} | ||
|
||
[Fact] | ||
public void CheckDefaultValues() | ||
{ | ||
Assert.Equal(ExpandDirection.Down, expander.Direction); | ||
Assert.False(expander.IsExpanded); | ||
Assert.Null(expander.Content); | ||
Assert.Null(expander.Header); | ||
Assert.Null(expander.Command); | ||
Assert.Null(expander.CommandParameter); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void ExpandedChangedIsExpandedPassedWithEvent(bool expectedIsExpanded) | ||
{ | ||
bool? isExpanded = null; | ||
var action = new EventHandler<ExpandedChangedEventArgs>((_, e) => isExpanded = e.IsExpanded); | ||
expander.ExpandedChanged += action; | ||
((IExpander)expander).ExpandedChanged(expectedIsExpanded); | ||
expander.ExpandedChanged -= action; | ||
|
||
isExpanded.Should().Be(expectedIsExpanded); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void ExpandedChangedCommandExecutedWithParams(bool expectedIsExpanded) | ||
{ | ||
bool? isExpanded = null; | ||
|
||
expander.Command = new Command<bool>(parameter => isExpanded = parameter); | ||
expander.CommandParameter = expectedIsExpanded; | ||
((IExpander)expander).ExpandedChanged(expectedIsExpanded); | ||
|
||
isExpanded.Should().Be(expectedIsExpanded); | ||
} | ||
|
||
[Theory] | ||
[InlineData((ExpandDirection)(-1))] | ||
[InlineData((ExpandDirection)2)] | ||
public void ExpanderDirectionThrowsInvalidEnumArgumentException(ExpandDirection direction) | ||
{ | ||
Assert.Throws<InvalidEnumArgumentException>(() => expander.Direction = direction); | ||
} | ||
} |
Oops, something went wrong.