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

Expandable-text-with-line-limit example bug #5

Open
mobileuidev opened this issue Jan 31, 2023 · 2 comments
Open

Expandable-text-with-line-limit example bug #5

mobileuidev opened this issue Jan 31, 2023 · 2 comments

Comments

@mobileuidev
Copy link

mobileuidev commented Jan 31, 2023

When I try to use viewThatFits as described in the Expandable-text-with-line-limit.swift example but with a LazyVStack shows the button incorrectly when scrolling up and down, copy and paste the following code to try it out:

struct ContentView: View {
    
    var items = ["this is test text",
                 
                 "this is test text this is test text",
                 
                 " this is test text this is test text this is test text",
                 
                 "this is test text this is test text this is test text this is test text",
                 
                 "this is test text this is test text this is test text this is test text this is test text",
                 
                 "this is test text this is test text this is test text this is test text this is test text this is test text",
                 
                 "this is a small text",
                 
                 "this is test text this is test text this is test text this is test text this is test text this is test text this is test text this is test text",
                 
                 "this is test text this is test text this is test text this is test text this is test text this is test text this is test text this is test text this is test text",
                 
                 "this is test text this is test text this is test text this is test text this is test text this is test text this is test text this is test text this is test text this is test text",
                 
                 "this is test text this is test text this is test text this is test text this is test text this is test text this is test text this is test text this is test text this is test text this is test text",
    ]
    
    var body: some View {
        ScrollView {
            LazyVStack(spacing: 0) {
                ForEach(items, id: \.self) { item in
                   ExpandableTextWithLineLimit(text: item, initialLineLimit: 2)
                        .padding()
                }
            }
        }
       
    }
}

However, this issue doesn't happen with a VStack, but I need to use LazyVStack to simulate async data rendering.

@nataliapanferova
Copy link
Member

@mobileuidev might be something to do with how the size of text is calculated when it appears on screen in a LazyVStack, I'll add a note to my article mentioning that.

I'll let you know if I come up with a different solution, in the meantime you might need to set the initial height on the view, like in the example from Expandable-text-with-constrained-height.swift.

@mobileuidev
Copy link
Author

@nataliapanferova someone on SO added an answer to my question, I guess it's an acceptable solution for this issue.

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

2 participants