33-- This behavior sits at the back of a row's behavior chain and is used to
44-- determine and handle edit mode and swipe actions.
55
6+ local sPreDragging
67local sDragging
78local sDragStart
89local sDragLocs
910local sControlLeft
1011local sControlRight
1112
13+ -- A user is seen to be dragging a row if the mouse has moved kPreDragLocDiff
14+ -- points within kPreDragTimeMargin milliseconds of the initial mouse click.
15+ constant kPreDragLocDiff = 15
16+ constant kPreDragTimeMargin = 100
17+
1218-- A swipe has occured if the mouse has moved kSwipeLocDiff points within
1319-- kSwipeTimeDiff milliseconds, plus or minus kSwipeTimeDiffMargin.
1420constant kSwipeTimeDiff = 100
@@ -17,16 +23,25 @@ constant kSwipeLocDiff = 50
1723
1824-- --------------------------------------------------------------------
1925
20- before PreFillInData
26+ private command DG2_ClearVars
27+ put false into sPreDragging
2128 put false into sDragging
2229 put empty into sDragStart
2330 put empty into sDragLocs
2431 put empty into sControlLeft
2532 put empty into sControlRight
2633
2734 DG2_CustomisableControlsClearForControl the long id of me
35+ end DG2_ClearVars
36+
37+ before PreFillInData
38+ DG2_ClearVars
2839end PreFillInData
2940
41+ before ResetData
42+ DG2_ClearVars
43+ end ResetData
44+
3045-- --------------------------------------------------------------------
3146
3247before mouseDown
@@ -45,7 +60,11 @@ before mouseDown
4560 exit to top
4661 end if
4762 else
48- if the dgProps["enable swipe" ] of the dgControl of me then
63+ -- Only track swipes if all previous swipe actions have completed - i.e.
64+ -- there are no animations pending. This prevents situations like where a
65+ -- user drags in one direction, but an animation is returning the row in
66+ -- the oposite direction.
67+ if the dgProps["enable swipe" ] of the dgControl of me and DG2_AnimationsGetPendingCount() is 0 then
4968 local tStartDrag
5069 put false into tStartDrag
5170
@@ -69,7 +88,8 @@ before mouseDown
6988 -- when repositioning the row control under the pointer on drag.
7089 put item 1 of the mouseLoc into sDragStart
7190 put the milliseconds && item 1 of the mouseLoc into sDragLocs
72- put true into sDragging
91+ put true into sPreDragging
92+ put false into sDragging
7393 end if
7494
7595 end if
@@ -85,6 +105,23 @@ before mouseMove pNewMouseH, pNewMouseV
85105 end if
86106
87107 if not the dgEditMode of the of the dgControl of me then
108+ -- If the user has just clicked (i.e. pre-dragging), attempt to determine
109+ -- if the user is trying to drag the row. We do this by checking if the
110+ -- horizontal position of the drag has changed sufficiently within a given
111+ -- time frame. If so, we can turn the scroller off to prevent any
112+ -- interference and begin tracking the drag.
113+ if sPreDragging then
114+ if abs (word 2 of the last line of sDragLocs - pNewMouseH ) > kPreDragLocDiff then
115+ put false into sPreDragging
116+ put true into sDragging
117+ __DisableMobileScroller
118+ else if the milliseconds - word 1 of the last line of sDragLocs > kPreDragTimeMargin then
119+ put false into sPreDragging
120+ else
121+ put the milliseconds && pNewMouseH & return before sDragLocs
122+ end if
123+ end if
124+
88125 if sDragging then
89126 put the milliseconds && pNewMouseH & return before sDragLocs
90127
@@ -146,6 +183,7 @@ before mouseUp
146183 end if
147184 end if
148185 else
186+ put false into sPreDragging
149187 if sDragging then
150188 DG2_DragFinished
151189 end if
@@ -163,10 +201,12 @@ before mouseRelease
163201 if the dgEditMode of the of the dgControl of me then
164202 DG2_ReorderEnd
165203 else
204+ put false into sPreDragging
166205 if sDragging then
167206 DG2_DragFinished
168207 end if
169208 end if
209+
170210 pass mouseRelease
171211end mouseRelease
172212
@@ -211,6 +251,8 @@ end LayoutControl
211251-- --------------------------------------------------------------------
212252
213253private command DG2_DragFinished
254+ __EnableMobileScroller
255+
214256 local tNow
215257 put the milliseconds into tNow
216258
@@ -252,11 +294,13 @@ private command DG2_DragFinished
252294 -- Determine the direction of the swipe and make sure we are
253295 -- currently showing the appropriate control for that swipe direcion.
254296 if tLocDiff > 0 and the left of me > sControlLeft then
297+ put false into sPreDragging
255298 put false into sDragging
256299 put empty into sDragLocs
257300 RowSwipeShowControlForIndexAndSide the dgIndex of me, "left"
258301 return the result
259302 else if tLocDiff < 0 and the right of me < sControlRight then
303+ put false into sPreDragging
260304 put false into sDragging
261305 put empty into sDragLocs
262306 RowSwipeShowControlForIndexAndSide the dgIndex of me, "right"
@@ -272,6 +316,7 @@ end DG2_DragFinished
272316
273317command DG2_SwipeReturn pDontAnimate
274318 -- Return everything back to where it was before the dragging started.
319+ put false into sPreDragging
275320 put false into sDragging
276321 put empty into sDragLocs
277322 if pDontAnimate then
0 commit comments