From b272f968aa5dbff7afab26162e9b978fa2b4f5c3 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 29 Jul 2025 15:26:21 +0100 Subject: [PATCH] NativeMessageBox (iOS): Delay lookup of focused peer Before 2c5b1fbb6f91ba9ffb03a82449edf678b8f2654f, we only queried currentlyFocusedPeer during runAsync(), instead of reading it immediately. The behaviour after that commit prevented message boxes from showing if showMessageBoxAsync() was called before any peer had been created. --- .../native/juce_NativeMessageBox_ios.mm | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_NativeMessageBox_ios.mm b/modules/juce_gui_basics/native/juce_NativeMessageBox_ios.mm index 7182599bd9..d97f643415 100644 --- a/modules/juce_gui_basics/native/juce_NativeMessageBox_ios.mm +++ b/modules/juce_gui_basics/native/juce_NativeMessageBox_ios.mm @@ -44,6 +44,15 @@ std::unique_ptr ScopedMessageBoxInterface::create (co void runAsync (std::function recipient) override { + auto* peerToUse = std::invoke ([&]() -> UIViewComponentPeer* + { + if (auto* comp = options.getAssociatedComponent()) + if (auto* peer = comp->getPeer()) + return static_cast (peer); + + return iOSGlobals::currentlyFocusedPeer; + }); + if (peerToUse == nullptr) { // Since iOS8, alert windows need to be associated with a window, so you need to @@ -109,15 +118,6 @@ std::unique_ptr ScopedMessageBoxInterface::create (co private: const MessageBoxOptions options; - UIViewComponentPeer* peerToUse = std::invoke ([&]() -> UIViewComponentPeer* - { - if (auto* comp = options.getAssociatedComponent()) - if (auto* peer = comp->getPeer()) - return static_cast (peer); - - return iOSGlobals::currentlyFocusedPeer; - }); - NSUniquePtr alert; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MessageBox) };