mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 02:15:34 +00:00
app/internal/window: [iOS] move logic out of GioAppDelegate
We'd like to remove GioAppDelegate when Gio is embedded with gogio's -buildmode=archive. Minimize the code in GioAppDelegate. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -309,3 +309,8 @@ func NewWindow(win Callbacks, opts *Options) error {
|
|||||||
|
|
||||||
func Main() {
|
func Main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export gio_runMain
|
||||||
|
func gio_runMain() {
|
||||||
|
runMain()
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,45 +13,32 @@
|
|||||||
|
|
||||||
@interface GioViewController : UIViewController
|
@interface GioViewController : UIViewController
|
||||||
@property(weak) UIScreen *screen;
|
@property(weak) UIScreen *screen;
|
||||||
|
|
||||||
|
+ (UIWindow *)createWindow;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation GioAppDelegate
|
@implementation GioAppDelegate
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||||
gio_runMain();
|
self.window = [GioViewController createWindow];
|
||||||
|
[self.window makeKeyAndVisible];
|
||||||
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
|
||||||
GioViewController *controller = [[GioViewController alloc] initWithNibName:nil bundle:nil];
|
|
||||||
controller.screen = self.window.screen;
|
|
||||||
self.window.rootViewController = controller;
|
|
||||||
[self.window makeKeyAndVisible];
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
|
||||||
GioViewController *vc = (GioViewController *)self.window.rootViewController;
|
|
||||||
UIView *drawView = vc.view.subviews[0];
|
|
||||||
if (drawView != nil) {
|
|
||||||
onStop((__bridge CFTypeRef)drawView);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
|
||||||
GioViewController *c = (GioViewController*)self.window.rootViewController;
|
|
||||||
UIView *drawView = c.view.subviews[0];
|
|
||||||
if (drawView != nil) {
|
|
||||||
CFTypeRef viewRef = (__bridge CFTypeRef)drawView;
|
|
||||||
gio_onDraw(viewRef);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation GioViewController
|
@implementation GioViewController
|
||||||
CGFloat _keyboardHeight;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)loadView {
|
- (void)loadView {
|
||||||
|
gio_runMain();
|
||||||
|
|
||||||
CGRect zeroFrame = CGRectMake(0, 0, 0, 0);
|
CGRect zeroFrame = CGRectMake(0, 0, 0, 0);
|
||||||
self.view = [[UIView alloc] initWithFrame:zeroFrame];
|
self.view = [[UIView alloc] initWithFrame:zeroFrame];
|
||||||
self.view.layoutMargins = UIEdgeInsetsMake(0, 0, 0, 0);
|
self.view.layoutMargins = UIEdgeInsetsMake(0, 0, 0, 0);
|
||||||
@@ -76,6 +63,28 @@ CGFloat _keyboardHeight;
|
|||||||
selector:@selector(keyboardWillHide:)
|
selector:@selector(keyboardWillHide:)
|
||||||
name:UIKeyboardWillHideNotification
|
name:UIKeyboardWillHideNotification
|
||||||
object:nil];
|
object:nil];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver: self
|
||||||
|
selector: @selector(applicationDidEnterBackground:)
|
||||||
|
name: UIApplicationDidEnterBackgroundNotification
|
||||||
|
object: nil];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver: self
|
||||||
|
selector: @selector(applicationWillEnterForeground:)
|
||||||
|
name: UIApplicationWillEnterForegroundNotification
|
||||||
|
object: nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||||
|
UIView *drawView = self.view.subviews[0];
|
||||||
|
if (drawView != nil) {
|
||||||
|
gio_onDraw((__bridge CFTypeRef)drawView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||||
|
UIView *drawView = self.view.subviews[0];
|
||||||
|
if (drawView != nil) {
|
||||||
|
onStop((__bridge CFTypeRef)drawView);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidDisappear:(BOOL)animated {
|
- (void)viewDidDisappear:(BOOL)animated {
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
// SPDX-License-Identifier: Unlicense OR MIT
|
|
||||||
|
|
||||||
// +build darwin,ios
|
|
||||||
|
|
||||||
package window
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
//export gio_runMain
|
|
||||||
func gio_runMain() {
|
|
||||||
runMain()
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user