From f7c7225f5c40a5aa04b3ff6bd6a426cc75f1bbb4 Mon Sep 17 00:00:00 2001 From: reuk Date: Sun, 27 Oct 2024 17:17:19 +0000 Subject: [PATCH] UIViewComponentPeer: Fix deprecation warnings for iOS 17 --- .../juce_core/native/juce_ObjCHelpers_mac.h | 1 + .../native/juce_UIViewComponentPeer_ios.mm | 35 +++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/modules/juce_core/native/juce_ObjCHelpers_mac.h b/modules/juce_core/native/juce_ObjCHelpers_mac.h index b122c755b8..f533412b37 100644 --- a/modules/juce_core/native/juce_ObjCHelpers_mac.h +++ b/modules/juce_core/native/juce_ObjCHelpers_mac.h @@ -593,6 +593,7 @@ private: } JUCE_DEFINE_IOS_VERSION_CHECKER_FOR_VERSION (14, 0) +JUCE_DEFINE_IOS_VERSION_CHECKER_FOR_VERSION (17, 0) #endif diff --git a/modules/juce_gui_basics/native/juce_UIViewComponentPeer_ios.mm b/modules/juce_gui_basics/native/juce_UIViewComponentPeer_ios.mm index 7ceaba7be8..da8d94f823 100644 --- a/modules/juce_gui_basics/native/juce_UIViewComponentPeer_ios.mm +++ b/modules/juce_gui_basics/native/juce_UIViewComponentPeer_ios.mm @@ -1019,10 +1019,8 @@ static bool doKeysUp (UIViewComponentPeer* owner, NSSet* presses, UIPr return owner != nullptr && owner->canBecomeKeyWindow(); } -- (void) traitCollectionDidChange: (UITraitCollection*) previousTraitCollection +static void postTraitChangeNotification (UITraitCollection* previousTraitCollection) { - [super traitCollectionDidChange: previousTraitCollection]; - const auto wasDarkModeActive = ([previousTraitCollection userInterfaceStyle] == UIUserInterfaceStyleDark); if (wasDarkModeActive != Desktop::getInstance().isDarkModeActive()) @@ -1030,6 +1028,18 @@ static bool doKeysUp (UIViewComponentPeer* owner, NSSet* presses, UIPr object: nil]; } +#if ! defined (__IPHONE_17_0) || __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_17_0 +- (void) traitCollectionDidChange: (UITraitCollection*) previousTraitCollection +{ + [super traitCollectionDidChange: previousTraitCollection]; + + if (@available (ios 17, *)) + {} // do nothing + else + postTraitChangeNotification (previousTraitCollection); +} +#endif + - (BOOL) isAccessibilityElement { return NO; @@ -1671,6 +1681,23 @@ bool KeyPress::isKeyCurrentlyDown (int keyCode) Point juce_lastMousePos; +struct ChangeRegistrationTrait +{ + #if defined (__IPHONE_17_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_17_0 + API_AVAILABLE (ios (17)) + static void newFn (UIView* view) + { + [view registerForTraitChanges: @[UITraitUserInterfaceStyle.self] + withHandler: ^(JuceUIView*, UITraitCollection* previousTraitCollection) + { + postTraitChangeNotification (previousTraitCollection); + }]; + } + #endif + + static void oldFn (UIView*) {} +}; + //============================================================================== UIViewComponentPeer::UIViewComponentPeer (Component& comp, int windowStyleFlags, UIView* viewToAttachTo) : ComponentPeer (comp, windowStyleFlags), @@ -1697,6 +1724,8 @@ UIViewComponentPeer::UIViewComponentPeer (Component& comp, int windowStyleFlags, if ((windowStyleFlags & ComponentPeer::windowRequiresSynchronousCoreGraphicsRendering) == 0) [[view layer] setDrawsAsynchronously: YES]; + ifelse_17_0 (view); + if (isSharedWindow) { window = [viewToAttachTo window];