From fdec8d726d209ec0510590b84b7f4ee475a631a0 Mon Sep 17 00:00:00 2001 From: Sergey Minakov Date: Mon, 27 Jul 2020 15:04:13 +0300 Subject: [PATCH] iOS: Use storyboard as loading screen If 'Launch Screen' storyboard is present it will be used as loading screen. --- platform/iphone/godot_view.h | 8 +++++++ platform/iphone/godot_view.mm | 9 ++++++++ platform/iphone/view_controller.mm | 36 +++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/platform/iphone/godot_view.h b/platform/iphone/godot_view.h index a41ae54d69bf..759e21fe55b5 100644 --- a/platform/iphone/godot_view.h +++ b/platform/iphone/godot_view.h @@ -37,12 +37,20 @@ class String; +@class GodotView; @protocol DisplayLayer; @protocol GodotViewRendererProtocol; +@protocol GodotViewDelegate + +- (BOOL)godotViewFinishedSetup:(GodotView *)view; + +@end + @interface GodotView : UIView @property(assign, nonatomic) id renderer; +@property(assign, nonatomic) id delegate; @property(assign, readonly, nonatomic) BOOL isActive; diff --git a/platform/iphone/godot_view.mm b/platform/iphone/godot_view.mm index 72c6a33fbe14..893a444bca60 100644 --- a/platform/iphone/godot_view.mm +++ b/platform/iphone/godot_view.mm @@ -113,6 +113,7 @@ - (void)dealloc { [self stopRendering]; self.renderer = nil; + self.delegate = nil; if (self.renderingLayer) { [self.renderingLayer removeFromSuperlayer]; @@ -235,6 +236,14 @@ - (void)drawView { return; } + if (self.delegate) { + BOOL delegateFinishedSetup = [self.delegate godotViewFinishedSetup:self]; + + if (!delegateFinishedSetup) { + return; + } + } + [self handleMotion]; [self.renderer renderOnView:self]; diff --git a/platform/iphone/view_controller.mm b/platform/iphone/view_controller.mm index c047579a17bc..70715e32f666 100644 --- a/platform/iphone/view_controller.mm +++ b/platform/iphone/view_controller.mm @@ -37,12 +37,14 @@ #import "native_video_view.h" #include "os_iphone.h" -@interface ViewController () +@interface ViewController () @property(strong, nonatomic) GodotViewRenderer *renderer; @property(strong, nonatomic) GodotNativeVideoView *videoView; @property(strong, nonatomic) GodotKeyboardInputView *keyboardView; +@property(strong, nonatomic) UIView *godotLoadingOverlay; + @end @implementation ViewController @@ -61,6 +63,7 @@ - (void)loadView { self.view = view; view.renderer = self.renderer; + view.delegate = self; } - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { @@ -96,6 +99,7 @@ - (void)viewDidLoad { [super viewDidLoad]; [self observeKeyboard]; + [self displayLoadingOverlay]; if (@available(iOS 11.0, *)) { [self setNeedsUpdateOfScreenEdgesDeferringSystemGestures]; @@ -120,6 +124,31 @@ - (void)observeKeyboard { object:nil]; } +- (void)displayLoadingOverlay { + NSBundle *bundle = [NSBundle mainBundle]; + NSString *storyboardName = @"Launch Screen"; + + if ([bundle pathForResource:storyboardName ofType:@"storyboardc"] == nil) { + return; + } + + UIStoryboard *launchStoryboard = [UIStoryboard storyboardWithName:storyboardName bundle:bundle]; + + UIViewController *controller = [launchStoryboard instantiateInitialViewController]; + self.godotLoadingOverlay = controller.view; + self.godotLoadingOverlay.frame = self.view.bounds; + self.godotLoadingOverlay.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; + + [self.view addSubview:self.godotLoadingOverlay]; +} + +- (BOOL)godotViewFinishedSetup:(GodotView *)view { + [self.godotLoadingOverlay removeFromSuperview]; + self.godotLoadingOverlay = nil; + + return YES; +} + - (void)dealloc { [self.videoView stopVideo]; self.videoView = nil; @@ -128,6 +157,11 @@ - (void)dealloc { self.renderer = nil; + if (self.godotLoadingOverlay) { + [self.godotLoadingOverlay removeFromSuperview]; + self.godotLoadingOverlay = nil; + } + [[NSNotificationCenter defaultCenter] removeObserver:self]; }