-
Notifications
You must be signed in to change notification settings - Fork 422
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
Expander #478
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work man, I did a quick review. I'll re-review again tomorrow since I'm a little sleepy and I may have missed something.
samples/CommunityToolkit.Maui.Sample/ViewModels/Views/ExpanderViewModel.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.Core/Views/Expander/PlatformView/MauiExpanderExtensions.shared.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.Core/Views/Expander/PlatformView/MauiExpanderExtensions.shared.cs
Outdated
Show resolved
Hide resolved
5a4669d
to
c49abaf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VladislavAntonyuk Thanks for this PR. I have some code suggestions and also found some bugs in all platforms. I'll do the Android and Windows in another post since the assets are on my Windows machine.
General
IMHO, since Windows provide control for that we should try to follow its guidelines, for example on Windows the header has an arrow icon and the controls have a better arrangement, we should mimic that for Android and Apple as well.
iOS / macOS
- We need to click two times to collapse or expand the control, as you can see in the video below.
Uploading Screen Recording 2022-07-05 at 20.13.22.mov…
- The Baboon expander doesn't appear
- The simple and multiple expanders doesn't work as well, they aren't renderer on screen. And the size isn't correctly applied to the ListView cell.
public ExpandDirection Direction { get; } | ||
|
||
/// <summary> | ||
/// Event occurred when IsExpanded changed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not an event
, can we change the term? Maybe method? Let's remember that we shouldn't influence the implementor in any way
} | ||
|
||
Header.Clickable = true; | ||
Header.SetOnClickListener(new HeaderClickEventListener(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this one is tricky. Because if we use the Listener
and the dev wants to customize it then he will lose all our implementation and will have to copy and paste our HeaderClickEventListener
, since it's internal, is it what we want?
On the other hand, we can use the Click
event to implement our logic, that way the dev can add his on delegate
and keep our implementation as well.
|
||
partial void Draw() | ||
{ | ||
if (Header is null || Content is null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that we need to set the Header
and the Content
in order to use the Expander
, but this is not very clear. Should add a log message/throw an exception telling the dev that he should provide both views?
I would say that could be a good idea to provide a default Header, maybe a BoxView? (If that isn't too hard)
|
||
partial void Draw() | ||
{ | ||
if (Header is null || Content is null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that we need to set the Header
and the Content
in order to use the Expander
, but this is not very clear. Should add a log message/throw an exception telling the dev that he should provide both views?
I would say that could be a good idea to provide a default Header, maybe a BoxView? (If that isn't too hard)
} | ||
|
||
var expanderGesture = new UITapGestureRecognizer(); | ||
expanderGesture.AddTarget(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small suggestion (:
expanderGesture.AddTarget(() => { | |
expanderGesture.AddTarget(() => | |
{ |
#if WINDOWS | ||
VirtualView.IsExpanded = false; | ||
VirtualView.ExpandedChanged(false); | ||
#else | ||
VirtualView.IsExpanded = !e.IsCollapsed; | ||
VirtualView.ExpandedChanged(!e.IsCollapsed); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we merge those? They have the same names for properties and method. And !e.IsCollapsed
should be false
for Windows, or not?
/// <summary> | ||
/// Event invoked when IsExpanded changed | ||
/// </summary> | ||
public event EventHandler<ExpanderCollapsedEventArgs> Collapsed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't use event handlers
here. Core
shouldn't force any pattern. The best solution is to call the IExpander.ExpandedChanged
method here.
If we've any Event Handler
exposed (public) in another control we should fix it.
/// <summary> | ||
/// Extension methods to support <see cref="IExpander"/> | ||
/// </summary> | ||
public static partial class MauiExpanderExtensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the partial
here
public static partial class MauiExpanderExtensions | |
public static class MauiExpanderExtensions |
/// </summary> | ||
public static void SetIsExpanded(this MauiExpander mauiExpander, bool isExpanded) | ||
{ | ||
if (mauiExpander.IsExpanded != isExpanded) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this check? This check should be in the IsExpanded.Setter
, that way will check for any type of value change.
Windows
expander.mp4Android
|
Thank you for detailed review @pictos. Windows uses native WinUI control, I didn't create custom MauiExpander.Windows. So it's a default behavior. There is a property to use all available horizontal space. I can set it to true by default |
@VladislavAntonyuk for ListView maybe you can try this. I believe that the dev will need to perform some properties on the ListView but you can call the |
Is it for sample? I believe it is not correct to call this method inside Expander. It's not its responsibility |
I thought to call that inside the expander, if the parent is a ListView. So the expander will communicate to the ListView that it needs to resize the cell. |
src/CommunityToolkit.Maui.Core/Views/Expander/PlatformView/MauiExpanderExtensions.shared.cs
Outdated
Show resolved
Hide resolved
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
6261033
to
59ebeab
Compare
Just adding the |
@pictos unfortunately Cell.ForceUpdateSize doesn't work. Windows: and |
@pictos I've just updated the sample and copied/pasted the code from XCT expander to compare the behavior. |
/dotnet format |
hope it won't delete the dotnet world |
When will this be merged? |
Hey Vlad! I made a couple tweaks to
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Vlad!
ListView support isn't working properly on iOS.
I confirmed that it is working on Android.
Simulator.Screen.Recording.-.iPhone.14.-.2022-11-06.at.12.27.25.mp4
@VladislavAntonyuk Since
Once we've finished these, I'm happy to Approve + Merge this PR 🙌 |
if (element is ListView listView) | ||
{ | ||
foreach (var child in listView.AllChildren.OfType<Cell>()) | ||
{ | ||
child.ForceUpdateSize(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's my recommendation to remove ListView
support from this release of Expander
if (element is ListView listView) | |
{ | |
foreach (var child in listView.AllChildren.OfType<Cell>()) | |
{ | |
child.ForceUpdateSize(); | |
} | |
if (element is ListView listView) | |
{ | |
throw new NotSupportedException($"{nameof(Expander)} is not yet supported inside {nameof(ListView)}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest keeping it, because ListView works much better on WinUI.
Description of Change
New Expander control.
Uses custom implementation on Android and iOS and native WinUI expander control.
Linked Issues
PR Checklist
approved
(bug) orChampioned
(feature/proposal)main
at time of PRAdditional information