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

Commit ac1beee

Browse files
[[ DataGrid 2 ]] Fix drags to cooperate with the mobile scroller.
Previously, a data grid's mobile scroller was getting in the way of reorder and swipe actions. To fix for reordering, we disable the scroller whenn the user clicks on a reorder control (and re-enable it when the reorder completes). Swipes are a little trickier. We track dragging on mouse down, but disabling the scroller at this point will prevent all scrolling. Instead we attempt to determine if the user is trying to drag the row before disabling the scroller.
1 parent 4abd6df commit ac1beee

2 files changed

Lines changed: 74 additions & 4 deletions

File tree

Toolset/palettes/revdatagridlibrary/behaviorsdatagridbuttonbehavior.livecodescript

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ private command _CreateMobileScroller
330330
mobileControlSet sScrollerId, "canBounce", "true"
331331
mobileControlSet sScrollerId, "pagingEnabled", "false"
332332
mobileControlSet sScrollerId, "canScrollToTop", "true"
333-
mobileControlSet sScrollerId, "delayTouches", "true"
333+
mobileControlSet sScrollerId, "delayTouches", "false"
334334
mobileControlSet sScrollerId, "canCancelTouches", "true"
335335
__PollVisibility
336336
end if
@@ -9593,6 +9593,18 @@ private function __HasMobileScroller
95939593
sScrollerId is among the lines of mobileControls()
95949594
end __HasMobileScroller
95959595

9596+
command __EnableMobileScroller
9597+
if __HasMobileScroller() then
9598+
mobileControlSet sScrollerId, "scrollingEnabled", "true"
9599+
end if
9600+
end __EnableMobileScroller
9601+
9602+
command __DisableMobileScroller
9603+
if __HasMobileScroller() then
9604+
mobileControlSet sScrollerId, "scrollingEnabled", "false"
9605+
end if
9606+
end __DisableMobileScroller
9607+
95969608
--------------------------------------------------------------------------------
95979609
-- DataGrid 2
95989610
--------------------------------------------------------------------------------
@@ -10069,6 +10081,9 @@ command DG2_ReorderStart
1006910081
return "Could not find line of control"
1007010082
end if
1007110083

10084+
-- Make sure any scroller doesn't interfere with drag reorders.
10085+
__DisableMobileScroller
10086+
1007210087
put tControl into sReorderControl
1007310088
put tIndex into sReorderStartIndex
1007410089
put tLine into sReorderStartLine
@@ -10192,6 +10207,8 @@ command DG2_ReorderEnd
1019210207
return "No reorder currently in progress"
1019310208
end if
1019410209

10210+
__EnableMobileScroller
10211+
1019510212
-- Animate the control we are reordering into its new slot.
1019610213
DG2_AnimationsAdd sReorderControl, "top", the top of sReorderControl, DG2_TopOfControlWithLineNo(sReorderLastHoverLine) + 1, the dgAnimationProp["ReorderHomingDuration"] of me, the dgAnimationProp["ReorderHomingEasing"] of me, "DG2_ReorderControlHomed", empty, the long id of me
1019710214
put false into sReorderInProgress
@@ -11091,6 +11108,14 @@ command DG2_AnimationsBatchAddWithArray pAnimationsA
1109111108
return tIDs
1109211109
end DG2_AnimationsBatchAddWithArray
1109311110

11111+
function DG2_AnimationsGetPendingCount
11112+
if sAnimationsA is empty or sAnimationsA is not an array then
11113+
return 0
11114+
else
11115+
return the number of lines in the keys of sAnimationsA
11116+
end if
11117+
end DG2_AnimationsGetPendingCount
11118+
1109411119
-- Set all current animations to their end value.
1109511120
command DG2_AnimationsFinaliseAll
1109611121
cancel sAnimationsPulseMsgID

Toolset/palettes/revdatagridlibrary/behaviorsrowchainedbehavior.livecodescript

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
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
67
local sDragging
78
local sDragStart
89
local sDragLocs
910
local sControlLeft
1011
local 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.
1420
constant 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
2839
end PreFillInData
2940

41+
before ResetData
42+
DG2_ClearVars
43+
end ResetData
44+
3045
----------------------------------------------------------------------
3146

3247
before 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
171211
end mouseRelease
172212

@@ -211,6 +251,8 @@ end LayoutControl
211251
----------------------------------------------------------------------
212252

213253
private 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

273317
command 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

Comments
 (0)