From 2c5b1fbb6f91ba9ffb03a82449edf678b8f2654f Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 4 Jun 2025 21:46:44 +0100 Subject: [PATCH] NativeMessageBox: On iOS, prefer the peer of the associatedComponent to the focused peer to determine the parent controller --- .../native/juce_NativeMessageBox_ios.mm | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_NativeMessageBox_ios.mm b/modules/juce_gui_basics/native/juce_NativeMessageBox_ios.mm index 2a649fb03c..4230ff1f31 100644 --- a/modules/juce_gui_basics/native/juce_NativeMessageBox_ios.mm +++ b/modules/juce_gui_basics/native/juce_NativeMessageBox_ios.mm @@ -44,7 +44,7 @@ std::unique_ptr ScopedMessageBoxInterface::create (co void runAsync (std::function recipient) override { - if (iOSGlobals::currentlyFocusedPeer == nullptr) + if (peerToUse == nullptr) { // Since iOS8, alert windows need to be associated with a window, so you need to // have at least one window on screen when you use this @@ -76,9 +76,9 @@ std::unique_ptr ScopedMessageBoxInterface::create (co [alert.get() setPreferredAction: action]; } - [iOSGlobals::currentlyFocusedPeer->controller presentViewController: alert.get() - animated: YES - completion: nil]; + [peerToUse->controller presentViewController: alert.get() + animated: YES + completion: nil]; } int runSync() override @@ -109,6 +109,15 @@ 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) };