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

Hello. We would really appreciate it if you let us know if you found a solution or a workaround to this issue. #3

Open
waelsaad opened this issue Jun 16, 2023 · 6 comments

Comments

@waelsaad
Copy link

waelsaad commented Jun 16, 2023

I can't belive I am asking the same question 2 years later but its causing a big problem within my application on iOS 16.

If anyone else in the future comes up with a solution to the issue Chrys described below, please kindly respond here or on the Stackoverflow question.

Thank you.

https://www.youtube.com/watch?v=z2pybl5yYqk
https://stackoverflow.com/questions/66523786/swiftui-putting-a-lazyvstack-or-lazyhstack-in-a-scrollview-causes-stuttering-a

@hugo53
Copy link

hugo53 commented Jul 1, 2023

@waelsaad @chrysb Did you guys find any solution for this? I'm also experiencing this issue and trying to resolve it.

@waelsaad
Copy link
Author

waelsaad commented Jul 5, 2023

@hugo53 no solution yet for me but I have to figure something out. I am creating an app and will be maintaining it for the far future so I hope someday this issue will be resolved. If I ever find something I will report it here and in the Stackoverflow question. I've reported this as a bug to Apple. Please let us know if you find a fully working workaround or a fix. Thank you.

@jb55
Copy link

jb55 commented Jan 12, 2024

Im leaning toward a limited sized VStack. It's the only way I can seem to get rid of jittering on my variable sized views.

The only downside is the initial load time and hang right when you begin scrolling, but after that it's buttery smooth. I'm trying to find a solution to this.

I will also probably need some kind of pagination that adds more views once I scroll near the bottom.

@djmango
Copy link

djmango commented Apr 19, 2024

Yeah this is a huge problem @apple. @jb55 pagination solution is what I'm implementing for now, it is super smooth perf-wise and sufficient UX-wise for now

@hugo53
Copy link

hugo53 commented Apr 20, 2024

@djmango Thank you for sharing the great information. Could you please share more how you did with pagination solution?

@djmango
Copy link

djmango commented Apr 20, 2024

@hugo53 here's an example of a basic implementation, i might make it an actual pagination rather than a boolean collapsed vs all view in the future but this works solid for now.

struct ExampleScrollView: View {
    @State private var showAll = false

    private var displayedItems: [Item] {
        if showAll {
            return GenericViewModel.shared.items
        } else {
            let suffix = GenericViewModel.shared.items.suffix(10)
            return Array(suffix)
        }
    }

    var body: some View {
        ScrollViewWithStickyHeader(
            header: {
                Rectangle().hidden()

                Button(
                    action: { showAll.toggle() }
                ) {
                    Text(showAll ? "Show last 10" : "Show all")
                }
                .visible(if: GenericViewModel.shared.items.count > 10)
                .keyboardShortcut("i", modifiers: [.command, .shift])
            },
            headerHeight: 200,
            headerMinHeight: 0,
            onScroll: handleOffset
        ) {
            VStack(alignment: .trailing, spacing: 5) {
                ForEach(displayedItems) { item in
                    ItemView(item: item)
                        .id(item.id)
                }
            }
        }
        .scrollContentBackground(.hidden)
        .scrollIndicators(.never)
        .defaultScrollAnchor(.bottom)
    }
}

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

4 participants