Interesting solution. I did something different. In my ListBoxModel class I have a boolean value called fDragScrolling, initialized to false. Then I implemented this:
void listBoxItemClicked(int rowNumber, const MouseEvent &)
fDragScrolling = false;
// stuff that should happen when an item is clicked
fDragScrolling = true;
The idea is that is cancels a click if a scroll happens. Same thing as your solution, just a little different method.
So that works nicely for some of my ListBoxes. But I have another one that you can use a mouse to drag-reorder items in it. I can’t figure out a way to allow touch events to scroll that ListBox, as well as reorder items in it.
On an iPad, maybe touch and drag would scroll, while touch and hod for a second would switch into item reordering mode. But JUCE doesn’t seem to have a concept of that in its ListBoxes. I may have to implement my own kind of ListBox to properly handle touch interaction - it doesn’t seem to be a priority for JUCE. Even this Viewport::setScrollOnDragEnabled method doesn’t really work right without some other workarounds by us.