diniska / swiftui-wrapping-stack

A SwiftUI Views for wrapping HStack elements into multiple lines
MIT License
84 stars 20 forks source link

Strange behaviour after WrappingStack out of screen #6

Open skywalkerlw opened 3 years ago

skywalkerlw commented 3 years ago

See attached video.

https://user-images.githubusercontent.com/2090084/127798187-fb63ef7f-f967-47ff-8a00-394df584235e.mp4

By the way, I'm using the latest version on iOS 14 (Xcode 12.5)

diniska commented 3 years ago

Thanks for sharing this issue. I'll check what happens here in the next couple of days

skywalkerlw commented 2 years ago

any potential update? Thanks

diniska commented 2 years ago

@skywalkerlw it seems that there could be lots of the rows here and you are using List view. Is that about right?

diniska commented 2 years ago

Here is the code that reproduces the issue:

import SwiftUI
import WrappingStack

private struct Item {
    var title: String
    var subtitle: String
    var content: [String]
}

struct ContentView: View {
    private let items = (0 ..< 100).map { index in
        Item(
            title: "\(index): \(Int.random(in: 100_000 ... 200_000))",
            subtitle: String(Int.random(in: 100_000 ... 200_000)),
            content: (0 ..< Int.random(in: 2 ..< 10)).map { _ in
                String(Int.random(in: 100_000 ... 200_000))
            }
        )
    }

    var body: some View {
        List(Array(items.enumerated()), id: \.offset) { i in
            VStack {
                Text(i.element.title).font(.headline)
                Text(i.element.subtitle).font(.body)
                WrappingHStack(id: \.self) {
                    ForEach(i.element.content, id: \.self) {
                        Text($0)
                            .padding()
                            .background(Color.gray.opacity(0.5))
                    }
                }
            }
            .padding()
            .cornerRadius(8)
            .background(Color.white)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
skywalkerlw commented 2 years ago

@skywalkerlw it seems that there could be lots of the rows here and you are using List view. Is that about right?

I'm using ScrollView + LazyVStack, and yes, it comes lots of list items