1
votes

I have a layout that looks like this: Layout Drawing

There is a main view which is the Feed that would be my NavigationView and then I have views inside: PostList -> Post -> PostFooter and in the PostFooter A Button that would be my NavigationLink

struct Feed: View {
    var body: some View {
        NavigationView {
            PostList()
        }
    }
}

struct PostList: View {
    var body: some View {
        List {
            ForEach(....) {
                Post()
            }
        }
    }
}

struct Post: View {
    var body: some View {
        PostHeader()
        Image()
        PostFooter()
    }
}

struct PostFooter: View {
    var body: some View {
        NavigationLink(destination: Comment()) {
             Text("comments")
        }
    }
} 

But When when I tap on the comments, it goes to the Comment View then go back to Feed() then back to Comment() then back to Feed() and have weird behaviour.

Is there a better way to handle such a situation ?

Update

The Navigation is now working but the all Post component is Tapeable instead of just the Text in the PostFooter. Is there any way to disable tap gesture on the cell and add multiple NavigationLink in a cell that go to different pages ?

1
Would you provide working example to reproduce?Asperi
your code works perfectly fine for me. Are you sure there's nothing else you're missing here?Ishmeet
@Asperi I've updated the post the navigation bug was due to something else but now the problem is that the all cell trigger the navigation instead of just the Text in the PostFooterjscatigna

1 Answers

0
votes

How about programmatically active the NavigationLink, for example:

struct PostFooter: View {
    @State var commentActive: Bool = false
    var body: some View {
        VStack{
            Button("Comments") {
                commentActive = true
            }
            NavigationLink(destination: Comment(), isActive: $commentActive) {
                EmptyView()
            }
        }
    }
} 

Another benefit of above is, your NavigationLink destination View can accept @ObservedObject or @Binding for comments editing.