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

Selected item wrong width on initial load #5

Closed
barenddev opened this issue Mar 7, 2024 · 3 comments · Fixed by #7
Closed

Selected item wrong width on initial load #5

barenddev opened this issue Mar 7, 2024 · 3 comments · Fixed by #7
Labels
bug Something isn't working

Comments

@barenddev
Copy link

barenddev commented Mar 7, 2024

When the view is initially loaded, the width calculation for the text is incorrect, which causes the underline to be squished. In my case, initial width printed out at around 30 pixels, but after you switch index and back it does get the correct width of around 100. Any ideas on how to resolve this?

let titles = ["Full Balance", "Other Amount"]

SegmentedPicker(
                    titles,
                    selectedIndex: Binding(
                        get: { selectedIndex },
                        set: { selectedIndex = $0 }),
                    selectionAlignment: .bottom,
                    content: { item, isSelected in
                        Text(item)
                            .foregroundColor(isSelected ? .black : .gray )
                            .padding(.horizontal, 16)
                            .padding(.vertical, 8)
                    },
                    selection: {
                        VStack(spacing: 0) {
                            Spacer()
                            Color.black.frame(height: 1)
                        }
                    })
                    ```
@KazaiMazai
Copy link
Owner

@barenddev I've made an improvement should fix the issue that you faced.
Lemme know if it worked for you.

@barenddev
Copy link
Author

@KazaiMazai I tested your changes and can confirm it resolves the sizing problem on initialization for me. Thanks for looking into this!

@KazaiMazai
Copy link
Owner

@KazaiMazai I tested your changes and can confirm it resolves the sizing problem on initialization for me. Thanks for looking into this!

Awesome, thank you!

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

Successfully merging a pull request may close this issue.

2 participants