Skip to content

Commit bcc5fea

Browse files
authored
feat: add ability to detect repeated press from defolds action (#31)
1 parent 9cee869 commit bcc5fea

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

in/gesture.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ function M.create(settings)
9696
gestures.swipe_up = false
9797
gestures.swipe_down = false
9898
gestures.swipe = nil
99+
gestures.repeated = false
99100

100101
gestures.two_finger.tap = false
101102
gestures.two_finger.double_tap = false
@@ -105,6 +106,7 @@ function M.create(settings)
105106
gestures.two_finger.swipe_up = false
106107
gestures.two_finger.swipe_down = false
107108
gestures.two_finger.pinch = nil
109+
gestures.two_finger.repeated = false
108110
end
109111

110112

@@ -114,6 +116,7 @@ function M.create(settings)
114116
state.is_tap = false
115117
state.is_long_press = false
116118
state.is_swipe = false
119+
state.is_repeated = false
117120
state.swipe_left = false
118121
state.swipe_right = false
119122
state.swipe_up = false
@@ -177,6 +180,9 @@ function M.create(settings)
177180

178181
state.released_time = socket.gettime()
179182
state.pressed = false
183+
184+
elseif touch.repeated then
185+
state.is_repeated = true
180186
end
181187
end
182188

@@ -196,6 +202,8 @@ function M.create(settings)
196202
gestures.swipe_down = single_state.swipe_down
197203
gestures.swipe_right = single_state.swipe_right
198204
gestures.swipe_left = single_state.swipe_left
205+
elseif single_state.is_repeated then
206+
gestures.repeated = single_state.is_repeated
199207
end
200208
end
201209

@@ -232,6 +240,8 @@ function M.create(settings)
232240
gestures.two_finger.swipe_down = s1.swipe_down and s2.swipe_down
233241
gestures.two_finger.swipe_right = s1.swipe_right and s2.swipe_right
234242
gestures.two_finger.swipe_left = s1.swipe_left and s2.swipe_left
243+
elseif s1.is_repeated and s1.is_repeated then
244+
guestures.two_finger.repeated = true
235245
else
236246
local pressed1 = s1.pressed_position
237247
local pressed2 = s2.pressed_position
@@ -276,12 +286,13 @@ local instances = {}
276286
-- * tap [table] Values: position
277287
-- * double_tap [table] Values: position
278288
-- * long_press [table] Values: position, time
289+
-- * repeated [boolean]
279290
-- * swipe_left [boolean]
280291
-- * swipe_right [boolean]
281292
-- * swipe_up [boolean]
282293
-- * swipe_down [boolean]
283294
-- * swipe [table] Values: from, to and time
284-
-- * two_finger [table] Two-finger geatures (tap, double_tap, long_press, swipe_* and pinch)
295+
-- * two_finger [table] Two-finger geatures (tap, double_tap, long_press, repeated, swipe_* and pinch)
285296
function M.on_input(self, action_id, action)
286297
if not instances[self] then
287298
instances[self] = M.create(M.SETTINGS)

in/gesture.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Using the gesture module directly gives you full control but requires a couple o
4141
print(g.double_tap.position)
4242
elseif g.long_press then
4343
print(g.long_press.position, g.long_press.time)
44+
elseif g.repeated then
45+
print("Repeated")
4446
elseif g.two_finger.tap then
4547
print("Two finger tap!")
4648
elseif g.two_finger.pinch then

0 commit comments

Comments
 (0)