UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: (Day 94) Layout and Geometry Challenge 2

Forums > 100 Days of SwiftUI

Hi folks,

I'm having a hard time with challenge 2 of the layout and geometry project. It's where Paul wants us to go back to WordScramble and make the last words on the word list swipe in from the right.

I thought of using an .offset and connecting its value to the minY value of each HStack in the list. I tried to define a coordinate frame in the list, called ListFrame, to have the first row have a minY of 0, but I can't get that to work. I keep getting back results in the .global frame, which appears to be the default behaviour when a user defined frame cannot be found.

Can anyone figure out why this doesn't work? and a hint towards the solution would also be appreciated :). Full NavigationView below.

All the best

Joao

NavigationView {
            VStack {
                TextField("Enter your word", text: $newWord, onCommit: addNewWord)
                    .textFieldStyle(RoundedBorderTextFieldStyle())
                    .autocapitalization(.none)
                    .padding()

                List(usedWords, id: \.self) { word in
                    GeometryReader { geo in
                        HStack {
                            Group {
                                Image(systemName: "\(word.count).circle")
                                Text(word)
                                Text("minY ListFrame: \(geo.frame(in: .named("ListFrame")).minY)") //debug
                            }
                        }
                        .accessibilityElement(children: .ignore)
                        .accessibility(label: Text("\(word), \(word.count) letters"))
                    }
                }.coordinateSpace(name: "ListFrame")

                Text("Score: \(score) points")
                    .font(.headline)

            }
            .navigationBarTitle(rootWord)
            .onAppear(perform: startGame)
            .alert(isPresented: $showingError) {
                Alert(title: Text(errorTitle), message: Text(errorMessage), dismissButton: .default(Text("OK")))
            }
            .navigationBarItems(leading:
                Button(action: startGame) {
                    Text("Restart")
                }
            )

        }

3      

I added a coordinate space to the TextField above the list, then used the minY relative to that coordinate space to offset.

3      

crafty! it makes sense, thank you!

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.