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

HStack alignment #5

Closed
andredewaard opened this issue Jan 5, 2022 · 2 comments
Closed

HStack alignment #5

andredewaard opened this issue Jan 5, 2022 · 2 comments

Comments

@andredewaard
Copy link

Is there a way to align all the items to the top.
Normally HStack alignment is used to align the items inside to the desired position.
For HStackSnap it is used for where it should snap.

I'm trying to recreate what you have in example 2 but with 3 items above each other. My search result doesn't always give me a multiple of 3 since sometimes there are only 8 results. when this happens the last 2 are aligned in the middle

@andredewaard
Copy link
Author

andredewaard commented Jan 5, 2022

Fixed this with GeometryReader and adding a frame to the VStack that has the height of the geometryReader

GeometryReader { reader in
    HStackSnap(alignment: .leading(16)) {
        ForEach(0..<chunkedUsers.count) { index in
            VStack(alignment: .leading) {
                ForEach(chunkedUsers[index]) { user in
                    UserRow(user: user)
                        .frame(width: 300, alignment: .leading)
                        .background(NavigationLink(destination: UserView(user: user), tag: user.id, selection: $activeUser) {
                            EmptyView()
                        })
                        .snapAlignmentHelper(id: user.id)
                        .onTapGesture {
                            activeUser = user.id
                        }
                }
            }
            .frame(height: reader.size.height, alignment: .top)
        }
    }
}

@trentguillory
Copy link
Member

Thanks for sharing your solution!

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