簡體   English   中英

SwiftUI 列出不傳播的觸摸

[英]SwiftUI List not propagating touches

嘗試使用 SwiftUI 並遇到一個奇怪的問題。 我有一個視圖列表,應該可以單擊以推送到詳細視圖,可滑動以刪除,並且視圖中有幾個交互式元素。 該列表或多或少設置如下:

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)
            }

我已將所有內容都包含在身體中,因為我懷疑它與阻止觸摸的其他東西有關。 我試過刪除一些東西,但似乎無法識別它。 這是該行的視圖代碼:

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()
                            }
                        }
                }
            }
        }

另請注意:如果您持有元素,列表視圖確實有效。 即點擊一行不會觸發導航鏈接,但按住單元格最終會觸發它。

原來它是我使用的Toast 庫 然而,他們的視圖修飾符可能會發揮其捕捉作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM