Skip to content

[iOS] Improve LaunchEngine implementation/API/docs#185200

Merged
cbracken merged 3 commits into
flutter:masterfrom
cbracken:launchengine-cleanup
Apr 21, 2026
Merged

[iOS] Improve LaunchEngine implementation/API/docs#185200
cbracken merged 3 commits into
flutter:masterfrom
cbracken:launchengine-cleanup

Conversation

@cbracken

@cbracken cbracken commented Apr 17, 2026

Copy link
Copy Markdown
Member

Refactors the internal state management of LaunchEngine to more idiomatic Swift, makes the possible states clear, and makes invalid states impossible: e.g. didTakeEngine == true but _engine != nil.

LaunchEngine has three valid states:

  1. .uninitialized: Initial state. The engine has not yet been created.
  2. .created: The engine has been created and is cached for future access.
  3. .taken: The engine has been transferred to a consumer, and the container is now empty.

This also refactors the engine computed property into an acquireEngine() method. In Swift and Objective-C, properties should generally be idempotent and avoid side effects. Since the engine property triggers the lazy instantiation and execution of a FlutterEngine (a pretty heavy operation), exposing it as a method better communicates the potential cost / side effects.

Also adds a bit more context to the docs that this class is an internal compatibility measure introduced as part of UISceneDelegate migration to avoid breaking the old AppDelegate-based plugin registration API.

I'll send a followup that tags this @MainActor but that should probably be its own patch.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the AI contribution guidelines and understand my responsibilities, or I am not using AI tools.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I did not list at least one issue that this PR fixes in the description above, cause mostly it just improves the existing code, or at least in my mind it does.
  • I added at least one checkbox that wasn't supposed to be here.
  • Ceci n'est pas un checklist item.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • I followed the breaking change policy and added Data Driven Fixes where supported.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@cbracken cbracken requested a review from a team as a code owner April 17, 2026 10:26
@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added platform-ios iOS applications specifically engine flutter/engine related. See also e: labels. team-ios Owned by iOS platform team labels Apr 17, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the LaunchEngine class to use a state-based lifecycle management system, replacing the engine property with an acquireEngine() method. The FlutterAppDelegate and associated tests were updated to use this new API. Review feedback highlighted logic errors in FlutterAppDelegate.mm where incorrect methods were called during the refactor, as well as stale documentation references in LaunchEngine.swift.

Comment thread engine/src/flutter/shell/platform/darwin/ios/framework/Source/LaunchEngine.swift Outdated
Comment thread engine/src/flutter/shell/platform/darwin/ios/framework/Source/LaunchEngine.swift Outdated
@cbracken

Copy link
Copy Markdown
Member Author

It looks like this pull request may not have tests.

Alrighty... flutter/cocoon#5024

@cbracken cbracken force-pushed the launchengine-cleanup branch 2 times, most recently from efe5854 to d17fa8b Compare April 17, 2026 10:34
Refactors the internal state management of `LaunchEngine` to more
idiomatic Swift, makes the possible states clear, and makes invalid
states impossible: e.g. `didTakeEngine == true` but `_engine != nil`.

LaunchEngine has three valid states:
1. Uninitialized: Initial state. The engine has not yet been created.
2. Created: The engine has been created and is cached for future access.
3. Taken: The engine has been transferred to a consumer, and the container is now empty.

This also refactors the `engine` computed property into an
`acquireEngine()` method. In Swift and Objective-C, properties should
generally be idempotent and avoid side effects. Since the engine
property triggers the lazy instantiation and execution of a
`FlutterEngine` (a pretty heavy operation), exposing it as a method
better communicates the potential cost / side effects.

This also adds a bit more context to the docs that this class is an
internal compatibility measure introduced as part of `UISceneDelegate`
migration to avoid breaking the old AppDelegate-based plugin
registration API.
@cbracken cbracken force-pushed the launchengine-cleanup branch from d17fa8b to c46ef46 Compare April 17, 2026 10:38
@cbracken cbracken added the CICD Run CI/CD label Apr 17, 2026
@cbracken cbracken requested a review from hellohuanlin April 17, 2026 11:16
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 17, 2026
@cbracken cbracken added the CICD Run CI/CD label Apr 17, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 17, 2026
@cbracken cbracken added the CICD Run CI/CD label Apr 17, 2026

@hellohuanlin hellohuanlin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@cbracken cbracken added this pull request to the merge queue Apr 20, 2026
Merged via the queue into flutter:master with commit c1c901d Apr 21, 2026
193 checks passed
@cbracken cbracken deleted the launchengine-cleanup branch April 21, 2026 00:37
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Apr 21, 2026
flutter/flutter@2844af6...3d0e822

