NavigationLink从视图中的任何位置触发

时间:2019-11-07 05:44:29

标签: swift swiftui ios-navigationview

我正在尝试单击语音气泡图标来重新显示新视图。当前,新视图已正确触发,但是我可以单击PostView正文中的任意位置,然后触发NavigationLink。我无法仅在单击气泡图标时触发新视图。

除此之外,我无法使灰色箭头消失。

PostView

struct PostView: View {
    var post: Post
    @State var postComment: String
    @State var showPlaylistsView = false
    @State var action: String? = ""
    @EnvironmentObject var viewHandler: ViewHandler


    var body: some View {
        VStack {
            HStack {
                Text(post.songInfo.album).font(.title)
                Spacer()
                Text(post.songInfo.artist)
            }.padding()

            URLImage(url: post.songInfo.albumArtURL)
                .aspectRatio(contentMode: .fit)

            NavigationLink(destination: Text(self.post.songInfo.track), tag: post.id, selection: self.$action) {
                EmptyView()
            }

            HStack {
                Spacer()
                Image("comment-icon")
                    .onTapGesture {
                        self.action = self.post.id
                }
                Spacer()
            }


            HStack {
                Text(post.user.userName)
                Spacer()
            }.padding()

            HStack {
                Text(post.textContent)
                Spacer()
            }.padding()


        }
    }



}

PostsView

struct PostsView: View {
    @ObservedObject var fbVM = FirebasePosts()
    @State private var action: Int? = 0

    var body: some View {
        NavigationView {
            List {
                ForEach(fbVM.visiblePosts) { post in
                    PostView(post: post, postComment: "")
                }.listRowInsets(EdgeInsets())

            }
        }
    }
}

如上所述,灰色箭头仍然存在,单击帖子中的任意位置将触发NavigationLink。在下图中,您可以看到整个帖子以灰色突出显示。无论您在PostView中的何处单击,都会发生这种情况。

Example

0 个答案:

没有答案