@@ -6,168 +6,123 @@ namespace Unity.UIWidgets.gestures {
6
6
7
7
public delegate void GestureLongPressUpCallback ( ) ;
8
8
9
- public delegate void GestureLongPressDragStartCallback ( GestureLongPressDragStartDetails details ) ;
9
+ public delegate void GestureLongPressStartCallback ( LongPressStartDetails details ) ;
10
10
11
- public delegate void GestureLongPressDragUpdateCallback ( GestureLongPressDragUpdateDetails details ) ;
11
+ public delegate void GestureLongPressMoveUpdateCallback ( LongPressMoveUpdateDetails details ) ;
12
12
13
- public delegate void GestureLongPressDragUpCallback ( GestureLongPressDragUpDetails details ) ;
13
+ public delegate void GestureLongPressEndCallback ( LongPressEndDetails details ) ;
14
14
15
- public class GestureLongPressDragStartDetails {
16
- public GestureLongPressDragStartDetails (
17
- TimeSpan ? sourceTimeStamp = null ,
15
+ public class LongPressStartDetails {
16
+ public LongPressStartDetails (
18
17
Offset globalPosition = null
19
18
) {
20
- this . sourceTimeStamp = sourceTimeStamp ;
21
19
this . globalPosition = globalPosition ?? Offset . zero ;
22
20
}
23
21
24
-
25
- public readonly TimeSpan ? sourceTimeStamp ;
26
-
27
22
public readonly Offset globalPosition ;
28
23
}
29
24
30
- public class GestureLongPressDragUpdateDetails {
31
- public GestureLongPressDragUpdateDetails (
32
- TimeSpan ? sourceTimeStamp = null ,
25
+ public class LongPressMoveUpdateDetails {
26
+ public LongPressMoveUpdateDetails (
33
27
Offset globalPosition = null ,
34
28
Offset offsetFromOrigin = null
35
29
) {
36
- this . sourceTimeStamp = sourceTimeStamp ;
37
30
this . globalPosition = globalPosition ?? Offset . zero ;
38
31
this . offsetFromOrigin = offsetFromOrigin ?? Offset . zero ;
39
32
}
40
33
41
- public readonly TimeSpan ? sourceTimeStamp ;
42
-
43
34
public readonly Offset globalPosition ;
44
35
45
36
public readonly Offset offsetFromOrigin ;
46
37
}
47
38
48
- public class GestureLongPressDragUpDetails {
49
- public GestureLongPressDragUpDetails (
50
- TimeSpan ? sourceTimeStamp = null ,
39
+ public class LongPressEndDetails {
40
+ public LongPressEndDetails (
51
41
Offset globalPosition = null
52
42
) {
53
- this . sourceTimeStamp = sourceTimeStamp ;
54
43
this . globalPosition = globalPosition ?? Offset . zero ;
55
44
}
56
45
57
- public readonly TimeSpan ? sourceTimeStamp ;
58
-
59
46
public readonly Offset globalPosition ;
60
47
}
61
48
62
49
63
50
public class LongPressGestureRecognizer : PrimaryPointerGestureRecognizer {
64
- public LongPressGestureRecognizer ( object debugOwner = null , PointerDeviceKind ? kind = null ) :
65
- base ( deadline : Constants . kLongPressTimeout , debugOwner : debugOwner , kind : kind ) {
66
- }
51
+ public LongPressGestureRecognizer (
52
+ float ? postAcceptSlopTolerance = null ,
53
+ object debugOwner = null ,
54
+ PointerDeviceKind ? kind = null ) : base (
55
+ deadline : Constants . kLongPressTimeout ,
56
+ postAcceptSlopTolerance : postAcceptSlopTolerance ,
57
+ kind : kind ,
58
+ debugOwner : debugOwner ) { }
67
59
68
60
bool _longPressAccepted = false ;
69
61
62
+ Offset _longPressOrigin ;
63
+
70
64
public GestureLongPressCallback onLongPress ;
71
65
66
+ public GestureLongPressStartCallback onLongPressStart ;
67
+
68
+ public GestureLongPressMoveUpdateCallback onLongPressMoveUpdate ;
69
+
72
70
public GestureLongPressUpCallback onLongPressUp ;
73
71
72
+ public GestureLongPressEndCallback onLongPressEnd ;
73
+
74
74
protected override void didExceedDeadline ( ) {
75
75
this . resolve ( GestureDisposition . accepted ) ;
76
76
this . _longPressAccepted = true ;
77
-
77
+ base . acceptGesture ( this . primaryPointer ) ;
78
78
if ( this . onLongPress != null ) {
79
79
this . invokeCallback < object > ( "onLongPress" , ( ) => {
80
80
this . onLongPress ( ) ;
81
81
return null ;
82
82
} ) ;
83
83
}
84
- }
85
84
86
- protected override void handlePrimaryPointer ( PointerEvent evt ) {
87
- if ( evt is PointerUpEvent ) {
88
- if ( this . _longPressAccepted && this . onLongPressUp != null ) {
89
- this . _longPressAccepted = false ;
90
- this . invokeCallback < object > ( "onLongPressUp" , ( ) => {
91
- this . onLongPressUp ( ) ;
85
+ if ( this . onLongPressStart != null ) {
86
+ this . invokeCallback < object > ( "onLongPressStart" ,
87
+ ( ) => {
88
+ this . onLongPressStart ( new LongPressStartDetails ( globalPosition : this . _longPressOrigin ) ) ;
92
89
return null ;
93
90
} ) ;
94
- }
95
- else {
96
- this . resolve ( GestureDisposition . rejected ) ;
97
- }
98
- }
99
- else if ( evt is PointerDownEvent || evt is PointerCancelEvent ) {
100
- this . _longPressAccepted = false ;
101
- }
102
- }
103
-
104
- public override string debugDescription {
105
- get { return "long press" ; }
106
- }
107
- }
108
-
109
- public class LongPressDragGestureRecognizer : PrimaryPointerGestureRecognizer {
110
- public LongPressDragGestureRecognizer ( object debugOwner = null ) : base (
111
- deadline : Constants . kLongPressTimeout ,
112
- postAcceptSlopTolerance : null ,
113
- debugOwner : debugOwner
114
- ) {
115
- }
116
-
117
- bool _longPressAccepted = false ;
118
-
119
- Offset _longPressOrigin ;
120
-
121
- TimeSpan ? _longPressStartTimestamp ;
122
-
123
- public GestureLongPressDragStartCallback onLongPressStart ;
124
-
125
- public GestureLongPressDragUpdateCallback onLongPressDragUpdate ;
126
-
127
- public GestureLongPressDragUpCallback onLongPressUp ;
128
-
129
- protected override void didExceedDeadline ( ) {
130
- this . resolve ( GestureDisposition . accepted ) ;
131
- this . _longPressAccepted = true ;
132
- base . acceptGesture ( this . primaryPointer ) ;
133
- if ( this . onLongPressStart != null ) {
134
- this . invokeCallback < object > ( "onLongPressStart" , ( ) => {
135
- this . onLongPressStart ( new GestureLongPressDragStartDetails (
136
- sourceTimeStamp : this . _longPressStartTimestamp ,
137
- globalPosition : this . _longPressOrigin
138
- ) ) ;
139
- return null ;
140
- } ) ;
141
91
}
142
92
}
143
93
144
- protected override void handlePrimaryPointer ( PointerEvent e ) {
145
- if ( e is PointerUpEvent ) {
146
- if ( this . _longPressAccepted == true && this . onLongPressUp != null ) {
147
- this . _longPressAccepted = false ;
148
- this . invokeCallback < object > ( "onLongPressUp" , ( ) => {
149
- this . onLongPressUp ( new GestureLongPressDragUpDetails (
150
- sourceTimeStamp : e . timeStamp ,
151
- globalPosition : e . position
152
- ) ) ;
153
- return null ;
154
- } ) ;
94
+ protected override void handlePrimaryPointer ( PointerEvent evt ) {
95
+ if ( evt is PointerUpEvent ) {
96
+ if ( this . _longPressAccepted ) {
97
+ if ( this . onLongPressUp != null ) {
98
+ this . invokeCallback < object > ( "onLongPressUp" , ( ) => {
99
+ this . onLongPressUp ( ) ;
100
+ return null ;
101
+ } ) ;
102
+ }
103
+
104
+ if ( this . onLongPressEnd != null ) {
105
+ this . invokeCallback < object > ( "onLongPressEnd" , ( ) => {
106
+ this . onLongPressEnd ( new LongPressEndDetails ( globalPosition : evt . position ) ) ;
107
+ return null ;
108
+ } ) ;
109
+ }
110
+
111
+ this . _longPressAccepted = true ;
155
112
}
156
113
else {
157
114
this . resolve ( GestureDisposition . rejected ) ;
158
115
}
159
116
}
160
- else if ( e is PointerDownEvent ) {
117
+ else if ( evt is PointerDownEvent || evt is PointerCancelEvent ) {
161
118
this . _longPressAccepted = false ;
162
- this . _longPressStartTimestamp = e . timeStamp ;
163
- this . _longPressOrigin = e . position ;
119
+ this . _longPressOrigin = evt . position ;
164
120
}
165
- else if ( e is PointerMoveEvent && this . _longPressAccepted && this . onLongPressDragUpdate != null ) {
166
- this . invokeCallback < object > ( "onLongPressDrag" , ( ) => {
167
- this . onLongPressDragUpdate ( new GestureLongPressDragUpdateDetails (
168
- sourceTimeStamp : e . timeStamp ,
169
- globalPosition : e . position ,
170
- offsetFromOrigin : e . position - this . _longPressOrigin
121
+ else if ( evt is PointerMoveEvent && this . _longPressAccepted && this . onLongPressMoveUpdate != null ) {
122
+ this . invokeCallback < object > ( "onLongPressMoveUpdate" , ( ) => {
123
+ this . onLongPressMoveUpdate ( new LongPressMoveUpdateDetails (
124
+ globalPosition : evt . position ,
125
+ offsetFromOrigin : evt . position - this . _longPressOrigin
171
126
) ) ;
172
127
return null ;
173
128
} ) ;
@@ -177,15 +132,8 @@ protected override void handlePrimaryPointer(PointerEvent e) {
177
132
public override void acceptGesture ( int pointer ) {
178
133
}
179
134
180
- protected override void didStopTrackingLastPointer ( int pointer ) {
181
- this . _longPressAccepted = false ;
182
- this . _longPressOrigin = null ;
183
- this . _longPressStartTimestamp = null ;
184
- base . didStopTrackingLastPointer ( pointer ) ;
185
- }
186
-
187
135
public override string debugDescription {
188
- get { return "long press drag " ; }
136
+ get { return "long press" ; }
189
137
}
190
138
}
191
139
}
0 commit comments