Repos
C++
1016 B37 lines Opens in site
Directory
Raw
Download
#include "screens/post/TapGesture.hpp"
#include "core/Timer.hpp"
#include "spec/PostsSpec.hpp"
#include "ui/View.hpp"
namespace dp {
void TapGesture::tap(std::uint64_t slotId, const TapHandlers& handlers) {
if (!handlers.any()) return;
if (!handlers.doubleTap) {
handlers.single();
return;
}
ui::UiState& ui = ui::UiState::instance();
ui::Slot& slot = ui.slot(slotId);
const double now = ui.now;
const double windowSeconds = spec::PostsTiming::kDoubleTapMs / 1000.0;
if (slot.flag && now - slot.stamp < windowSeconds) {
slot.flag = false;
handlers.doubleTap();
return;
}
slot.flag = true;
slot.stamp = now;
if (!handlers.single) return;
const double stamp = now;
auto single = handlers.single;
Timer::after(spec::PostsTiming::kDoubleTapMs + 20, [slotId, stamp, single] {
ui::Slot& s = ui::UiState::instance().slot(slotId);
if (!s.flag || s.stamp != stamp) return; // a second tap consumed it
s.flag = false;
single();
});
}
} // namespace dp