Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] [iOS] Native loading screen implementation #40766

Merged
merged 1 commit into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions platform/iphone/godot_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@

class String;

@class GodotView;
@protocol DisplayLayer;
@protocol GodotViewRendererProtocol;

@protocol GodotViewDelegate

- (BOOL)godotViewFinishedSetup:(GodotView *)view;

@end

@interface GodotView : UIView

@property(assign, nonatomic) id<GodotViewRendererProtocol> renderer;
@property(assign, nonatomic) id<GodotViewDelegate> delegate;

@property(assign, readonly, nonatomic) BOOL isActive;

Expand Down
9 changes: 9 additions & 0 deletions platform/iphone/godot_view.mm
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ - (void)dealloc {
[self stopRendering];

self.renderer = nil;
self.delegate = nil;

if (self.renderingLayer) {
[self.renderingLayer removeFromSuperlayer];
Expand Down Expand Up @@ -241,6 +242,14 @@ - (void)drawView {
return;
}

if (self.delegate) {
BOOL delegateFinishedSetup = [self.delegate godotViewFinishedSetup:self];

if (!delegateFinishedSetup) {
return;
}
}

[self handleMotion];
[self.renderer renderOnView:self];
}
Expand Down
36 changes: 35 additions & 1 deletion platform/iphone/view_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
#import <AVFoundation/AVFoundation.h>
#import <GameController/GameController.h>

@interface ViewController ()
@interface ViewController () <GodotViewDelegate>

@property(strong, nonatomic) GodotViewRenderer *renderer;
@property(strong, nonatomic) GodotNativeVideoView *videoView;
@property(strong, nonatomic) GodotKeyboardInputView *keyboardView;

@property(strong, nonatomic) UIView *godotLoadingOverlay;

@end

@implementation ViewController
Expand All @@ -62,6 +64,7 @@ - (void)loadView {
self.view = view;

view.renderer = self.renderer;
view.delegate = self;
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
Expand Down Expand Up @@ -97,6 +100,7 @@ - (void)viewDidLoad {
[super viewDidLoad];

[self observeKeyboard];
[self displayLoadingOverlay];

if (@available(iOS 11.0, *)) {
[self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
Expand All @@ -121,6 +125,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];

Expand All @@ -130,6 +159,11 @@ - (void)dealloc {

self.renderer = nil;

if (self.godotLoadingOverlay) {
[self.godotLoadingOverlay removeFromSuperview];
self.godotLoadingOverlay = nil;
}

[[NSNotificationCenter defaultCenter] removeObserver:self];
}

Expand Down