From cc544160e49d7190ae6b41e8458cac4f8be4d283 Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Fri, 24 Apr 2026 23:10:55 +0300 Subject: [PATCH] Another attempt to fix iPad restart Form size issue Fixed #4767 --- .../nativeSources/CodenameOne_GLAppDelegate.m | 15 +++++---------- .../nativeSources/CodenameOne_GLViewController.m | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Ports/iOSPort/nativeSources/CodenameOne_GLAppDelegate.m b/Ports/iOSPort/nativeSources/CodenameOne_GLAppDelegate.m index 55caf784b4..4f71d16772 100644 --- a/Ports/iOSPort/nativeSources/CodenameOne_GLAppDelegate.m +++ b/Ports/iOSPort/nativeSources/CodenameOne_GLAppDelegate.m @@ -241,19 +241,14 @@ - (void)cn1ApplicationWillEnterForeground if (cn1IsHiddenInBackground) { [[CodenameOne_GLViewController instance] eaglView].hidden = NO; } + // Clear before updateCanvas: viewWillTransitionToSize: and + // didRotateFromInterfaceOrientation: use this to skip propagation during + // iOS's snapshot-phase orientation flip on iPad between stop and start. + isAppSuspended = NO; com_codename1_impl_ios_IOSImplementation_applicationWillEnterForeground__(CN1_THREAD_GET_STATE_PASS_SINGLE_ARG); CodenameOne_GLViewController* vc = [CodenameOne_GLViewController instance]; if (vc != nil) { - // Defer updateCanvas by one run-loop cycle so that UIKit has a chance to - // settle the root view bounds after foreground transition. Calling this - // too early can report the short edge for width/height on iPad, which - // causes a transient wrong screen-size event between stop/start. - dispatch_async(dispatch_get_main_queue(), ^{ - CodenameOne_GLViewController* deferredVc = [CodenameOne_GLViewController instance]; - if (deferredVc != nil) { - [deferredVc updateCanvas:YES]; - } - }); + [vc updateCanvas:YES]; } } diff --git a/Ports/iOSPort/nativeSources/CodenameOne_GLViewController.m b/Ports/iOSPort/nativeSources/CodenameOne_GLViewController.m index 53edd34858..6db7066182 100644 --- a/Ports/iOSPort/nativeSources/CodenameOne_GLViewController.m +++ b/Ports/iOSPort/nativeSources/CodenameOne_GLViewController.m @@ -158,6 +158,7 @@ JAVA_INT getSafeTop() { BOOL firstTime = YES; BOOL retinaBug; float scaleValue = 1; +extern BOOL isAppSuspended; static void updateDisplayMetricsFromView(UIView *view) { if (view == nil) { @@ -2726,7 +2727,13 @@ - (UIInterfaceOrientationMask)supportedInterfaceOrientations { } -(void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { - + // iOS fires this during its background snapshot pass on iPad with the + // opposite-orientation size. Publishing that would deliver a swapped + // screenSizeChanged to the EDT between stop and start. + if (isAppSuspended) { + return; + } + if(editingComponent != nil) { // Since willRotateToInterfaceOrientation is deprecated, newer versions (tested 11.3) // don't call it anymore on rotation. @@ -2789,7 +2796,10 @@ - (void)viewSafeAreaInsetsDidChange { } -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { - + if (isAppSuspended) { + return; + } + [[self eaglView] updateFrameBufferSize:(int)self.view.bounds.size.width h:(int)self.view.bounds.size.height]; [[self eaglView] deleteFramebuffer];