-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
SmoothScrollIntoView ListView Extension #3222
SmoothScrollIntoView ListView Extension #3222
Conversation
Thanks Vijay-Nirmal for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌 |
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 a great extension but it seems to be a lot of code.
Can you explain more the logic and why all of this is needed ?
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListViewExtensions/ListViewExtensionsPage.xaml.cs
Outdated
Show resolved
Hide resolved
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListViewExtensions/ListViewExtensionsPage.xaml.cs
Outdated
Show resolved
Hide resolved
Microsoft.Toolkit.Uwp.UI/Extensions/ListViewBase/ItemPlacement.cs
Outdated
Show resolved
Hide resolved
/// <summary> | ||
/// Aligned left | ||
/// </summary> | ||
Left, |
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.
ListView
and GridView
are usually scrolling only in one direction. What do you think of having only Start
, Center
End
values in the enum ?
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.
Yes, but GridView
supports scrolling on both axes at the same time. So, in my opinion, we need to support it.
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.
Would we want to make them independent so they can be combined if needed? Fine leaving this as is too, though we may want to name it ScrollItemPlacement
as it's specific to the scroll helper vs. a general ItemPlacement (as it's in the UI namespace which could be broad).
Microsoft.Toolkit.Uwp.UI/Extensions/ListViewBase/SmoothScrollIntoView.cs
Outdated
Show resolved
Hide resolved
Microsoft.Toolkit.Uwp.UI/Extensions/ListViewBase/SmoothScrollIntoView.cs
Outdated
Show resolved
Hide resolved
Microsoft.Toolkit.Uwp.UI/Extensions/ListViewBase/SmoothScrollIntoView.cs
Outdated
Show resolved
Hide resolved
/// <returns>Note: Even though this return <see cref="Task"/>, it will not wait until the scrolling completes</returns> | ||
public static async Task SmoothScrollIntoViewWithItem(this ListViewBase listViewBase, object item, ItemPlacement itemPlacement = ItemPlacement.Default, bool disableAnimation = false, bool scrollIfVisibile = true, int additionalHorizontalOffset = 0, int additionalVerticalOffset = 0) | ||
{ | ||
await SmoothScrollIntoViewWithIndex(listViewBase, listViewBase.Items.IndexOf(item), itemPlacement, disableAnimation, scrollIfVisibile, additionalHorizontalOffset, additionalVerticalOffset); |
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.
Is it working for grouped collections ?
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.
It will work but header will hide the element if the item is aligned to the top. I need to think of a solution.
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.
@Vijay-Nirmal do you think fixing that scenario is required before we add the feature?
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.
@michael-hawker Your call.... I tried a little bit, I can't figure out a way. I need to look into it more.
/// <returns>Note: Even though this return <see cref="Task"/>, it will not wait until the scrolling completes</returns> | ||
public static async Task SmoothScrollIntoViewWithItem(this ListViewBase listViewBase, object item, ItemPlacement itemPlacement = ItemPlacement.Default, bool disableAnimation = false, bool scrollIfVisibile = true, int additionalHorizontalOffset = 0, int additionalVerticalOffset = 0) | ||
{ | ||
await SmoothScrollIntoViewWithIndex(listViewBase, listViewBase.Items.IndexOf(item), itemPlacement, disableAnimation, scrollIfVisibile, additionalHorizontalOffset, additionalVerticalOffset); |
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.
You can directly return the inner task here. You don't need to let the compiler generate the async/await state machine.
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.
Really? I heard it a bad practice like call stack won't be proper etc...
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.
@vgromfeld comment?
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 can't find a solution :( it would be nice if I can see how ScrollViewer is working.
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.
@vgromfeld you're just saying to make a direct return here? Can you confirm and maybe just make the code suggestion?
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.
The suggestion is to remove the async/await keywords.:
public static Task SmoothScrollIntoViewWithItem(this ListViewBase listViewBase, object item, ItemPlacement itemPlacement = ItemPlacement.Default, bool disableAnimation = false, bool scrollIfVisibile = true, int additionalHorizontalOffset = 0, int additionalVerticalOffset = 0)
{
return SmoothScrollIntoViewWithIndex(listViewBase, listViewBase.Items.IndexOf(item), itemPlacement, disableAnimation, scrollIfVisibile, additionalHorizontalOffset, additionalVerticalOffset);
}
It saves some size on the final binary because the compiler does not have the generate the state machine behind the async/await keywords.
It is not always recommended to do this because if the called method is throwing, you will not see all the methods in the exception stack. Here, it means that if SmoothScrollIntoViewWithIndex
throws, its exception will not contains any information about the fact that it has been called by SmoothScrollIntoViewWithItem
.
Microsoft.Toolkit.Uwp.UI/Extensions/ListViewBase/SmoothScrollIntoView.cs
Outdated
Show resolved
Hide resolved
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.
@Vijay-Nirmal there appears to be a merge conflict now, and I can't seem to build it as-is with the latest VS I have. Can you update the PR to the latest master?
Microsoft.Toolkit.Uwp.UI/Extensions/ListViewBase/SmoothScrollIntoView.cs
Outdated
Show resolved
Hide resolved
/// <returns>Note: Even though this return <see cref="Task"/>, it will not wait until the scrolling completes</returns> | ||
public static async Task SmoothScrollIntoViewWithItem(this ListViewBase listViewBase, object item, ItemPlacement itemPlacement = ItemPlacement.Default, bool disableAnimation = false, bool scrollIfVisibile = true, int additionalHorizontalOffset = 0, int additionalVerticalOffset = 0) | ||
{ | ||
await SmoothScrollIntoViewWithIndex(listViewBase, listViewBase.Items.IndexOf(item), itemPlacement, disableAnimation, scrollIfVisibile, additionalHorizontalOffset, additionalVerticalOffset); |
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.
@Vijay-Nirmal do you think fixing that scenario is required before we add the feature?
/// <returns>Note: Even though this return <see cref="Task"/>, it will not wait until the scrolling completes</returns> | ||
public static async Task SmoothScrollIntoViewWithItem(this ListViewBase listViewBase, object item, ItemPlacement itemPlacement = ItemPlacement.Default, bool disableAnimation = false, bool scrollIfVisibile = true, int additionalHorizontalOffset = 0, int additionalVerticalOffset = 0) | ||
{ | ||
await SmoothScrollIntoViewWithIndex(listViewBase, listViewBase.Items.IndexOf(item), itemPlacement, disableAnimation, scrollIfVisibile, additionalHorizontalOffset, additionalVerticalOffset); |
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.
@vgromfeld comment?
{ | ||
var sampleListView = control.FindChildByName("SampleListView") as ListView; | ||
sampleListView = control.FindChildByName("SampleListView") as 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.
Wish I could have built and seen this, trying to think if there's a better way we can show this sample. It almost seems as if we want a static page vs. using the property panel...?
@Vijay-Nirmal let's brainstorm with some folks about finding a solution to your remaining open issue and move this to the 7.0 milestone. In the meantime, can you update the PR to merge in from master and have it be current again? Thanks! |
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 15 days. It will be closed if no further activity occurs within 30 days of this comment. |
I will work on this today |
This PR has been marked as "needs attention 👋" and awaiting a response from the team. |
d5a7dad
to
3884163
Compare
3884163
to
4aca259
Compare
I have updated my branch with latest change from the master. Currently facing an issue in the sample app. |
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListViewExtensions/ListViewExtensionsPage.xaml.cs
Show resolved
Hide resolved
e38721d
to
3d8fa7c
Compare
@Vijay-Nirmal @michael-hawker, I think this is almost over the line. Do we want split up the |
@RosarioPulella I'm good with either choice, think we should rename it Also for the sample, I meant adding a |
51bbb4b
to
e65181b
Compare
Renamed.
Done. |
@vgromfeld I know you looked at these before, did you want to take another quick look to review? Thanks! |
bfd26b1
to
c6212fc
Compare
Hello @michael-hawker! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Fixes #1499
SmoothScrollIntoView extensions allow scrolling the item into the view with animation.
PR Type
What kind of change does this PR introduce?
PR Checklist
Please check if your PR fulfills the following requirements: