Skip to content

Fix ios black screen during splash screen if widget binding initializ…#52913

Merged
fluttergithubbot merged 8 commits intoflutter:masterfrom
chunhtai:issues/39494
Mar 23, 2020
Merged

Fix ios black screen during splash screen if widget binding initializ…#52913
fluttergithubbot merged 8 commits intoflutter:masterfrom
chunhtai:issues/39494

Conversation

@chunhtai
Copy link
Contributor

…ed before runapp

Description

When ios engine starts up, it will send semantics enable message to framework if the binding has been initialized. Framework will schedule a new frame to make sure the semantics tree gets sent to the engine. This makes engine thinks the framework is ready to produce frame and takes down the splash screen.

This pr make sure scheduler binding only schedule frame when widget binding think it is ready by overriding the frameEnabled getter.

Related Issues

Fixes #39494

Tests

I added the following tests:

"The frames will only be enabled after runApp has bootstrapped the app"

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.
    • I wrote a design doc: https://flutter.dev/go/template Replace this with a link to your design doc's short link
    • I got input from the developer relations team, specifically from: Replace with the names of who gave advice
    • I wrote a migration guide: Replace with a link to your migration guide

@fluttergithubbot
Copy link
Contributor

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label Mar 19, 2020
@skia-gold
Copy link

Gold has detected one or more untriaged digests on patchset 4.
Please triage them at https://flutter-gold.skia.org/search?issue=52913.

@chunhtai
Copy link
Contributor Author

apparently it broke all the tests, I will add a WIP label

@chunhtai chunhtai changed the title Fix ios black screen during splash screen if widget binding initializ… [WIP] Fix ios black screen during splash screen if widget binding initializ… Mar 19, 2020
bool _appHasBootStapped = false;

@override
bool get framesEnabled => super.framesEnabled && _appHasBootStapped;
Copy link
Contributor

Choose a reason for hiding this comment

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

"BootStapped" isn't english... what did you mean? :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe "rootWidgetAttached"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I misspelled bootstrapped. but your suggestion may be better. will update

Copy link
Contributor

Choose a reason for hiding this comment

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

fwiw you ended up going with a different name -- i'm fine with either, just wanted to mention it since you said above that you like the specific name i'd suggested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The rootWidgetAttached will confuse with the existing https://api.flutter.dev/flutter/widgets/WidgetsBinding/isRootWidgetAttached.html. This field actually need to be set to true right before attaching the root widget. That is why i change the name.

@chunhtai chunhtai changed the title [WIP] Fix ios black screen during splash screen if widget binding initializ… Fix ios black screen during splash screen if widget binding initializ… Mar 20, 2020
@chunhtai
Copy link
Contributor Author

ready for review

Element get renderViewElement => _renderViewElement;
Element _renderViewElement;

bool _rootWidgetAttached = false;
Copy link
Member

Choose a reason for hiding this comment

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

We already have https://master-api.flutter.dev/flutter/widgets/WidgetsBinding/isRootWidgetAttached.html, what's the difference between isRootWidgetAttached and _rootWidgetAttached?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, the name is confusing. I cannot use isRootWidgetAttached because it schedules the first frame during attaching the root widget, the frames should be enabled before that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually have some question about #40105. What is the issue behind this pr?

Copy link
Member

Choose a reason for hiding this comment

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

isRootWidgetAttached is just a getter. How does it schedule a frame?

I actually have some question about #40105. What is the issue behind this pr?

The issue is described in the PR's description. What's your question?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After the change in #39535 we were only scheduling the first frame on accident as a side-effect of the warm-up frame (SchedulerBinding. scheduleWarmUpFrame awaits SchedulerBinding.endOfFrame, which implicitly schedules a frame)

I know it is a fact, but what problem will it cause if we keep this behavior?

Copy link
Member

Choose a reason for hiding this comment

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

Everything will continue to work as before because the warmup frame schedules the first frame as a side effect. However, if we ever were to remove the warmup frame, things would start to break. Therefore, we decided to make scheduling the first frame more explicit.


void main() {
test('The frames will only be enabled after runApp attaches the root widget', () async {
final WidgetsFlutterBinding binding = WidgetsFlutterBinding.ensureInitialized() as WidgetsFlutterBinding;
Copy link
Member

Choose a reason for hiding this comment

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

Why does this need to be casted to a WidgetsFlutterBinding? ensureInitialized returns a WidgetsBinding, which should give you access to everything you may want to call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied from the other test. will update

test('The frames will only be enabled after runApp attaches the root widget', () async {
final WidgetsFlutterBinding binding = WidgetsFlutterBinding.ensureInitialized() as WidgetsFlutterBinding;
expect(SchedulerBinding.instance.framesEnabled, isFalse);
// Framework starts with detached statue. Sends resumed signal to enable frame.
Copy link
Member

Choose a reason for hiding this comment

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

statue? Do you mean state?

@chunhtai
Copy link
Contributor Author

ready for review @goderbauer

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WidgetsFlutterBinding.ensureInitialized() takes down splash screen too early.

6 participants