1

I am running Xcode 11 GM2 and having issues with a NavigationLink not triggering where it is expected. The app I am working on is based on Apple's sample SwiftUI app found here. The problem I am having also happens in Apple's sample.

When I add the NavigationLink to the photos:

 NavigationLink(destination: PhotoDetail(photo: photo)) {

    PhotoItem(photo: photo)
       .frame(width: 300)
       .padding(.trailing, 30)

 }

The link is not accessible when you click on the image and the other content within the PhotoItem. But if you move up a bit and touch/click just below the Category name above the image, it not only triggers the link to the destination, it triggers it for all five of the items inside the scroll view.

enter image description here

Here is the full code from the Home page and the PhotoRow:

Home

struct HomeView: View {

    // Create a categories dictionary
    var categories: [String:[Photo]] {
        .init(
            grouping: photoData,
            by: { $0.category.rawValue }
        )
    }

    var body: some View {
        NavigationView {
            List(categories.keys.sorted(), id: \String.self) { key in
                    PhotoRow(categoryName: "\(key)".uppercased(),
                             photos: self.categories[key]!)
                        .frame(height: 320)
                        .padding(.top)
            }
        .navigationBarTitle(Text("Portfolio"))
        }
    }
}

PhotoRow

struct PhotoRow: View {
    var categoryName: String
    var photos: [Photo]

    var body: some View {
        VStack(alignment: .leading){
            Text(self.categoryName)
                .font(.title)


            ScrollView(.horizontal, showsIndicators: false) {
                HStack(alignment: .top) {
                    ForEach (self.photos) { photo in

                        // add navigation to detail view:
                        NavigationLink(destination: PhotoDetail(photo: photo)) {

                            PhotoItem(photo: photo)
                                .frame(width: 300)
                                .padding(.trailing, 30)

                        }
                    }
                }
            }
        }
    }
}

Any help resolving this would be appreciated.

Fabian
  • 5,040
  • 2
  • 23
  • 35
forrest
  • 10,570
  • 25
  • 70
  • 132

0 Answers0