From d97f7f909350620f1631e5c636f7218aeaca472f Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 26 Jun 2020 15:47:00 +0200 Subject: [PATCH] app/internal/window,cmd/gogio: [iOS] export GioViewController The Gio GioAppDelegate created the GioViewController programmatically. When using gogio's -buildmode=archive users may want to use a different method (for example storyboards) but there can only be one app delegate. Move the GioAppDelegate to gogio's exe buildmode, and export the GioViewController for embedding use. Signed-off-by: Elias Naur --- app/internal/window/framework_ios.h | 4 +--- app/internal/window/os_ios.m | 25 ++----------------------- cmd/gogio/iosbuild.go | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/app/internal/window/framework_ios.h b/app/internal/window/framework_ios.h index 87b682b6..18e5a02f 100644 --- a/app/internal/window/framework_ios.h +++ b/app/internal/window/framework_ios.h @@ -2,7 +2,5 @@ #include -@interface GioAppDelegate : UIResponder -@property (strong, nonatomic) UIWindow *window; +@interface GioViewController : UIViewController @end - diff --git a/app/internal/window/os_ios.m b/app/internal/window/os_ios.m index 93f36e62..66830e40 100644 --- a/app/internal/window/os_ios.m +++ b/app/internal/window/os_ios.m @@ -11,30 +11,9 @@ @interface GioView: UIView @end -@interface GioViewController : UIViewController -@property(weak) UIScreen *screen; - -+ (UIWindow *)createWindow; -@end - -@implementation GioAppDelegate -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - self.window = [GioViewController createWindow]; - [self.window makeKeyAndVisible]; - return YES; -} -@end - @implementation GioViewController -CGFloat _keyboardHeight; -+ (UIWindow *)createWindow { - UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - GioViewController *controller = [[self alloc] initWithNibName:nil bundle:nil]; - controller.screen = window.screen; - window.rootViewController = controller; - return window; -} +CGFloat _keyboardHeight; - (void)loadView { gio_runMain(); @@ -47,7 +26,6 @@ CGFloat _keyboardHeight; #ifndef TARGET_OS_TV drawView.multipleTouchEnabled = YES; #endif - drawView.contentScaleFactor = self.screen.nativeScale; drawView.preservesSuperviewLayoutMargins = YES; drawView.layoutMargins = UIEdgeInsetsMake(0, 0, 0, 0); onCreate((__bridge CFTypeRef)drawView); @@ -156,6 +134,7 @@ NSArray *_keyCommands; name:UIWindowDidResignKeyNotification object:self.window]; } + self.contentScaleFactor = newWindow.screen.nativeScale; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onWindowDidBecomeKey:) name:UIWindowDidBecomeKeyNotification diff --git a/cmd/gogio/iosbuild.go b/cmd/gogio/iosbuild.go index b6b8eb8f..20cde3d6 100644 --- a/cmd/gogio/iosbuild.go +++ b/cmd/gogio/iosbuild.go @@ -163,6 +163,20 @@ func exeIOS(tmpDir, target, app string, bi *buildInfo) error { const mainmSrc = `@import UIKit; @import Gio; +@interface GioAppDelegate : UIResponder +@property (strong, nonatomic) UIWindow *window; +@end + +@implementation GioAppDelegate +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + GioViewController *controller = [[GioViewController alloc] initWithNibName:nil bundle:nil]; + self.window.rootViewController = controller; + [self.window makeKeyAndVisible]; + return YES; +} +@end + int main(int argc, char * argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([GioAppDelegate class]));