From 0cec50618d705953e9eff9b5e1c5a372a2d46187 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 15 Dec 2021 17:02:48 +0000 Subject: [PATCH] FileChooser: Find an appropriate peer to focus when the FileChooser is destroyed This works around a rare issue in the DialogsDemo where the AlertWindow would fail to display because no peer had focus. --- modules/juce_gui_basics/native/juce_ios_FileChooser.mm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/juce_gui_basics/native/juce_ios_FileChooser.mm b/modules/juce_gui_basics/native/juce_ios_FileChooser.mm index 28bb6904a9..f3b50115e8 100644 --- a/modules/juce_gui_basics/native/juce_ios_FileChooser.mm +++ b/modules/juce_gui_basics/native/juce_ios_FileChooser.mm @@ -131,6 +131,16 @@ public: ~Native() override { exitModalState (0); + + // Our old peer may not have received a becomeFirstResponder call at this point, + // so the static currentlyFocusedPeer may be null. + // We'll try to find an appropriate peer to focus. + + for (auto i = 0; i < ComponentPeer::getNumPeers(); ++i) + if (auto* p = ComponentPeer::getPeer (i)) + if (p != getPeer()) + if (auto* view = (UIView*) p->getNativeHandle()) + [view becomeFirstResponder]; } void launch() override