How to perform an action after NavigationLink is tapped?

后端 未结 4 933
梦毁少年i
梦毁少年i 2020-12-10 14:29

I have a Plus button in my first view. Looks like a FAB button. I want to hide it after I tap some step wrapped in NavigationLink. So far I have something like this:

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-10 14:46

    Another alternative I have tried. Not using simultaneousGesture, but an onDisappear modifier instead. Code is simple and It works. One downside is that those actions happen with a slight delay. Because first the destination view slides in and after this the actions are performed. This is why I still prefer @Asperi's answer where he added .simultaneousGesture(LongPressGesture) to my code.

    ForEach(0 ..< 12) {item in
        NavigationLink(destination: TransactionsDetailsView()) {
            VStack {
                HStack(alignment: .top) {
                    Text("List item")
                }
                .padding(EdgeInsets(top: 5, leading: 10, bottom: 5, trailing: 10))
                .foregroundColor(.black)
                Divider()
            }
        }
        .onDisappear(){
            self.showPlusButton = false
        }
        .onAppear(){
            self.showPlusButton = true
        }
    }
    

提交回复
热议问题