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

ItemsRepeater in ScrollViewer - scroll resets to 0 on app lags when scrolling #10

Open
Mikolaytis opened this issue Feb 13, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@Mikolaytis
Copy link

Mikolaytis commented Feb 13, 2022

Describe the bug
Your app slightly lags and you have an ItemsRepeater in a ScrollViewer. When you start scrolling down - there is a big chance of scroll resetting to 0 position.

To Reproduce
Steps to reproduce the behavior:

Sorry for not providing an example project with a repro - it's a lot of time to emulate this conditions.

  1. Launch lunacy 8.1 https://docs.icons8.com/release-notes/#81
  2. Unzip and open attached file in Lunacy 081221 scroll tree.sketch.zip
  3. rename two elements
  4. scroll down
  5. repeat from step 3

Expected behavior
Scroll do not resets to 0 position.

Screenshots
We've attached a video

Desktop (please complete the following information):

  • We have repro on any desktop platform

Additional context
I've debugged deep. The bug is based on two behaviors:

  1. ItemsRepeater recycles elements by setting them position of another element, or -10k position if there is nothing to recycle.
  2. ScrollContentPresenter saves the link to the anchor element and calculates everything from it. see TrackAnchor local method.
  3. There is a chance that anchor element gets recycled by ItemsRepeater
  4. Position of element jumps to other elements position or -10k if hidden, so offset of ScrollViewer tries to set equally in invalid or even negative area.
  5. Coerce logic resets negative value to zero offset on negative value. Or scroll just jumps to other position.

So to fix this I think ScrollContentPresenter should check for anchor getting recycled.

I've temporarily fixed this by a hack in our app: If scroll is resets to zero without any point - I'm restoring old offset.

@Mikolaytis Mikolaytis added the bug Something isn't working label Feb 13, 2022
@Mikolaytis
Copy link
Author

I think this will not be fixed shortly. So I will publish my fix if anyone will get the same issue:

    private void OnScrollChanged(object? sender, ScrollChangedEventArgs e)
    {
        if (sender is not ScrollViewer sv)
        {
            return;
        }
        if (!_skipScrollResetFixHack &&
            Math.Abs(sv.Offset.Y - _correctOffset.Y) > 200)
        {
            Logger.Log("Layers scroll lag fixed from " + sv.Offset + " to " + _correctOffset + ".");
            sv.Offset = _correctOffset;
        }
        
        _correctOffset = sv.Offset;
    }

@maxkatz6 maxkatz6 transferred this issue from AvaloniaUI/Avalonia Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant