Skip to content

Conversation

@LouiseHsu
Copy link
Contributor

This is a reland of #177410

The previous pr was hitting deadlocks with tests that use screenshots. This reland fixes it by submitting frames asynchronously instead of synchronously.

This PR fixes #169147

This is the iOS implementation of #149033

In Add-to-App scenarios, a common desired use case is to have the embedded FlutterView be able to size itself based on it's content. Up till now, the size had to be manually specified, which can be tedious and inaccurate.

This PR adds a new flag, isAutoResizable, which enables the ability for the embedded flutter view to dynamically set it's own size based off it's content. Note that this feature will NOT work if the the embedded app is wrapped in flexible or unsized widgets, such as Scaffold. The FlutterView will just not display at all.

To use the new flag, just set it like

flutterViewController.autoResizable = true;

or in Swift

flutterViewController.isAutoResizable = true

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • 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 listed at least one issue that this PR fixes in the description above.
  • 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.

@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 Nov 26, 2025
Copy link
Contributor

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

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 relands dynamic content resizing for iOS, introducing an isAutoResizable flag on FlutterViewController. This allows an embedded Flutter view to size itself based on its content. The implementation uses custom layout constraints and asynchronous frame submission to prevent deadlocks that were an issue in a previous attempt. The changes include new integration and UI tests to validate this functionality. My review identifies a critical crash risk, a potential retain cycle, and several opportunities to improve code maintainability and style.

Comment on lines 57 to 58
CGFloat scale = self.window.windowScene.screen.scale;
CGSize scaledSize = CGSizeMake(size.width / scale, size.height / scale);
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

Accessing self.window.windowScene.screen.scale can cause a crash if self.window is nil, which can happen if the view is not yet part of a window hierarchy. You should add a check to ensure self.window is not nil before accessing its properties.

Suggested change
CGFloat scale = self.window.windowScene.screen.scale;
CGSize scaledSize = CGSizeMake(size.width / scale, size.height / scale);
UIWindow* window = self.window;
if (!window) {
return;
}
CGFloat scale = window.windowScene.screen.scale;
CGSize scaledSize = CGSizeMake(size.width / scale, size.height / scale);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why didnt you have these thoughts in the original pr

Copy link
Member

Choose a reason for hiding this comment

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

I think this is a valid concern. I don't like returning nothing though. Can we instead use self.traitCollection.displayScale to get the scale?

Copy link
Contributor Author

@LouiseHsu LouiseHsu Nov 26, 2025

Choose a reason for hiding this comment

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

tbf this is a void function - maybe an error msg abt the view not being part of a window yet instead?

Copy link
Member

Choose a reason for hiding this comment

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

No, I don't like that because when you "set" something it should set it or provide some way to know programmatically that it wasn't set.

Do you not like the idea of getting self.traitCollection.displayScale or if self.window ? self.window.windowScene.screen.scale : self.traitCollection.displayScale?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, gotcha.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

Looking good, i think the bot had a few good comments. I've noted where it had a point and I have one cleanup note that should happen now that we are using RunNowOrPostTask.

if (self.flutterView == nil || (self.compositionOrder.empty() && !self.hadPlatformViews)) {
// No platform views to render but the FlutterView may need to be resized.
if (self.flutterView != nil) {
if (self.platformTaskRunner->RunsTasksOnCurrentThread()) {
Copy link
Member

Choose a reason for hiding this comment

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

This check is no longer necessary, RunNowOrPostTask is doing this for us.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

You forgot to push the commit methinks =)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oopssss

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

lgtm! round 2, fight!

@LouiseHsu LouiseHsu added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 26, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Nov 26, 2025

autosubmit label was removed for flutter/flutter/179153, because - The status or check suite Mac mac_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 26, 2025
@LouiseHsu LouiseHsu added the autosubmit Merge PR when tree becomes green via auto submit App label Dec 1, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Dec 2, 2025

autosubmit label was removed for flutter/flutter/179153, because - The status or check suite Windows tool_tests_commands has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Dec 2, 2025
@LouiseHsu LouiseHsu added the autosubmit Merge PR when tree becomes green via auto submit App label Dec 2, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Dec 2, 2025
Merged via the queue into flutter:master with commit 1bf445b Dec 2, 2025
182 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Dec 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 3, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Dec 3, 2025
flutter/flutter@5545bb3...e274574

2025-12-03 [email protected] Roll Skia from 20829e37dfb8 to db4c79d41513 (1 revision) (flutter/flutter#179401)
2025-12-03 [email protected] Roll Skia from adc7ea94cada to 20829e37dfb8 (6 revisions) (flutter/flutter#179385)
2025-12-03 [email protected] Refactor GetShaderClipDepth for clarity (flutter/flutter#179110)
2025-12-03 [email protected] Roll Skia from 3b339a83959b to adc7ea94cada (1 revision) (flutter/flutter#179376)
2025-12-03 [email protected] Roll Dart SDK from eb743a1d4ade to 0bb365d7ac74 (7 revisions) (flutter/flutter#179372)
2025-12-03 [email protected] feat: Add `mainAxisExtent` parameter to `GridView` constructors (flutter/flutter#176927)
2025-12-03 [email protected] Roll Skia from eb01fff20df8 to 3b339a83959b (4 revisions) (flutter/flutter#179371)
2025-12-02 [email protected] Fix crash when text editing value changes between scrolls (flutter/flutter#179163)
2025-12-02 [email protected] Roll Skia from 6bd3b06b1e08 to eb01fff20df8 (3 revisions) (flutter/flutter#179362)
2025-12-02 [email protected] Adds Impellerc flatbuffer format versioning. (flutter/flutter#175470)
2025-12-02 [email protected] Adds format argument to Picture.toImageSync (flutter/flutter#178691)
2025-12-02 [email protected] Delete disabled workflow and add missing permissions key to workflow (flutter/flutter#178911)
2025-12-02 [email protected] [web] Fix some gn warnings (flutter/flutter#178313)
2025-12-02 [email protected] Roll Skia from 45337c4e919d to 6bd3b06b1e08 (4 revisions) (flutter/flutter#179353)
2025-12-02 [email protected] [ios] Reland Dynamic Content Resizing (flutter/flutter#179153)
2025-12-02 [email protected] [web] Fix onTextScaleFactorChanged not getting called. (flutter/flutter#178862)
2025-12-02 [email protected] Roll Packages from c8be05d to 148dcd2 (9 revisions) (flutter/flutter#179343)

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 [email protected] 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
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
This is a reland of flutter#177410

The previous pr was hitting deadlocks with tests that use screenshots.
This reland fixes it by submitting frames asynchronously instead of
synchronously.

This PR fixes flutter#169147

This is the iOS implementation of
flutter#149033

In Add-to-App scenarios, a common desired use case is to have the
embedded FlutterView be able to size itself based on it's content. Up
till now, the size had to be manually specified, which can be tedious
and inaccurate.

This PR adds a new flag, `isAutoResizable`, which enables the ability
for the embedded flutter view to dynamically set it's own size based off
it's content. Note that this feature will *NOT* work if the the embedded
app is wrapped in flexible or unsized widgets, such as Scaffold. The
FlutterView will just not display at all.

To use the new flag, just set it like
```
flutterViewController.autoResizable = true;
```
or in Swift

```
flutterViewController.isAutoResizable = true
```
## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Allow an embedded Flutter View on iOS to size itself, implement content-sized views

2 participants