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

SmoothScrollIntoView ListView Extension #3222

Merged

Conversation

Vijay-Nirmal
Copy link
Contributor

@Vijay-Nirmal Vijay-Nirmal commented Apr 5, 2020

Fixes #1499

SmoothScrollIntoView extensions allow scrolling the item into the view with animation.

image

PR Type

What kind of change does this PR introduce?

  • Feature
  • Documentation content changes
  • Sample app changes

PR Checklist

Please check if your PR fulfills the following requirements:

@ghost
Copy link

ghost commented Apr 5, 2020

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 🙌

Copy link
Contributor

@vgromfeld vgromfeld left a 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 ?

/// <summary>
/// Aligned left
/// </summary>
Left,
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

Copy link
Member

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).

/// <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);
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vgromfeld comment?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor

@vgromfeld vgromfeld Sep 9, 2020

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.

@michael-hawker michael-hawker added this to the 6.1 milestone May 18, 2020
Copy link
Member

@michael-hawker michael-hawker left a 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?

/// <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);
Copy link
Member

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);
Copy link
Member

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;
Copy link
Member

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...?

@michael-hawker
Copy link
Member

@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!

@michael-hawker michael-hawker modified the milestones: 6.1, 7.0 May 29, 2020
@ghost ghost added the no-recent-activity 📉 Open Issues that require attention label Jun 13, 2020
@ghost
Copy link

ghost commented Jun 13, 2020

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.

@Vijay-Nirmal
Copy link
Contributor Author

I will work on this today

@ghost ghost removed the no-recent-activity 📉 Open Issues that require attention label Jun 13, 2020
@ghost
Copy link

ghost commented Jun 21, 2020

This PR has been marked as "needs attention 👋" and awaiting a response from the team.

@Vijay-Nirmal
Copy link
Contributor Author

I have updated my branch with latest change from the master. Currently facing an issue in the sample app.

@Rosuavio Rosuavio force-pushed the SmoothScrollIntoView branch from e38721d to 3d8fa7c Compare June 28, 2021 16:31
@Rosuavio
Copy link
Contributor

@Vijay-Nirmal @michael-hawker, I think this is almost over the line. Do we want split up the ItemPlacement directions?

@michael-hawker
Copy link
Member

@RosarioPulella I'm good with either choice, think we should rename it ScrollItemPlacement though?

Also for the sample, I meant adding a XamlRoot like the ImageCachePage. Then you remove all those textboxes and things from the .bind file and just reference them directly in the .xaml.cs file outside the OnXamlRendered method.

@Rosuavio Rosuavio force-pushed the SmoothScrollIntoView branch 2 times, most recently from 51bbb4b to e65181b Compare June 29, 2021 15:40
@Rosuavio
Copy link
Contributor

@RosarioPulella I'm good with either choice, think we should rename it ScrollItemPlacement though?

Renamed.

Also for the sample, I meant adding a XamlRoot like the ImageCachePage. Then you remove all those textboxes and things from the .bind file and just reference them directly in the .xaml.cs file outside the OnXamlRendered method.

Done.

@michael-hawker
Copy link
Member

Looks great! Few small comments:

  • Let's put "Smooth Scroll Settings" header above the properties
  • We should have the index be non-zero by default so that clicking the button does something first try
  • Put a right-margin on the settings so they align with the button bar below

image

@michael-hawker
Copy link
Member

@vgromfeld I know you looked at these before, did you want to take another quick look to review? Thanks!

@ghost
Copy link

ghost commented Jul 7, 2021

Hello @michael-hawker!

Because this pull request has the auto merge :zap: label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

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 (@msftbot) and give me an instruction to get started! Learn more here.

@michael-hawker michael-hawker added the next preview ✈️ Label for marking what we want to include in the next preview release for developers to try. label Jul 15, 2021
@michael-hawker michael-hawker merged commit 1abf8f8 into CommunityToolkit:main Jul 15, 2021
@Rosuavio Rosuavio removed their assignment Sep 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New ListViewBase extensions - SmoothScrollIntoView
6 participants