Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forwards iOS dark mode trait to the Flutter framework (#34441). #9722

Conversation

matthew-carroll
Copy link
Contributor

Forwards iOS dark mode trait to the Flutter framework (#34441).

This change forwards iOS's dark mode setting to the Flutter framework from the appropriate ViewController methods:
https://developer.apple.com/documentation/appkit/supporting_dark_mode_in_your_interface?language=objc

MaterialApp will respect this setting on iOS. I don't believe CupertinoApp is setup yet to respect brightness.

This change does not include official color support for iOS's dark mode, nor does this PR resolve the issue of rendering correctly in the app switcher.

ios_dark_mode_demo

@matthew-carroll matthew-carroll force-pushed the 34441_send_ios_brightness_to_flutter branch 2 times, most recently from a94504c to c1136d6 Compare July 9, 2019 08:08
@matthew-carroll
Copy link
Contributor Author

@xster @dnfield please let me know if you can think of a reasonable way to test this.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

For tests, take a look at https://github.com/flutter/engine/blob/master/shell/platform/darwin/ios/framework/Source/FlutterEngineTest.mm

You could mock out the engine for the VC, mock out the settingschannel for the mock engine, and verify that calling the methods you're changing here resulted in a message on the settings channel.

@matthew-carroll
Copy link
Contributor Author

@dnfield can we do any better in terms of test value? Seems like that kind of test fakes most of the important machinery to validate one of the simplest and least likely to change details, a channel message....seems very low value from a regression-prevention standpoint.

@dnfield
Copy link
Contributor

dnfield commented Jul 9, 2019

My thought is that it would test that a channel message is sent on these events, which is all the new behavior this PR introduces.

An end to end test of that would be even better, but harder to create IMO. You could put another integration test in ios_add2app but not sure how you would modify the system setting in a test.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM. I can't think of a better way to test than what's been suggested. Not sure about changing system settings in an e2e test.

@LongCatIsLooong
Copy link
Contributor

LongCatIsLooong commented Jul 9, 2019

When the user changes the system appearance, the system automatically asks each window and view to redraw itself. During this process, the system calls several well-known methods for both macOS and iOS, listed in the following table, to update your content. The system updates the trait environment before calling these methods, so if you make all of your appearance-sensitive changes in them, your app updates itself correctly.

It sounds like reporting trait collection changes in one of the methods in the list should suffice? I wonder if we can reduce it down to viewDidLoad and traitCollectionDidChange.

EDIT:
@matthew-carroll
traitCollectionDidChange(_:) should be called every single time the surrounding UITraitCollection changes, per its name and documentation. It also gets called if I change color vibrancy while the app is in background and then foreground the app.

According to this article, traitCollectionDidChange(_:) will no longer pick up the initial traitCollection value on iOS 13 so I guess it's safer to manually pick up the initial value in viewDidLoad or a similar method.

@dnfield
Copy link
Contributor

dnfield commented Jul 9, 2019

In terms of preventing regressions, it would prevent someone from inadvertently removing one of the places where we need to invoke this channel.

Part of the idea here is that channel message passing should also be well tested (but shouldn't be the responsibility of this PR), and the framework's handling of such a message should also be well tested (but also isn't the job of this PR). It's also not our responsibility to test whether iOS calls the methods it documents that it will call in the linked documentation.

As I said, an integration test would also be good but is probably pretty challenging to get quite right in this case - I think at the least we'd end up mocking out the system preference change by just directly messaging the ViewController.

@matthew-carroll
Copy link
Contributor Author

@dnfield @justinmc I'll go ahead and try to write up that test as described.

@LongCatIsLooong I'm open to removing excessive calls. Can you demonstrate that we don't need all of those methods? It may be the case that they are often called in succession, but the question is, are there ever moments where only 1 of them is called? If so, then we would need that call overridden. Unfortunately, I don't know nearly enough about ViewController lifecycles. CC @dnfield if you happen to know about this.

@matthew-carroll
Copy link
Contributor Author

@dnfield do we have any docs for how to run those tests locally? If not, would you mind providing instructions here?

@dnfield
Copy link
Contributor

dnfield commented Jul 10, 2019

@gaaclarke should know, but I think you just run the shell scripts in that folder....

@matthew-carroll
Copy link
Contributor Author

@dnfield I'm not seeing a shell script in that directory, or its parent directory. Can you point me to the script you're thinking of?

@dnfield
Copy link
Contributor

dnfield commented Jul 19, 2019

https://github.com/flutter/engine/blob/master/testing/ios/IosUnitTests/build_and_run_tests.sh

@cbracken
Copy link
Member

cbracken commented Aug 5, 2019

@matthew-carroll do you plan to continue with this PR?

@matthew-carroll
Copy link
Contributor Author

Yep. I need to figure out how to write unit tests for iOS first.

@matthew-carroll matthew-carroll force-pushed the 34441_send_ios_brightness_to_flutter branch from 1d45ae2 to ee52181 Compare August 8, 2019 04:22
@matthew-carroll
Copy link
Contributor Author

I finally got around to adding tests for this.

@dnfield can you take another look?

@matthew-carroll matthew-carroll requested a review from dnfield August 8, 2019 07:20
Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the test. Fyi @LongCatIsLooong

@matthew-carroll matthew-carroll merged commit 65fd5d4 into flutter:master Aug 8, 2019
@chinmaygarde
Copy link
Member

chinmaygarde added a commit that referenced this pull request Aug 9, 2019
chinmaygarde added a commit that referenced this pull request Aug 9, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 9, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 9, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 9, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Aug 9, 2019
[email protected]:flutter/engine.git/compare/d9bbe37ce376...dd735c9

git log d9bbe37..dd735c9 --no-merges --oneline
2019-08-09 [email protected] [flutter_runner] Improve frame scheduling (flutter/engine#10780)
2019-08-09 [email protected] [flutter] Create the compositor context on the GPU task runner. (flutter/engine#10781)
2019-08-09 [email protected] Revert "Forwards iOS dark mode trait to the Flutter framework (#34441). (#9722)" (flutter/engine#10789)
2019-08-08 [email protected] Forwards iOS dark mode trait to the Flutter framework (#34441). (flutter/engine#9722)
2019-08-08 [email protected] Specify which android variant for tests (flutter/engine#10717)
2019-08-08 [email protected] Don't use gradle daemon for building (flutter/engine#10771)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff ([email protected]), and stop
the roller if necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants