|
| 1 | +script "RevDataGridLibraryBehaviorsSwipeControlHolderBehavior" |
| 2 | +---------------------------------------------------------------------- |
| 3 | +-- This behavior is applied to a group used to house fully visible swipe |
| 4 | +-- controls for a give row and side, dealing with animating the control in an |
| 5 | +-- out as well as catching any clicks. (Partially visible - i.e. during a row |
| 6 | +-- drag left/right action - are handled in the row's chained behavior). When |
| 7 | +-- fully visible, a swipe control takes over the full DataGrid, using the holder |
| 8 | +-- group as message catcher, with all clicks in th DataGrid either hiding the |
| 9 | +-- swipe control or performing the swipe control click action. |
| 10 | + |
| 11 | +local sRowIndex |
| 12 | +local sSwipeControlSide |
| 13 | +local sSwipeControl |
| 14 | +local sSwipeControlOwner |
| 15 | + |
| 16 | +setProp dgSwipeControlSide pSide |
| 17 | + put pSide into sSwipeControlSide |
| 18 | +end dgSwipeControlSide |
| 19 | + |
| 20 | +getProp dgSwipeControlSide |
| 21 | + return sSwipeControlSide |
| 22 | +end dgSwipeControlSide |
| 23 | + |
| 24 | +-- Animate in the swipe control for the given row index using from the |
| 25 | +-- previously specified side. |
| 26 | +-- Setting to empty will animate out any visible swipe control. |
| 27 | +setProp dgSwipeControlRowIndex pIndex |
| 28 | + if pIndex is not empty then |
| 29 | + local tRowControl |
| 30 | + put the dgDataControlOfIndex[pIndex] of the dgControl of me into tRowControl |
| 31 | + if tRowControl is empty then |
| 32 | + return "Could not find row control" |
| 33 | + end if |
| 34 | + |
| 35 | + switch sSwipeControlSide |
| 36 | + case "left" |
| 37 | + get DG2_CustomisableControlsGetLeftSwipeControlForControl(the long id of tRowControl) |
| 38 | + break |
| 39 | + case "right" |
| 40 | + get DG2_CustomisableControlsGetRightSwipeControlForControl(the long id of tRowControl) |
| 41 | + break |
| 42 | + default |
| 43 | + return "Unknown swipe side" && sSwipeControlSide |
| 44 | + end switch |
| 45 | + if it is empty then |
| 46 | + return "Could not find swipe control" |
| 47 | + end if |
| 48 | + |
| 49 | + put it into sSwipeControl |
| 50 | + put pIndex into sRowIndex |
| 51 | + put the owner of sSwipeControl into sSwipeControlOwner |
| 52 | + |
| 53 | + lock screen |
| 54 | + set the rect of me to the rect of group "dgList" of the dgControl of me |
| 55 | + set the rect of graphic "Message Catcher" of me to the rect of me |
| 56 | + set the visible of me to true |
| 57 | + unlock screen |
| 58 | + |
| 59 | + DG2_SwipeControlShow |
| 60 | + return the result |
| 61 | + else |
| 62 | + local tResult |
| 63 | + DG2_SwipeControlHide |
| 64 | + put empty into sRowIndex |
| 65 | + return tResult |
| 66 | + end if |
| 67 | +end dgSwipeControlRowIndex |
| 68 | + |
| 69 | +getProp dgSwipeControlRowIndex |
| 70 | + return sRowIndex |
| 71 | +end dgSwipeControlRowIndex |
| 72 | + |
| 73 | +-- A scroll or resize has occurred. Reposition the group inside the the list, |
| 74 | +-- the swipe control next to the appropriate row and the row to the left or |
| 75 | +-- right of the swipe control. |
| 76 | +command DG2_SwipeControlHolderReposition |
| 77 | + if not the visible of me then |
| 78 | + return empty |
| 79 | + end if |
| 80 | + if sRowIndex is empty then |
| 81 | + return empty |
| 82 | + end if |
| 83 | + if sSwipeControl is empty then |
| 84 | + return empty |
| 85 | + end if |
| 86 | + |
| 87 | + local tRowControl |
| 88 | + put the dgDataControlOfIndex[sRowIndex] of the dgControl of me into tRowControl |
| 89 | + if tRowControl is empty then |
| 90 | + set the visible of sSwipeControl to false |
| 91 | + return empty |
| 92 | + end if |
| 93 | + |
| 94 | + lock screen |
| 95 | + set the visible of sSwipeControl to true |
| 96 | + set the rect of me to the rect of group "dgList" of the dgControl of me |
| 97 | + set the rect of graphic "Message Catcher" of me to the rect of me |
| 98 | + set the top of sSwipeControl to the top of tRowControl |
| 99 | + switch sSwipeControlSide |
| 100 | + case "left" |
| 101 | + set the left of tRowControl to the right of sSwipeControl |
| 102 | + break |
| 103 | + case "right" |
| 104 | + set the right of tRowControl to the left of sSwipeControl |
| 105 | + break |
| 106 | + end switch |
| 107 | + unlock screen |
| 108 | + |
| 109 | + return empty |
| 110 | +end DG2_SwipeControlHolderReposition |
| 111 | + |
| 112 | +private command DG2_SwipeControlShow |
| 113 | + local tRowControl |
| 114 | + put the dgDataControlOfIndex[sRowIndex] of the dgControl of me into tRowControl |
| 115 | + if tRowControl is empty then |
| 116 | + return "Could not find row control" |
| 117 | + end if |
| 118 | + |
| 119 | + -- A swipe has been occured so tell the user by sending the |
| 120 | + -- appropriate message. If the user handles the message then we |
| 121 | + -- can assume they are dealing with the action and on't need to do |
| 122 | + -- anything more. If it's not handled, then fully animate in the |
| 123 | + -- swipe control. |
| 124 | + switch sSwipeControlSide |
| 125 | + case "left" |
| 126 | + dispatch DG2_GetMessageNameForTag("RowSwipedRight") to tRowControl |
| 127 | + if it is not "handled" then |
| 128 | + DG2_AnimationsAdd the long id of tRowControl, "left", the left of tRowControl, the right of sSwipeControl, the dgAnimationProp["SwipeCompleteDuration"] of the dgControl of me, the dgAnimationProp["SwipeCompleteEasing"] of the dgControl of me, "DG2_SwipeControlShowComplete", empty, the long id of me |
| 129 | + end if |
| 130 | + break |
| 131 | + case "right" |
| 132 | + dispatch DG2_GetMessageNameForTag("RowSwipedLeft") to tRowControl |
| 133 | + if it is not "handled" then |
| 134 | + DG2_AnimationsAdd the long id of tRowControl, "right", the right of tRowControl, the left of sSwipeControl, the dgAnimationProp["SwipeCompleteDuration"] of the dgControl of me, the dgAnimationProp["SwipeCompleteEasing"] of the dgControl of me, "DG2_SwipeControlShowComplete", empty, the long id of me |
| 135 | + end if |
| 136 | + break |
| 137 | + end switch |
| 138 | + |
| 139 | + return empty |
| 140 | +end DG2_SwipeControlShow |
| 141 | + |
| 142 | +on DG2_SwipeControlShowComplete |
| 143 | + -- When the animation is complete, the swipe control should be fully visible. |
| 144 | + -- This means we can now bring it to the front of the DataGrid allowing it or |
| 145 | + -- the holder group to catch all messages. |
| 146 | + lock screen |
| 147 | + relayer me to front of owner |
| 148 | + relayer sSwipeControl to front of me |
| 149 | + unlock screen |
| 150 | + |
| 151 | + return empty |
| 152 | +end DG2_SwipeControlShowComplete |
| 153 | + |
| 154 | +private command DG2_SwipeControlHide |
| 155 | + local tRowControl |
| 156 | + put the dgDataControlOfIndex[sRowIndex] of the dgControl of me into tRowControl |
| 157 | + if tRowControl is empty then |
| 158 | + return "Could not find row control" |
| 159 | + end if |
| 160 | + |
| 161 | + local tIsVisible |
| 162 | + put the visible of me into tIsVisible |
| 163 | + |
| 164 | + lock screen |
| 165 | + relayer sSwipeControl before tRowControl |
| 166 | + set the visible of me to false |
| 167 | + unlock screen |
| 168 | + |
| 169 | + -- The row script takes care of returning the swipe control. |
| 170 | + -- If we're not visible then tell the row control not to bother animating the |
| 171 | + -- return. |
| 172 | + dispatch "DG2_SwipeReturn" to tRowControl with not tIsVisible |
| 173 | + return the result |
| 174 | +end DG2_SwipeControlHide |
| 175 | + |
| 176 | +on DG2_SwipeControlHideComplete |
| 177 | + local tRowControl |
| 178 | + put the dgDataControlOfIndex[sRowIndex] of the dgControl of me into tRowControl |
| 179 | + if tRowControl is not empty then |
| 180 | + set the left of tRowControl to the left of group "dgList" of the dgControl of me |
| 181 | + end if |
| 182 | + |
| 183 | + if sSwipeControl is not empty then |
| 184 | + set the visible of sSwipeControl to false |
| 185 | + relayer sSwipeControl to back of sSwipeControlOwner |
| 186 | + end if |
| 187 | + |
| 188 | + return empty |
| 189 | +end DG2_SwipeControlHideComplete |
| 190 | + |
| 191 | +on mouseUp |
| 192 | + local tRowControl |
| 193 | + put the dgDataControlOfIndex[sRowIndex] of the dgControl of me into tRowControl |
| 194 | + if tRowControl is empty then |
| 195 | + exit mouseUp |
| 196 | + end if |
| 197 | + |
| 198 | + if the long id of the target contains the long id of sSwipeControl then |
| 199 | + switch sSwipeControlSide |
| 200 | + case "left" |
| 201 | + dispatch DG2_GetMessageNameForTag("RowLeftSwipeControlClicked") to tRowControl |
| 202 | + break |
| 203 | + case "right" |
| 204 | + dispatch DG2_GetMessageNameForTag("RowRightSwipeControlClicked") to tRowControl |
| 205 | + break |
| 206 | + end switch |
| 207 | + else |
| 208 | + DG2_SwipeControlHide |
| 209 | + switch sSwipeControlSide |
| 210 | + case "left" |
| 211 | + dispatch DG2_GetMessageNameForTag("RowLeftSwipeControlHidden") to tRowControl |
| 212 | + break |
| 213 | + case "right" |
| 214 | + dispatch DG2_GetMessageNameForTag("RowRightSwipeControlHidden") to tRowControl |
| 215 | + break |
| 216 | + end switch |
| 217 | + end if |
| 218 | +end mouseUp |
0 commit comments