Skip to content

☂️ Umbrella issue for replace deprecated [UIScreen mainScreen] in iOS 16 #125496

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

Open
gaaclarke opened this issue Apr 25, 2023 · 5 comments
Open
Labels
c: tech-debt Technical debt, code quality, testing, etc. engine flutter/engine repository. See also e: labels. P2 Important issues not at the top of the work list platform-ios iOS applications specifically team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team

Comments

@gaaclarke
Copy link
Member

gaaclarke commented Apr 25, 2023

One instance was introduced in flutter/engine#41460

Use Case

UIScreen mainScreen is deprecated in iOS 16 per https://developer.apple.com/documentation/uikit/uiscreen/deprecated_symbols. We should use the recommended replacement UiWindowScene which was added in iOS 13 to support multiple windows and provide a fallback for iOS 11 & 12.

Proposal

There are several places where the deprecated UIScreen mainScreen is used and should be replaced:

File Name Tracking Issue
FlutterViewController.mm & FlutterViewControllerTest.mm
FlutterPlatformViews_Internal.mm
FlutterDartProject.mm & FlutterDartProjectTest.mm
FlutterView.mm
vsync_waiter_ios.mm
SemanticsObject.mm
FlutterPlatformViews.mm & FlutterPlatformViewsTest.mm
AppDelegate.m

Out of Scope

Currently, most Flutter behavior is built and tested for the single window. The simple replacement proposed in this issue may not address all multi-window scenario cases.

@gaaclarke gaaclarke added engine flutter/engine repository. See also e: labels. platform-ios iOS applications specifically labels Apr 25, 2023
@jmagman
Copy link
Member

jmagman commented Apr 25, 2023

Instead of a adding a new deprecated API usage can you instead use self.window.windowScene.screen.traitCollection.displayGamut?
https://github.com/flutter/engine/pull/41460/files#r1176801450

See https://github.com/flutter/engine/blob/36730dd4e4b195cde399d500600c3536b1a07b83/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm#L615-L623 for how the fallback is done in the FlutterViewController.

@jmagman
Copy link
Member

jmagman commented Apr 26, 2023

@gaaclarke since you didn't introduce a new one in flutter/engine#41460 are there more places +mainScreen is used outside of the availability check?

@gaaclarke
Copy link
Member Author

Yea, there is still quite a few instances.

aaclarke-macbookpro3:flutter aaclarke$ ag mainScreen
shell/platform/darwin/macos/framework/Source/FlutterPlatformNodeDelegateMac.mm
119:  // Thus, this method uses [[NSScreen screens] firstObject] instead of [NSScreen mainScreen].

shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
482:  const CGFloat scale = [UIScreen mainScreen].scale;
615:- (UIScreen*)mainScreenIfViewLoaded {
622:  return UIScreen.mainScreen;
1059:  const CGFloat scale = [UIScreen mainScreen].scale;
1274:  CGFloat scale = [UIScreen mainScreen].scale;
1321:  UIScreen* mainScreen = [self mainScreenIfViewLoaded];
1322:  if (!mainScreen) {
1326:  CGFloat scale = mainScreen.scale;
1335:  UIScreen* mainScreen = [self mainScreenIfViewLoaded];
1336:  if (!mainScreen) {
1340:  CGFloat scale = mainScreen.scale;
1501:  CGRect screenRect = [self mainScreenIfViewLoaded].bounds;
1541:                     toCoordinateSpace:[self mainScreenIfViewLoaded].coordinateSpace];
1557:                     toCoordinateSpace:[self mainScreenIfViewLoaded].coordinateSpace];
1564:    CGFloat scale = [self mainScreenIfViewLoaded].scale;
2233:  CGFloat scale = [UIScreen mainScreen].scale;
2290:  const CGFloat scale = [UIScreen mainScreen].scale;
2319:  const CGFloat scale = [UIScreen mainScreen].scale;

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm
263:  return [self initWithFrame:frame screenScale:[UIScreen mainScreen].scale];
485:                                            screenScale:[UIScreen mainScreen].scale] autorelease];
493:                                            screenScale:[UIScreen mainScreen].scale] autorelease];

shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm
269:  CGFloat scale = [UIScreen mainScreen].scale;
270:  CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width * scale;
271:  CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height * scale;

shell/platform/darwin/ios/framework/Source/FlutterView.mm
43:  return UIScreen.mainScreen;
101:    CGFloat screenScale = [UIScreen mainScreen].scale;

shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm
173:      SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
281:  CGFloat screenScale = [UIScreen mainScreen].scale;
351:  CGFloat screenScale = [UIScreen mainScreen].scale;
421:  CGFloat screenScale = [UIScreen mainScreen].scale;
492:  CGFloat screenScale = [UIScreen mainScreen].scale;
603:  CGFloat screenScale = [UIScreen mainScreen].scale;
738:  CGFloat screenScale = [UIScreen mainScreen].scale;
1013:  CGFloat screenScale = [UIScreen mainScreen].scale;
1312:      SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1365:  CGFloat screenScale = [UIScreen mainScreen].scale;
1458:      SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1527:      SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1592:      SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1656:      SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1727:      SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
1798:      SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);
2721:      SkMatrix::Scale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale);

shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm
185:  return [UIScreen mainScreen].maximumFramesPerSecond;

shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm
34:  CGFloat scale = [UIScreen mainScreen].scale;
35:  CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width * scale;
36:  CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height * scale;

shell/platform/darwin/ios/framework/Source/SemanticsObject.mm
60:  CGFloat scale = screen == nil ? [UIScreen mainScreen].scale : screen.scale;
88:  CGFloat scale = screen == nil ? [UIScreen mainScreen].scale : screen.scale;

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm
109:      CGFloat screenScale = [UIScreen mainScreen].scale;
470:  CGFloat screenScale = [UIScreen mainScreen].scale;
606:  CGFloat screenScale = [UIScreen mainScreen].scale;
644:  UIScreen* screen = [UIScreen mainScreen];
809:  auto screenScale = [UIScreen mainScreen].scale;

shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm
131:- (UIScreen*)mainScreenIfViewLoaded;
178:  OCMStub([viewControllerMock mainScreenIfViewLoaded]).andReturn(UIScreen.mainScreen);
235:  CGRect viewFrame = UIScreen.mainScreen.bounds;
274:  CGRect viewFrame = UIScreen.mainScreen.bounds;
278:  CGFloat screenHeight = UIScreen.mainScreen.bounds.size.height;
279:  CGFloat screenWidth = UIScreen.mainScreen.bounds.size.height;
360:  CGRect viewFrame = UIScreen.mainScreen.bounds;
363:  CGFloat screenWidth = UIScreen.mainScreen.bounds.size.width;
364:  CGFloat screenHeight = UIScreen.mainScreen.bounds.size.height;
462:  CGRect viewFrame = UIScreen.mainScreen.bounds;
465:  CGFloat screenWidth = UIScreen.mainScreen.bounds.size.width;
466:  CGFloat screenHeight = UIScreen.mainScreen.bounds.size.height;
587:  CGFloat screenWidth = UIScreen.mainScreen.bounds.size.width;
588:  CGFloat screenHeight = UIScreen.mainScreen.bounds.size.height;
589:  CGRect screenRect = UIScreen.mainScreen.bounds;
614:  OCMStub([viewControllerMock mainScreenIfViewLoaded]).andReturn(UIScreen.mainScreen);
616:  CGFloat screenWidth = UIScreen.mainScreen.bounds.size.width;
617:  CGFloat screenHeight = UIScreen.mainScreen.bounds.size.height;
628:  XCTAssertTrue(inset == 300 * UIScreen.mainScreen.scale);
638:  CGFloat screenWidth = UIScreen.mainScreen.bounds.size.width;
639:  CGFloat screenHeight = UIScreen.mainScreen.bounds.size.height;
641:  CGRect viewFrame = UIScreen.mainScreen.bounds;
662:  XCTAssertTrue(viewControllerMock.targetViewInsetBottom == 320 * UIScreen.mainScreen.scale);
873:  OCMStub([viewControllerMock mainScreenIfViewLoaded]).andReturn(UIScreen.mainScreen);
894:  OCMStub([viewControllerMock mainScreenIfViewLoaded]).andReturn(UIScreen.mainScreen);
927:  OCMStub([viewControllerMock mainScreenIfViewLoaded]).andReturn(UIScreen.mainScreen);

testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenTestManager.m
61:  XCUIScreenshot* screenshot = [[XCUIScreen mainScreen] screenshot];

testing/scenario_app/ios/Scenarios/Scenarios/AppDelegate.m
26:  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

@chinmaygarde chinmaygarde added P3 Issues that are less important to the Flutter project c: tech-debt Technical debt, code quality, testing, etc. labels May 1, 2023
@mossmana mossmana self-assigned this May 11, 2023
@mossmana mossmana changed the title Replace deprecated [UIScreen mainScreen]. Replace deprecated [UIScreen mainScreen] in iOS 16 May 12, 2023
@mossmana
Copy link
Contributor

@mossmana mossmana changed the title Replace deprecated [UIScreen mainScreen] in iOS 16 ☂️ Umbrella issue for replace deprecated [UIScreen mainScreen] in iOS 16 Jun 5, 2023
@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team labels Jul 8, 2023
@mossmana mossmana removed their assignment Sep 20, 2023
@mossmana mossmana added P2 Important issues not at the top of the work list and removed P3 Issues that are less important to the Flutter project labels Sep 20, 2023
@mossmana
Copy link
Contributor

Relates to #134062

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: tech-debt Technical debt, code quality, testing, etc. engine flutter/engine repository. See also e: labels. P2 Important issues not at the top of the work list platform-ios iOS applications specifically team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team
Projects
None yet
Development

No branches or pull requests

6 participants