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

Add a -[FlutterViewController launchView] property #6112

Merged
merged 2 commits into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ FLUTTER_EXPORT

- (id<FlutterPluginRegistry>)pluginRegistry;

/**
Specifies the launch view to initialize the view with. If not specified, uses a view
generated from `UILaunchStoryboardName` from the main bundle's `Info.plist` file.
*/
@property(strong, nonatomic) UIView* launchView;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about splashScreenView? IMO, the name launchView does not make the views purpose immediately clear.

Also, I would amend the docstring to say something like: "Flutters rendering is asynchronous. Due to this, the first frame rendered by the Flutter application may not immediately show up when the UIView is initially placed in the view hierarchy. This view is used a a replacement till the first frame is rendered."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add note about how the user should configure the launch/splashScreen view for multiple sizes. Saying that an autoresizing mask is applied should be sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good ideas. I've renamed all of the other launchView references to splashScreenView. (I could have just renamed the external property, but I think in the long run it's better for the naming to be consistent everywhere.)


@end

#endif // FLUTTER_FLUTTERVIEWCONTROLLER_H_
47 changes: 34 additions & 13 deletions shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -330,20 +330,19 @@ - (void)loadView {
- (void)installLaunchViewIfNecessary {
// Show the launch screen view again on top of the FlutterView if available.
// This launch screen view will be removed once the first Flutter frame is rendered.
[_launchView.get() removeFromSuperview];
_launchView.reset();
NSString* launchStoryboardName =
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"UILaunchStoryboardName"];
if (launchStoryboardName && !self.isBeingPresented && !self.isMovingToParentViewController) {
UIViewController* launchViewController =
[[UIStoryboard storyboardWithName:launchStoryboardName bundle:nil]
instantiateInitialViewController];
_launchView.reset([launchViewController.view retain]);
_launchView.get().frame = self.view.bounds;
_launchView.get().autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:_launchView.get()];
if (self.isBeingPresented || self.isMovingToParentViewController) {
[_launchView.get() removeFromSuperview];
_launchView.reset();
return;
}

// Use the property getter to initialize the default value.
UIView* launchView = self.launchView;
if (launchView == nil) {
return;
}
launchView.frame = self.view.bounds;
[self.view addSubview:launchView];
}

- (void)removeLaunchViewIfPresent {
Expand Down Expand Up @@ -387,6 +386,28 @@ - (void)installLaunchViewCallback {
});
}

#pragma mark - Properties

- (UIView*)launchView {
if (_launchView == nullptr) {
NSString* launchStoryboardName =
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"UILaunchStoryboardName"];
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:launchStoryboardName bundle:nil];
if (storyboard == nil) {
return nil;
}
UIViewController* launchViewController = [storyboard instantiateInitialViewController];
self.launchView = launchViewController.view;
}
return _launchView.get();
}

- (void)setLaunchView:(UIView*)view {
_launchView.reset([view retain]);
_launchView.get().autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}

#pragma mark - Surface creation and teardown updates

- (void)surfaceUpdated:(BOOL)appeared {
Expand Down