Skip to content

Commit

Permalink
Deprecate -[FlutterDartProject initFromDefaultSourceForConfiguration] (
Browse files Browse the repository at this point in the history
…flutter#18886) (flutter#5858)

* Deprecate -[FlutterDartProject initFromDefaultSourceForConfiguration] (flutter#18886)

`-[FlutterDartProject initFromDefaultSourceForConfiguration]` no
longer seems very useful.  It calls `-initWithPrecompiledDartBundle:`
or `-initWithFlutterAssets:dartMain:packages:`, but since it now
passes `nil` for all arguments, both paths end up doing the same
thing.

Additionally, `-initFromDefaultSourceForConfiguration` is awkward to
use in Swift.  The automatically generated Swift interface is:

    public convenience init!(fromDefaultSourceForConfiguration: ())

and it's not obvious how to call that.

Let's deprecate `-initFromDefaultSourceForConfiguration` and instead
expect callers to use the existing `-init` method. (We can make
`-init` do different things for different build configurations later
if necessary.)

Bonus: Rename some parameters to make it more obvious when they may
be `nil`.
  • Loading branch information
jamesderlin authored and chinmaygarde committed Jul 31, 2018
1 parent 3e6b681 commit d06e9e8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
3 changes: 3 additions & 0 deletions shell/platform/darwin/ios/framework/Headers/Flutter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
/**
BREAKING CHANGES:
July 26, 2018: Marked -[FlutterDartProject
initFromDefaultSourceForConfiguration] deprecated.
February 28, 2018: Removed "initWithFLXArchive" and
"initWithFLXArchiveWithScriptSnapshot".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ FLUTTER_EXPORT
- (instancetype)initWithFlutterAssetsWithScriptSnapshot:(NSURL*)flutterAssetsURL
NS_DESIGNATED_INITIALIZER;

- (instancetype)initFromDefaultSourceForConfiguration;
- (instancetype)initFromDefaultSourceForConfiguration FLUTTER_DEPRECATED("Use -init instead.");

/**
Returns the file name for the given asset.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
#include "FlutterTexture.h"

FLUTTER_EXPORT
@interface FlutterViewController : UIViewController<FlutterBinaryMessenger, FlutterTextureRegistry, FlutterPluginRegistry>
@interface FlutterViewController
: UIViewController <FlutterBinaryMessenger, FlutterTextureRegistry, FlutterPluginRegistry>

- (instancetype)initWithProject:(FlutterDartProject*)project
- (instancetype)initWithProject:(FlutterDartProject*)projectOrNil
nibName:(NSString*)nibNameOrNil
bundle:(NSBundle*)nibBundleOrNil NS_DESIGNATED_INITIALIZER;

Expand Down
15 changes: 7 additions & 8 deletions shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,12 @@ - (instancetype)initWithFlutterAssets:(NSURL*)flutterAssetsURL
if (self) {
_settings = DefaultSettingsForProcess();

if ([[NSFileManager defaultManager] fileExistsAtPath:dartMainURL.path]) {
if (dartMainURL != nil && [[NSFileManager defaultManager] fileExistsAtPath:dartMainURL.path]) {
_settings.main_dart_file_path = dartMainURL.path.UTF8String;
}

if ([[NSFileManager defaultManager] fileExistsAtPath:dartPackages.path]) {
if (dartPackages.path != nil &&
[[NSFileManager defaultManager] fileExistsAtPath:dartPackages.path]) {
_settings.packages_file_path = dartPackages.path.UTF8String;
}
}
Expand All @@ -176,7 +177,8 @@ - (instancetype)initWithFlutterAssetsWithScriptSnapshot:(NSURL*)flutterAssetsURL
if (self) {
_settings = DefaultSettingsForProcess();

if ([[NSFileManager defaultManager] fileExistsAtPath:flutterAssetsURL.path]) {
if (flutterAssetsURL != nil &&
[[NSFileManager defaultManager] fileExistsAtPath:flutterAssetsURL.path]) {
_settings.assets_path = flutterAssetsURL.path.UTF8String;

NSURL* scriptSnapshotPath =
Expand All @@ -192,12 +194,9 @@ - (instancetype)initWithFlutterAssetsWithScriptSnapshot:(NSURL*)flutterAssetsURL

#pragma mark - Convenience initializers

// Exists for backward-compatibility. Expect this to be removed.
- (instancetype)initFromDefaultSourceForConfiguration {
if (blink::DartVM::IsRunningPrecompiledCode()) {
return [self initWithPrecompiledDartBundle:nil];
} else {
return [self initWithFlutterAssets:nil dartMain:nil packages:nil];
}
return [self init];
}

- (const blink::Settings&)settings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ - (void)runWithEntrypointAndCallback:(NSString*)entrypoint
return;
}

FlutterDartProject* project =
[[[FlutterDartProject alloc] initFromDefaultSourceForConfiguration] autorelease];
FlutterDartProject* project = [[[FlutterDartProject alloc] init] autorelease];

auto config = project.runConfiguration;
config.SetEntrypointAndLibrary(entrypoint.UTF8String, uri.UTF8String);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ @implementation FlutterViewController {

#pragma mark - Manage and override all designated initializers

- (instancetype)initWithProject:(FlutterDartProject*)project
- (instancetype)initWithProject:(FlutterDartProject*)projectOrNil
nibName:(NSString*)nibNameOrNil
bundle:(NSBundle*)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) {
if (project == nil)
_dartProject.reset([[FlutterDartProject alloc] initFromDefaultSourceForConfiguration]);
if (projectOrNil == nil)
_dartProject.reset([[FlutterDartProject alloc] init]);
else
_dartProject.reset([project retain]);
_dartProject.reset([projectOrNil retain]);

[self performCommonViewControllerInitialization];
}
Expand Down

0 comments on commit d06e9e8

Please sign in to comment.