WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

double clicking a NavigationLink opens another view window

Forums > SwiftUI

Writing a Macos app. The following code just puts up a simple navigation list. everthing is fine with single clicking the Row links and displaying the Detail row If you double click the NavigationLink, another window opens with only the Text view on it. During my testing, there was a button to dismiss the view on the detail window, and if clicked, the original window would close leaving this stripped down view open.

I have to assume that no one else is seeing this since I cannot see anything from other people. Does anyone have any ideas what would cause this to happen?

import SwiftUI

struct ContentView: View {

    var body: some View {
        HStack {
            NavigationView {
                List(0..<100) { row in
                    NavigationLink(destination: Text("Detail \(row)")) {
                        Text("Row \(row)")
                    }
                }
            }
        }
    }
}

@guci0 I put in the sizes and got the same results. Since you are seeing the little window, you are experiencing the same issue

@TheTwoNotes I put in the following with the same results. 1) with both gestures, only the single displays the print, the double click gives me the extra window opening as before. 2) with only the count: 2 in , on a double click I get the same extra window opening with the Text Row displayed...not what should happen

                .onTapGesture(count: 1) {
                    print("tapped single \(row)")
                }
                .onTapGesture(count: 2) {
                    print("tapped double \(row)")
                }

1      

Hey, I tried this and not seeing any issue. Here is the code I ran locally:

import SwiftUI

struct ContentView: View {
   var body: some View {
      VStack {
         NavigationView {
            List(0..<100) { row in
               NavigationLink(destination: Text("Detail \(row)")) {
                  Text("Row \(row)")
                     .padding()
               }
            }
         }
      }
   }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Maybe you could try something with adding gestures for single and double tap, on single, open the view, on double, do nothing.

1      

@guci0  

@rbquick I tested – your destination view is so small just resize. This is my first post 🎉

NavigationLink(destination: Text("Detail \(row)").frame(width: 300, height: 300)) {

1      

Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

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.