未验证 提交 92d30c0c 编写于 作者: G gaaclarke 提交者: GitHub

Added a default entrypoint variable to match android syntax. (#12370)

Made creating and using a FlutterEngine a bit easier, to try to get it get it as easy to use as Android's equivalent.
* Added a default entrypoint variable.
* I added `run` to and `initWithName:` to FlutterEngine.
上级 84c167d8
......@@ -18,6 +18,12 @@
NS_ASSUME_NONNULL_BEGIN
/**
* The dart entrypoint that is associated with `main()`. This is to be used as an argument to the
* `runWithEntrypoint*` methods.
*/
extern NSString* const FlutterDefaultDartEntrypoint;
/**
* The FlutterEngine class coordinates a single instance of execution for a
* `FlutterDartProject`. It may have zero or one `FlutterViewController` at a
......@@ -41,6 +47,26 @@ NS_ASSUME_NONNULL_BEGIN
*/
FLUTTER_EXPORT
@interface FlutterEngine : NSObject <FlutterTextureRegistry, FlutterPluginRegistry>
/**
* Initialize this FlutterEngine.
*
* The engine will execute the project located in the bundle with the identifier
* "io.flutter.flutter.app" (the default for Flutter projects).
*
* A newly initialized engine will not run until either `-runWithEntrypoint:` or
* `-runWithEntrypoint:libraryURI:` is called.
*
* FlutterEngine created with this method will have allowHeadlessExecution set to `YES`.
* This means that the engine will continue to run regardless of whether a `FlutterViewController`
* is attached to it or not, until `-destroyContext:` is called or the process finishes.
*
* @param labelPrefix The label prefix used to identify threads for this instance. Should
* be unique across FlutterEngine instances, and is used in instrumentation to label
* the threads used by this FlutterEngine.
*/
- (instancetype)initWithName:(NSString*)labelPrefix;
/**
* Initialize this FlutterEngine with a `FlutterDartProject`.
*
......@@ -91,6 +117,17 @@ FLUTTER_EXPORT
+ (instancetype)new NS_UNAVAILABLE;
/**
* Runs a Dart program on an Isolate from the main Dart library (i.e. the library that
* contains `main()`), using `main()` as the entrypoint (the default for Flutter projects).
*
* The first call to this method will create a new Isolate. Subsequent calls will return
* immediately.
*
* @return YES if the call succeeds in creating and running a Flutter Engine instance; NO otherwise.
*/
- (BOOL)run;
/**
* Runs a Dart program on an Isolate from the main Dart library (i.e. the library that
* contains `main()`).
......@@ -99,10 +136,10 @@ FLUTTER_EXPORT
* immediately.
*
* @param entrypoint The name of a top-level function from the same Dart
* library that contains the app's main() function. If this is nil, it will
* default to `main()`. If it is not the app's main() function, that function
* must be decorated with `@pragma(vm:entry-point)` to ensure the method is not
* tree-shaken by the Dart compiler.
* library that contains the app's main() function. If this is FlutterDefaultDartEntrypoint (or
* nil) it will default to `main()`. If it is not the app's main() function, that function must
* be decorated with `@pragma(vm:entry-point)` to ensure the method is not tree-shaken by the Dart
* compiler.
* @return YES if the call succeeds in creating and running a Flutter Engine instance; NO otherwise.
*/
- (BOOL)runWithEntrypoint:(nullable NSString*)entrypoint;
......@@ -114,10 +151,10 @@ FLUTTER_EXPORT
* The first call to this method will create a new Isolate. Subsequent calls will return
* immediately.
*
* @param entrypoint The name of a top-level function from a Dart library. If nil, this will
* default to `main()`. If it is not the app's main() function, that function
* must be decorated with `@pragma(vm:entry-point)` to ensure the method is not
* tree-shaken by the Dart compiler.
* @param entrypoint The name of a top-level function from a Dart library. If this is
* FlutterDefaultDartEntrypoint (or nil); this will default to `main()`. If it is not the app's
* main() function, that function must be decorated with `@pragma(vm:entry-point)` to ensure the
* method is not tree-shaken by the Dart compiler.
* @param uri The URI of the Dart library which contains the entrypoint method. IF nil,
* this will default to the same library as the `main()` function in the Dart program.
* @return YES if the call succeeds in creating and running a Flutter Engine instance; NO otherwise.
......
......@@ -27,6 +27,8 @@
#import "flutter/shell/platform/darwin/ios/ios_surface.h"
#import "flutter/shell/platform/darwin/ios/platform_view_ios.h"
NSString* const FlutterDefaultDartEntrypoint = nil;
@interface FlutterEngine () <FlutterTextInputDelegate, FlutterBinaryMessenger>
// Maintains a dictionary of plugin names that have registered with the engine. Used by
// FlutterEngineRegistrar to implement a FlutterPluginRegistrar.
......@@ -70,6 +72,10 @@
FlutterBinaryMessengerRelay* _binaryMessenger;
}
- (instancetype)initWithName:(NSString*)labelPrefix {
return [self initWithName:labelPrefix project:nil allowHeadlessExecution:YES];
}
- (instancetype)initWithName:(NSString*)labelPrefix project:(FlutterDartProject*)project {
return [self initWithName:labelPrefix project:project allowHeadlessExecution:YES];
}
......@@ -429,6 +435,10 @@
return _shell != nullptr;
}
- (BOOL)run {
return [self runWithEntrypoint:FlutterDefaultDartEntrypoint libraryURI:nil];
}
- (BOOL)runWithEntrypoint:(NSString*)entrypoint libraryURI:(NSString*)libraryURI {
if ([self createShell:entrypoint libraryURI:libraryURI]) {
[self launchEngine:entrypoint libraryURI:libraryURI];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册