Bug: PopupMenu gets into flickering, locked state on iOS and Android

JUCE PopupMenus can get locked into an unresponsive mode where the UI starts flickering. This happens on iOS and Android, and is related to multi-touch operation.

The issue is easy to reproduce with the JUCE DemoRunner app (for example on Android):

  1. Click ‘Browse demos’
  2. Select ‘GUI’
  3. Select ‘WidgetsDemo.h’
  4. From the menu bar, select ‘Menus’
  5. Hold one finger somewhere on the screen where there are no buttons
  6. while holding that finger, use a second finger to select ‘Nested Sub-Menus’ and then select one of the sub menus that appear
  7. Release the screen with both fingers. The flickering menu options start to appear.

There is at least one solution to solve this, which is to not call ‘highlightItemUnderMouse()’ in juce_PopupMenu.cpp, line 1341, but instead make it dependent on mouse events actually happening in the window:

    if (window.reallyContains(localMousePos, true)) // EDIT - new requirement
        highlightItemUnderMouse (globalMousePos, localMousePos, timeNow);

Hope this helps! This is a relevant use case for synths with an on-screen keyboard, in which one could be playing the keys while selecting something from a PopupMenu to change the sound. This is currently problematic as it triggers this bug.

There are many issues with submenus on touchscreens with JUCE. The PopupMenu code is really focused on mouse interaction. I have attempted to fix a lot of these issues here, I think the code includes something similar to you fix: Improving PopupMenu for touch screens

This. We’ve resorted to create native popup menus for iOS from juce::PopupMenu. That works pretty ok.

Thanks for the replies! Hoping the JUCE team will pick this up, either by integrating some of the patches that have been proposed, or by allowing a PopupMenu to use the JUCE popup or a native popup (like we have for file browsers where we can choose which one we want).