@@ -544,19 +544,62 @@ void appStyleChanged() override
544544 [controller setNeedsStatusBarAppearanceUpdate ];
545545 }
546546
547- void windowSceneChanged () override
547+ void updateSceneForWindow ()
548548 {
549549 if (isSharedWindow)
550550 return ;
551551
552- if (@ available (iOS 13 , *))
552+ auto * newWindow = std::invoke ([&]() -> JuceUIWindow*
553553 {
554- window.windowScene = windowSceneTracker->getWindowScene ();
554+ if (@available (iOS 13 , *))
555+ {
556+ if (auto * scene = windowSceneTracker->getWindowScene ())
557+ return [[JuceUIWindow alloc ] initWithWindowScene: scene];
558+ }
559+ else if (window == nil )
560+ {
561+ auto r = convertToCGRect (component.getBounds ());
562+ r.origin .y = [UIScreen mainScreen ].bounds .size .height - (r.origin .y + r.size .height );
563+
564+ return [[JuceUIWindow alloc ] initWithFrame: r];
565+ }
566+
567+ return nil ;
568+ });
569+
570+ if (newWindow == nil )
571+ return ;
572+
573+ if (window != nil )
574+ {
575+ [(JuceUIWindow*) window setOwner: nullptr ];
576+
577+ if (@available (iOS 13 , *))
578+ window.windowScene = nil ;
579+
580+ [window release ];
581+ window = nil ;
555582 }
556583
584+ [newWindow setOwner: this ];
585+ newWindow.rootViewController = controller;
586+ newWindow.hidden = ! isShowing ();
587+ newWindow.opaque = component.isOpaque ();
588+ newWindow.backgroundColor = [[UIColor blackColor ] colorWithAlphaComponent: 0 ];
589+
590+ if (component.isAlwaysOnTop ())
591+ newWindow.windowLevel = UIWindowLevelAlert;
592+
593+ window = newWindow;
594+
557595 updateScreenBounds ();
558596 }
559597
598+ void windowSceneChanged () override
599+ {
600+ updateSceneForWindow ();
601+ }
602+
560603 // ==============================================================================
561604 class AsyncRepaintMessage final : public CallbackMessage
562605 {
@@ -1768,27 +1811,12 @@ static void oldFn (UIView*) {}
17681811 r = convertToCGRect (component.getBounds ());
17691812 r.origin .y = [UIScreen mainScreen ].bounds .size .height - (r.origin .y + r.size .height );
17701813
1771- window = [[JuceUIWindow alloc ] initWithFrame: r];
1772-
1773- if (@available (iOS 13 , *))
1774- {
1775- window.windowScene = windowSceneTracker->getWindowScene ();
1776- }
1777-
1778- [((JuceUIWindow*) window) setOwner: this ];
1779-
17801814 controller = [[JuceUIViewController alloc ] init ];
17811815 controller.view = view;
1782- window.rootViewController = controller;
1783-
1784- window.hidden = true ;
1785- window.opaque = component.isOpaque ();
1786- window.backgroundColor = [[UIColor blackColor ] colorWithAlphaComponent: 0 ];
1787-
1788- if (component.isAlwaysOnTop ())
1789- window.windowLevel = UIWindowLevelAlert;
17901816
17911817 view.frame = CGRectMake (0 , 0 , r.size .width , r.size .height );
1818+
1819+ updateSceneForWindow ();
17921820 }
17931821
17941822 setTitle (component.getName ());
@@ -1811,7 +1839,7 @@ static void oldFn (UIView*) {}
18111839 [view release ];
18121840 [controller release ];
18131841
1814- if (! isSharedWindow)
1842+ if (! isSharedWindow && window != nil )
18151843 {
18161844 [((JuceUIWindow*) window) setOwner: nil ];
18171845
@@ -1825,7 +1853,7 @@ static void oldFn (UIView*) {}
18251853// ==============================================================================
18261854void UIViewComponentPeer::setVisible (bool shouldBeVisible)
18271855{
1828- if (! isSharedWindow)
1856+ if (! isSharedWindow && window != nil )
18291857 window.hidden = ! shouldBeVisible;
18301858
18311859 view.hidden = ! shouldBeVisible;
@@ -1854,7 +1882,9 @@ static void oldFn (UIView*) {}
18541882 }
18551883 else
18561884 {
1857- window.frame = convertToCGRect (newBounds);
1885+ if (window != nil )
1886+ window.frame = convertToCGRect (newBounds);
1887+
18581888 view.frame = CGRectMake (0 , 0 , (CGFloat) newBounds.getWidth (), (CGFloat) newBounds.getHeight ());
18591889
18601890 handleMovedOrResized ();
@@ -1894,7 +1924,8 @@ static void oldFn (UIView*) {}
18941924
18951925void UIViewComponentPeer::setAlpha (float newAlpha)
18961926{
1897- [view.window setAlpha: (CGFloat) newAlpha];
1927+ if (view.window != nil )
1928+ [view.window setAlpha: (CGFloat) newAlpha];
18981929}
18991930
19001931void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
@@ -1972,7 +2003,7 @@ static void oldFn (UIView*) {}
19722003
19732004bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
19742005{
1975- if (! isSharedWindow)
2006+ if (! isSharedWindow && window != nil )
19762007 window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
19772008
19782009 return true ;
0 commit comments