I’ve a easy SwiftUI Listing, which shows LineItems.
The specified beaviour is:
- detect click on and doubleclick within the standing subject (on the vanguard) and the sphere (“2W”) within the trailing edge.
- click on anyplace else within the line selects the road
- double click on anyplace else within the line run an motion
with the code under, that works superb, besides:
on MacOS,
- that clicks on Textual content(“Infotext”) don’t choose the road (clicks to proper of Textual content(“Infotext”) nonetheless do)
- that doubleclicks to proper of Textual content(“Infotext”) don’t run the onTap Motion (doubleclicks on Textual content(“Infotext”) nonetheless do )
on iOS,
- that doubleclicks to proper of Textual content(“Infotext”) don’t run the onTap Motion (doubleclick on Textual content(“Infotext”) nonetheless do )
import SwiftUI
struct ContentView: View {
@State personal var seletion: Int?
var physique: some View {
Listing( 1...10, id: .self, choice: $seletion) { nr in
ItemLine()
.tag(nr)
}
.listStyle(PlainListStyle())
}
}
struct ItemLine: View {
@State var showDuePopover = false
@State var showStatusSheet = false
var physique: some View {
HStack (alignment: .high) {
//Standing
Picture(systemName: "rectangle")
.onTapGesture(rely: 2, carry out: {
print("standing doubeclicked")
})
.onTapGesture(rely: 1, carry out: {
print("standing singleclicked")
showStatusSheet = true
})
.sheet(isPresented: $showStatusSheet) {
TESTPopOver()
}
.padding(.trailing, 10)
Textual content("Infotext")
.lineLimit(2)
//.contentShape(Rectangle())
//.background(.grey)
Spacer()
BadgeView(textual content: "2W", minWidth: 14)
.onTapGesture(rely: 2, carry out: {
print("reusub 2 clicked")
})
.onTapGesture(rely: 1, carry out: {
print("reusub clicked")
showDuePopover = true
})
.popover(isPresented: $showDuePopover) {
TESTPopOver()
}
.contextMenu {
Button("4h"){}
Button("1T"){}
Button("2T"){}
Button("WE"){}
Button("subsequent week"){}
Button("subsequent 2 week"){}
}
//.background(.inexperienced)
//.contentShape(Rectangle())
} // Outer HStack
//.background(.yellow)
//.contentShape(Rectangle())
.onTapGesture(rely: 2) {
print("🍀🍀🍀🍀 Line doubleclicked")
} // finish of Double-Faucet-Gesture
} // finish of physique
}
struct TESTPopOver: View {
@Surroundings(.dismiss) var dismiss
var physique: some View {
VStack (alignment: HorizontalAlignment.main ){
Textual content("Popover")
Button("cancel") {
dismiss()
}
}
.padding(15)
}
}
struct BadgeView: View
{
var textual content: String
var minWidth: CGFloat = 60.0
var physique: some View
{ Textual content(textual content)
.body(minWidth: minWidth)
.lineLimit(2)
.padding([.horizontal],4.0)
.padding([.vertical],2.0)
.font(.footnote)
.background(.blue)
.cornerRadius(5.0)
.foregroundColor(.white)
}
}