mirror of
https://github.com/godotengine/godot.git
synced 2026-05-12 22:35:35 +00:00
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 0c8c425f9b)
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import <GameController/GameController.h>
|
||||
#import <objc/runtime.h>
|
||||
|
||||
@interface GDTViewController () <GDTViewDelegate>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user