-
Notifications
You must be signed in to change notification settings - Fork 6k
Added a default entrypoint variable to match android syntax. #12370
Changes from all commits
fc0da29
bc34054
ad2cf30
141e758
1c5de8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -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 | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure you want to allow
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like the interface and I don't like the use of nil as placeholders for future calculations either. In this PR I've tried to make it so no one ever has to mention a nil to create or run an Engine. Truly eliminating the use of nil will require some excavation, a breaking change and some philosophy debates. I've avoided that to make some concrete progress on the issue.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. |
||||
| * 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; | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not familiar with how things are packaged at the binary level in iOS, but do we not need a configurable bundle path along with the function name? The entrypoint on Android has both pieces in a data structure called DartEntrypoint...
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason that's separated? Is the goal of this change to match Android? If so, shouldn't that involve pairing the entrypoint with the bundle path? The entrypoint only exists in a specific bundle, so if we think it's legitimate to lazily choose the entrypoint method, then it seems like you should be able to lazily choose the bundle path, right?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's a legitimate point. What you are proposing is a breaking change though. The idea with this PR is it gets us closer to Android without breaking. We can see what @xster thinks. I'd say that could be a different PR though.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can see what @xster says, but seems like we could introduce a new constructor and a new dart entrypoint setter method, then soft deprecate the existing ones. That wouldn't be a breaking change, but it would move us forward for the future.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That DartEntrypoint contains 2 fields: an entrypoint function and a bundle path:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ya, we're in kind of a pickle. The Android engine constructor doesn't ask for anything and everything's provided by the dart executor's execute. The iOS engine asks for half of the stuff during init and the other half during run. I think the ideal solution is probably:
It looks like _dartProject is only ever used in the launchEngine method in the FlutterEngine so moving it implementation wise shouldn't alter too much. The break would be ok (but still needs announcing) since the only valid use of that API is add-to-app currently and we never shipped add-to-app yet.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I'll look into making this a bit deeper. If you want the API's to be closer though, shouldn't we introduce a class called FlutterDartEntrypoint in objc and make a method on
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depends on how ambitious you want to get. If you want to go big, you can do flutter/flutter#33099 at the same time :)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unable to add the bundle to the run arguments. This would negatively affect our app launch time for full flutter apps since the engine is created and There are still a few things I can do to make working with the FlutterEngine nicer though. I'll do everything but move the bundle to run/launch arguments. |
||||
|
|
@@ -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. | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: is it
main()ormain? The Android embedding seems to use justmainengine/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java
Line 202 in fde7c8c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm that the literal value on Android is just the name of the function, no
(). For the purpose of documentation it might be useful to represent it as "main()" for clarity.