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

Scrolling too fast with scroll bar results in console error #19

Open
mywristbands opened this issue Jul 28, 2022 · 3 comments
Open

Scrolling too fast with scroll bar results in console error #19

mywristbands opened this issue Jul 28, 2022 · 3 comments

Comments

@mywristbands
Copy link

I started using this package a couple days ago, and it's pretty nice! However, I've encountered one issue.

When I scroll normally by swiping my figure up and down, everything works fine. And when I scroll by holding down on the scroll bar and moving my figure up and down, this also works fine as long as I scroll slowly.

However, if I hold on the scroll bar and move my figure up and down quickly, it results in many error messages in the console of the form Bound preference PositionPreferenceKey tried to update multiple times per frame.

Based on this SO answer, the error message is probably due to how the GeometryReader and PositionPreferenceKey interact with each other. But I'm not sure exactly how to fix it.

@mywristbands mywristbands changed the title Scrolling two fast with scroll bar results in console error Scrolling too fast with scroll bar results in console error Jul 28, 2022
@gordan-glavas-codecons
Copy link
Collaborator

I can't repro this on my phone/Xcode (can't see the warnings no matter what I do). If you wrap the onPreferenceChange body (starts at line 131) into a DispatchQueue.main.async { }, do the warnings go away?

@mywristbands
Copy link
Author

Thanks so much for looking into this @gordan-glavas-codecons. Unfortunately the DispatchQueue.main.async { } tip didn't help.

It took me awhile, but I did finally manage to create some sample code to help you reproduce the error. Here it is:

import SwiftUI

@main
struct RefreshableScrollViewApp: App {
  var body: some Scene {
    WindowGroup {
      TestingView()
    }
  }
}

struct TestingView: View {
  var body: some View {
    RefreshableScrollView(
      onRefresh: { done in DispatchQueue.main.asyncAfter(deadline: .now() + 3) { done() } },
      content: {
        LazyVStack {
          ForEach(0..<80) { _ in
            Menu {
              Button("Delete", role: .destructive) {}
            } label: {
              Text(Image(systemName: "ellipsis"))
            }
          }
        }
      }
    )
  }
}

To trigger the error, refresh the scroll view, and then rapidly drag the scroll bar in long strokes up and down. You should see a bunch of instances of Bound preference PositionPreferenceKey tried to update multiple times per frame appear in the console as you scroll.

@GioPalusa
Copy link

I too have this problem, but haven't found a solution yet...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants