Reputation: 5206
I've been bridging to use RACSignal.bufferWithTime
. As far as I know there is no equivalence of it in RAC 3? Is there a workaround / trick to imitate the behaviour of bufferWithTime
using RAC3?
My case scenario is that I need to track if the user tapped twice in a given short period (to capture double tap). I basically buffer it with about 0.2 seconds and see if there was more than a single tap. FIY, I cannot use UIGestureRecognizer
since I use third party object which only exposes a single tap API.
Thanks!
Upvotes: 0
Views: 164
Reputation: 6308
You don't need to bufferWithTime
, it can be done simply by checking timestamps on each tap. Follow these steps:
map
the Signal of tap events into timestamps representing the current time when the tap occurs.combinePrevious
on the Signal of tap events to create a Signal whose values are a tuple of two timestamps: the first is previous value and the second is the current value.filter
this signal by subtracting the first value in each tuple from the second value, and comparing whether it meets or exceeds your 0.2
-second threshold.Whenever the final signal sends a value, a tap occurred within 0.2 seconds of the previous tap.
Upvotes: 1