Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 85d2b2a

Browse files
committed
longpressup support
1 parent cde853f commit 85d2b2a

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Runtime/gestures/long_press.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,16 @@ public LongPressGestureRecognizer(object debugOwner = null, PointerDeviceKind? k
6565
base(deadline: Constants.kLongPressTimeout, debugOwner: debugOwner, kind: kind) {
6666
}
6767

68+
bool _longPressAccepted = false;
69+
6870
public GestureLongPressCallback onLongPress;
6971

72+
public GestureLongPressUpCallback onLongPressUp;
73+
7074
protected override void didExceedDeadline() {
7175
this.resolve(GestureDisposition.accepted);
76+
this._longPressAccepted = true;
77+
7278
if (this.onLongPress != null) {
7379
this.invokeCallback<object>("onLongPress", () => {
7480
this.onLongPress();
@@ -79,7 +85,19 @@ protected override void didExceedDeadline() {
7985

8086
protected override void handlePrimaryPointer(PointerEvent evt) {
8187
if (evt is PointerUpEvent) {
82-
this.resolve(GestureDisposition.rejected);
88+
if (this._longPressAccepted && this.onLongPressUp != null) {
89+
this._longPressAccepted = false;
90+
this.invokeCallback<object>("onLongPressUp", () => {
91+
this.onLongPressUp();
92+
return null;
93+
});
94+
}
95+
else {
96+
this.resolve(GestureDisposition.rejected);
97+
}
98+
}
99+
else if (evt is PointerDownEvent || evt is PointerCancelEvent) {
100+
this._longPressAccepted = false;
83101
}
84102
}
85103

Runtime/widgets/gesture_detector.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ public override Widget build(BuildContext context) {
235235
gestures[typeof(LongPressGestureRecognizer)] =
236236
new GestureRecognizerFactoryWithHandlers<LongPressGestureRecognizer>(
237237
() => new LongPressGestureRecognizer(debugOwner: this),
238-
instance => { instance.onLongPress = this.onLongPress; }
238+
instance => {
239+
instance.onLongPress = this.onLongPress;
240+
instance.onLongPressUp = this.onLongPressUp;
241+
}
239242
);
240243
}
241244

0 commit comments

Comments
 (0)