Trying to work with SwiftUI and experiencing a weird issue. 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. i.e. Tapping a row will not trigger the navigation link but holding the cell will eventually trigger it.