From 34bc3757057cbf679cdc861f48a1867e23140d9e Mon Sep 17 00:00:00 2001 From: jaypaik Date: Sun, 22 Feb 2026 13:19:21 -0500 Subject: [PATCH] iOS: Propagate VC UI preferences to SwiftUI hosting controller The SwiftUI lifecycle wraps GDTViewController in a hosting controller that becomes the window's root VC. iOS queries the root VC for preferredScreenEdgesDeferringSystemGestures, prefersHomeIndicatorAutoHidden, and prefersStatusBarHidden, but the hosting controller doesn't delegate these to child VCs. This propagates the preference implementations onto the root VC's class at runtime using class_addMethod. (cherry picked from commit 0c8c425f9be73b3ff43b96e9998edb3608b743a0) --- .../apple_embedded/godot_view_controller.mm | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/apple_embedded/godot_view_controller.mm b/drivers/apple_embedded/godot_view_controller.mm index 0134d718cfc..0bb2ee39b8a 100644 --- a/drivers/apple_embedded/godot_view_controller.mm +++ b/drivers/apple_embedded/godot_view_controller.mm @@ -42,6 +42,7 @@ #import #import +#import @interface GDTViewController () @@ -172,6 +173,9 @@ - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self.godotView startRendering]; +#ifdef IOS_ENABLED + [self propagateUIPreferencesToRootViewController]; +#endif } - (void)viewDidDisappear:(BOOL)animated { @@ -237,6 +241,35 @@ [[NSNotificationCenter defaultCenter] removeObserver:self]; } +// Propagate UI preferences to the root VC (the SwiftUI hosting controller doesn't delegate these). +#ifdef IOS_ENABLED +- (void)propagateUIPreferencesToRootViewController { + UIViewController *rootVC = self.view.window.rootViewController; + if (!rootVC || rootVC == self) { + return; + } + + Class rootClass = [rootVC class]; + + SEL selectors[] = { + @selector(preferredScreenEdgesDeferringSystemGestures), + @selector(prefersHomeIndicatorAutoHidden), + @selector(prefersStatusBarHidden), + }; + + for (SEL sel : selectors) { + Method method = class_getInstanceMethod([GDTViewController class], sel); + if (!class_addMethod(rootClass, sel, method_getImplementation(method), method_getTypeEncoding(method))) { + method_setImplementation(class_getInstanceMethod(rootClass, sel), method_getImplementation(method)); + } + } + + [rootVC setNeedsUpdateOfScreenEdgesDeferringSystemGestures]; + [rootVC setNeedsUpdateOfHomeIndicatorAutoHidden]; + [rootVC setNeedsStatusBarAppearanceUpdate]; +} +#endif + // MARK: Orientation #ifdef IOS_ENABLED