2026-04-21 goderbauer@google.com Reland "Unpin google_mobile_ads" (flutter/flutter#180838)
2026-04-21 ishaquehassan@gmail.com fix: correct LicenseRegistry docs to reference NOTICES instead of LICENSE (flutter/flutter#184572)
2026-04-21 engine-flutter-autoroll@skia.org Roll Skia from f8637ade3d92 to a234f0ed7245 (2 revisions) (flutter/flutter#185334)
2026-04-21 engine-flutter-autoroll@skia.org Roll Skia from 3b338913f623 to f8637ade3d92 (9 revisions) (flutter/flutter#185331)
2026-04-21 kevmoo@users.noreply.github.com Fix non-minimal relative imports in flutter_tools (flutter/flutter#183971)
2026-04-21 sigurdm@google.com Reapply "Unpin sdk package dependencies" (flutter/flutter#185268)
2026-04-21 robert.ancell@canonical.com Remove unused private header (flutter/flutter#185260)
2026-04-20 chris@bracken.jp [iOS] Improve LaunchEngine implementation/API/docs (flutter/flutter#185200)
2026-04-20 41930132+hellohuanlin@users.noreply.github.com [ios][pv] Reland platform view hitTest approach (again) (flutter/flutter#185126)
2026-04-20 engine-flutter-autoroll@skia.org Roll Skia from 75c2791c6274 to 3b338913f623 (3 revisions) (flutter/flutter#185304)
2026-04-20 srawlins@google.com ignore avoid_type_to_string lint rule (flutter/flutter#184765)
2026-04-20 jacksongardner@google.com Fix race condition in modifying release manifest. (flutter/flutter#185185)
2026-04-20 jason-simmons@users.noreply.github.com In the dev/bots/analyze.dart script, obtain the relevant set of paths from Git instead of crawling the filesystem (flutter/flutter#185058)
2026-04-20 jacksongardner@google.com [wimp] Implement images for wimp. (flutter/flutter#183913)
2026-04-20 47866232+chunhtai@users.noreply.github.com add the next batch for VPAT assessment (flutter/flutter#185053)
2026-04-20 engine-flutter-autoroll@skia.org Roll Packages from c2e3d1f to 01c505f (21 revisions) (flutter/flutter#185287)
2026-04-20 jacksongardner@google.com Avoid use of direct string injection in GitHub Workflow "run" steps. (flutter/flutter#185301)
2026-04-20 bkonyi@google.com Regenerate pubspec.lock (flutter/flutter#185290)
2026-04-20 jason-simmons@users.noreply.github.com Report an error if the git ls-tree command fails in the content_aware_hash script (flutter/flutter#185170)
2026-04-20 engine-flutter-autoroll@skia.org Roll Skia from d8415c5d7b91 to 75c2791c6274 (40 revisions) (flutter/flutter#185284)
2026-04-20 bkonyi@google.com Move widget_preview_scaffold into pub workspace (flutter/flutter#185176)
2026-04-20 dacoharkes@google.com [record_use] Run build hooks and link hooks in separate targets (flutter/flutter#184880)
2026-04-20 arpitgandhi9@users.noreply.github.com feat: add reloadIsRestart to handle hot reload as a restart for web #179448 (flutter/flutter#183233)
2026-04-20 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from aDbXQm6WA0wFCAUp-... to LPa7NLiXEZP2A7IwZ... (flutter/flutter#185269)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…r#11548)

flutter/flutter@2844af6...3d0e822

2026-04-21 goderbauer@google.com Reland "Unpin google_mobile_ads" (flutter/flutter#180838)
2026-04-21 ishaquehassan@gmail.com fix: correct LicenseRegistry docs to reference NOTICES instead of LICENSE (flutter/flutter#184572)
2026-04-21 engine-flutter-autoroll@skia.org Roll Skia from f8637ade3d92 to a234f0ed7245 (2 revisions) (flutter/flutter#185334)
2026-04-21 engine-flutter-autoroll@skia.org Roll Skia from 3b338913f623 to f8637ade3d92 (9 revisions) (flutter/flutter#185331)
2026-04-21 kevmoo@users.noreply.github.com Fix non-minimal relative imports in flutter_tools (flutter/flutter#183971)
2026-04-21 sigurdm@google.com Reapply "Unpin sdk package dependencies" (flutter/flutter#185268)
2026-04-21 robert.ancell@canonical.com Remove unused private header (flutter/flutter#185260)
2026-04-20 chris@bracken.jp [iOS] Improve LaunchEngine implementation/API/docs (flutter/flutter#185200)
2026-04-20 41930132+hellohuanlin@users.noreply.github.com [ios][pv] Reland platform view hitTest approach (again) (flutter/flutter#185126)
2026-04-20 engine-flutter-autoroll@skia.org Roll Skia from 75c2791c6274 to 3b338913f623 (3 revisions) (flutter/flutter#185304)
2026-04-20 srawlins@google.com ignore avoid_type_to_string lint rule (flutter/flutter#184765)
2026-04-20 jacksongardner@google.com Fix race condition in modifying release manifest. (flutter/flutter#185185)
2026-04-20 jason-simmons@users.noreply.github.com In the dev/bots/analyze.dart script, obtain the relevant set of paths from Git instead of crawling the filesystem (flutter/flutter#185058)
2026-04-20 jacksongardner@google.com [wimp] Implement images for wimp. (flutter/flutter#183913)
2026-04-20 47866232+chunhtai@users.noreply.github.com add the next batch for VPAT assessment (flutter/flutter#185053)
2026-04-20 engine-flutter-autoroll@skia.org Roll Packages from c2e3d1f to 01c505f (21 revisions) (flutter/flutter#185287)
2026-04-20 jacksongardner@google.com Avoid use of direct string injection in GitHub Workflow "run" steps. (flutter/flutter#185301)
2026-04-20 bkonyi@google.com Regenerate pubspec.lock (flutter/flutter#185290)
2026-04-20 jason-simmons@users.noreply.github.com Report an error if the git ls-tree command fails in the content_aware_hash script (flutter/flutter#185170)
2026-04-20 engine-flutter-autoroll@skia.org Roll Skia from d8415c5d7b91 to 75c2791c6274 (40 revisions) (flutter/flutter#185284)
2026-04-20 bkonyi@google.com Move widget_preview_scaffold into pub workspace (flutter/flutter#185176)
2026-04-20 dacoharkes@google.com [record_use] Run build hooks and link hooks in separate targets (flutter/flutter#184880)
2026-04-20 arpitgandhi9@users.noreply.github.com feat: add reloadIsRestart to handle hot reload as a restart for web #179448 (flutter/flutter#183233)
2026-04-20 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from aDbXQm6WA0wFCAUp-... to LPa7NLiXEZP2A7IwZ... (flutter/flutter#185269)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-ios iOS applications specifically team-ios Owned by iOS platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants