简体   繁体   English

SwiftUI 列出不传播的触摸

[英]SwiftUI List not propagating touches

Trying to work with SwiftUI and experiencing a weird issue.尝试使用 SwiftUI 并遇到一个奇怪的问题。 I have a List of Views that should be clickable to push to a detail view, swipable to delete, and have a couple of interactive elements in the view.我有一个视图列表,应该可以单击以推送到详细视图,可滑动以删除,并且视图中有几个交互式元素。 The list is more or less set up as follows:该列表或多或少设置如下:

NavigationView {
            ZStack(alignment: .top) {
                if viewModel.value != nil {
                    List {
                        ForEach(viewModel.value!, id: \.address) { model in
                            VStack {
                                NavigationLink(destination: AliasDetailView(alias: model) { msg in
                                        self.toastText = msg
                                        self.showCopiedToast = true
                                    }) {
                                    ModelRow(alias: alias) { msg in
                                        self.toastText = msg
                                        self.showCopiedToast = true
                                    }
                                }
                            }
                        }
                        .onDelete(perform: self.deleteModel)
                    }
                    .listStyle(PlainListStyle())
                    .alert(isPresented: $showDefaultAlert) {
                        Alert(title: Text("Default Address"),
                              message: Text("Would you like to set this as your default address?"),
                              primaryButton: .default(Text("Yes")) {
                                NSUbiquitousKeyValueStore.default.set(self.targetAddress, forKey: SettingsKeys.DefaultAddress)
                                NSUbiquitousKeyValueStore.default.synchronize()
                                print("Stored key")
                                self.targetAddress = ""
                              }, secondaryButton: .cancel({
                                NSUbiquitousKeyValueStore.default.set("NONE", forKey: SettingsKeys.DefaultAddress)
                                NSUbiquitousKeyValueStore.default.synchronize()
                                self.targetAddress = ""
                              }))
                    }
                } else {
                    Text("Loading...")
                }
                
                VStack {
                    Spacer()
                        .alert(isPresented: $showInvalidAddressAlert) {
                            Alert(title: Text("Invalid Email"), message: Text("Please enter a valid address."), dismissButton: .default(Text("Ok")))
                        }
                    
                    // Begin Floating action button
                    HStack {
                        Spacer()
                        Button(action: {
                            addModelAction()
                        }, label: {
                            Text("+")
                                .font(.largeTitle)
                                .frame(width: 77, height: 70)
                                .foregroundColor(.white)
                                .padding(.bottom, 7)
                        })
                        .background(Color.blue)
                        .cornerRadius(38.5)
                        .padding()
                        .shadow(color: Color.black.opacity(0.3),
                                radius: 3, x: 3, y: 3)
                        .alert(isPresented: $showAccountLimitAlert) {
                            Alert(title: Text("Account Limit Reached"), message: Text("You are currently at your account limit for models. Upgrade your account to create more."), dismissButton: .default(Text("Ok")))
                        }
                    }
                }
            }
            .navigationBarTitle("Models")
            .navigationBarItems(trailing:
                Button(action: {
                    self.showSettingsModal = true
                }) {
                    Image(systemName: "gearshape")
                        .font(.title)
                }
            )
            .addPartialSheet(style: PartialSheetStyle(
                                backgroundColor: .black,
                                handlerBarColor: .secondary,
                                enableCover: true,
                                coverColor: Color.black.opacity(0.6),
                                blurEffectStyle: .dark))
            .popup(isPresented: $showCopiedToast, type: .toast, position: .bottom, autohideIn: 2) {
                HStack {
                    Text(self.toastText)
                }
                .frame(width: 200, height: 60)
                .background(Color(red: 0.85, green: 0.8, blue: 0.95))
                .cornerRadius(30.0)
                .padding(15)
            }
            .sheet(isPresented: $showSettingsModal) {
                SettingsView()
                    .environmentObject(ProductsStore.shared)
            }

I've included everything in the body because I have a suspicion its related to something else blocking the touches.我已将所有内容都包含在身体中,因为我怀疑它与阻止触摸的其他东西有关。 I've tried removing some things but can't seem to identify it.我试过删除一些东西,但似乎无法识别它。 Here is the view code for the row:这是该行的视图代码:

HStack {
            VStack(alignment: .leading) {
                HStack {
                    VStack(alignment: .leading) {
                        Text(model.address)
                            .font(.headline)
                            .lineLimit(1)
                            .truncationMode(.tail)
                        Text("➜ \(model.target)")
                            .font(.subheadline)
                            .foregroundColor(.secondary)
                    }
                    Spacer()
                    VStack {
                        Image(systemName: "doc.on.doc")
                            .frame(width: 35, height: 38)
                            .font(.headline)
                            .foregroundColor(.accentColor)
                            .onTapGesture {
                                copyAlias()
                            }
                    }
                }
                HStack {
                    Text("Received: \(model.received)")
                    Spacer()
                    Toggle("", isOn: $isActive)
                        .labelsHidden()
                        .onReceive([self.isActive].publisher.first()) { value in
                            if value != prevActive {
                                toggleModel()
                            }
                        }
                }
            }
        }

Also note: The list view does work if you hold the elements.另请注意:如果您持有元素,列表视图确实有效。 ie Tapping a row will not trigger the navigation link but holding the cell will eventually trigger it.即点击一行不会触发导航链接,但按住单元格最终会触发它。

Turns out it was the Toast Library I was using.原来它是我使用的Toast 库 Likely however their view modifier works its capturing touches.然而,他们的视图修饰符可能会发挥其捕捉作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM