Handle single click and double click while updating the view
You can use a custom click handler like this:
class TapState {
static var taps: [String: Date] = [:]
static func isDoubleTap<Content: View>(for view: Content) -> Bool {
let key = "\(view)"
let date = taps[key]
taps[key] = Date()
if let date = date, date.timeIntervalSince1970 >= Date().timeIntervalSince1970 - 0.4 {
return true
} else {
return false
}
}
}
extension View {
public func onTapGesture(firstTap: @escaping () -> Void, secondTap: @escaping () -> Void) -> some View {
onTapGesture(count: 1) {
if TapState.isDoubleTap(for: self) {
secondTap()
} else {
firstTap()
}
}
}
}
And implement it like this:
struct MyView: View {
@State var isSelected: Bool = false
@State var isShowingDetail: Bool = false
var body: some View {
Text("Text")
.background(isSelected ? Color.green : Color.blue)
.onTapGesture(firstTap: {
isSelected = true
}, secondTap: {
isShowingDetail = true
})
.sheet(isPresented: $isShowingDetail) {
Text("Detail")
}
}
}
Swift Package
I've also created a small package you can use: https://github.com/lukaswuerzburger/DoubleTap
How to handle single click and double click on the same html DOM element using typescript:Angular 2 or 4?
You can use a timeout and a boolean flag to solve this.
Consider the following:
The DOM takes a few milliseconds to recognize the double click.
But it's damn sure that it recognize the double click but the first click is also recognized.
So the logic goes like this.
isSingleClick: Boolean = true;
method1CallForClick(){
this.isSingleClick = true;
setTimeout(()=>{
if(this.isSingleClick){
doTheStuffHere();
}
},250)
}
method2CallForDblClick(){
this.isSingleClick = false;
doTheStuffDblClickHere();
}
Call the method one in the click event of the element and method 2 in the click event of the element.
SwiftUI on macOS - handle single-click and double-click at the same time
Here is possible approach (tested with Xcode 11.2 / macOS 10.15)
struct MyView: View {
var body: some View {
Rectangle()
.fill(Color.blue)
.frame(width: 200, height: 200)
.gesture(TapGesture(count: 2).onEnded {
print("double clicked")
})
.simultaneousGesture(TapGesture().onEnded {
print("single clicked")
})
}
}
Is it possible to suppress single-click events during a double-click?
Start a timer when you get WM_LBUTTONDOWN
(or Qt equivalent). If you get WM_LBUTTONDBLCLK
(or Qt equivalent) before the timer expires, cancel the timer and execute your double-click action. Otherwise, when the timer expires, execute your single-click event.
On Windows, you can get the double-click time using GetDoubleClickTime()
.
That's about the best you can do - you can't prevent the single click message being generated in the first place on either platform.
vue.js: how to handle click and dblclick events on same element
As suggested in comments, You can simulate the dblclick event by setting up a timer for a certain period of time(say x).
- If we do not get another click during that time span, go for the single_click_function().
- If we do get one, call double_click_function().
- Timer will be cleared once the second click is received.
- It will also be cleared once x milliseconds are lapsed.
See below code and working fiddle.
new Vue({
el: '#app',
data: {
result: [],
delay: 700,
clicks: 0,
timer: null
},
mounted: function() {
console.log('mounted');
},
methods: {
oneClick(event) {
this.clicks++;
if (this.clicks === 1) {
this.timer = setTimeout( () => {
this.result.push(event.type);
this.clicks = 0
}, this.delay);
} else {
clearTimeout(this.timer);
this.result.push('dblclick');
this.clicks = 0;
}
}
}
});
gtk tree view. Handle both single and double click
You can try to use parent signals, in this case GtkWidget's signal "button-press-event", with the event of GDK_BUTTON_PRESS doing something and GDK_2BUTTON_PRESS doing other.
Little note: you have grab the GtkTreeViewSelection on which row you need.
Related Topics
Can Openssl Be Bundled for Wget Wrapper App to Reference in Xcode Project
Why Does Classa Adopting Protocolb Not Satisfy the Protocolb Requirement
Nsurl Fail Able Initialiser Initwithstring: Does Not Return Nil on Empty String in Swift
Swift Why Isn't My Date Object That's (Equatable) Equal After Converting It to a String and Back
Change Mkmarkerannotationview Size
Swift: Nil Error When Using Self.Moc.Save() to Save in Core Data
Swift: Call Self Method Inside Init
Deleterowsatindexpaths Crashing
Nsurl from String Gets Truncated, Dots on the Uivideoeditorcontroller's Video Path Swift 2 iOS 8
How to Have Either or Wherefields for Firestore Query
C++ Dylib in Swift Project - Undefined Symbols for Function Exposed in Dylib
Use Huge Numbers in Apple Swift
Swiftui How to Programatically Adjust Spacing Between Images and Text
How to Loop All Firebase Children at Once in the Same Loop
Autoscrolling Infinite Effect in .Linear Type of Icarousel in Swift
Get Element from Array of Dictionaries According to Key
Getting Data Out of Completionhandler in Swift in Nsurlconnection