Skip to content

Commit 3a9e7a9

Browse files
authored
[integration_test]UIScene Migration (#182631)
integration_test adopts UIScene *List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.* Fixes #174414 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* ## 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. - [ ] 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. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). 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. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 64358e1 commit 3a9e7a9

6 files changed

Lines changed: 44 additions & 16 deletions

File tree

dev/devicelab/bin/tasks/plugin_lint_mac.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ Future<void> main() async {
4040
'integration_test.podspec',
4141
);
4242

43-
await exec('pod', <String>['lib', 'lint', iosintegrationTestPodspec, '--use-libraries']);
43+
await exec('pod', <String>[
44+
'lib',
45+
'lint',
46+
iosintegrationTestPodspec,
47+
'--use-libraries',
48+
'--quick',
49+
]);
4450

4551
final String macosintegrationTestPodspec = path.join(
4652
integrationTestPackage,

packages/integration_test/example/ios/Runner/AppDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
#import <Flutter/Flutter.h>
66
#import <UIKit/UIKit.h>
77

8-
@interface AppDelegate : FlutterAppDelegate
8+
@interface AppDelegate : FlutterAppDelegate <FlutterImplicitEngineDelegate>
99

1010
@end

packages/integration_test/example/ios/Runner/AppDelegate.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ @implementation AppDelegate
1010

1111
- (BOOL)application:(UIApplication *)application
1212
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
13-
[GeneratedPluginRegistrant registerWithRegistry:self];
13+
return [super application:application didFinishLaunchingWithOptions:launchOptions];
14+
}
15+
16+
- (void)didInitializeImplicitFlutterEngine:(NSObject<FlutterImplicitEngineBridge>*)engineBridge {
17+
[GeneratedPluginRegistrant registerWithRegistry:engineBridge.pluginRegistry];
1418

1519
// Register platform view factory.
16-
NSObject<FlutterPluginRegistrar>* registrar = [self registrarForPlugin:@"spv-plugin"];
20+
NSObject<FlutterPluginRegistrar>* registrar = [engineBridge.pluginRegistry registrarForPlugin:@"spv-plugin"];
1721
SimplePlatformViewFactory* factory = [[SimplePlatformViewFactory alloc] initWithMessenger:registrar.messenger];
1822
[registrar registerViewFactory:factory withId:@"simple-platform-view"];
19-
20-
// Override point for customization after application launch.
21-
return [super application:application didFinishLaunchingWithOptions:launchOptions];
2223
}
2324

2425
@end

packages/integration_test/example/ios/Runner/Info.plist

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,26 @@
4343
<true/>
4444
<key>UIApplicationSupportsIndirectInputEvents</key>
4545
<true/>
46+
<key>UIApplicationSceneManifest</key>
47+
<dict>
48+
<key>UIApplicationSupportsMultipleScenes</key>
49+
<false/>
50+
<key>UISceneConfigurations</key>
51+
<dict>
52+
<key>UIWindowSceneSessionRoleApplication</key>
53+
<array>
54+
<dict>
55+
<key>UISceneClassName</key>
56+
<string>UIWindowScene</string>
57+
<key>UISceneDelegateClassName</key>
58+
<string>FlutterSceneDelegate</string>
59+
<key>UISceneConfigurationName</key>
60+
<string>flutter</string>
61+
<key>UISceneStoryboardFile</key>
62+
<string>Main</string>
63+
</dict>
64+
</array>
65+
</dict>
66+
</dict>
4667
</dict>
4768
</plist>

packages/integration_test/ios/integration_test/Sources/integration_test/IntegrationTestPlugin.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
@interface IntegrationTestPlugin ()
1616

1717
@property(nonatomic, readwrite) NSDictionary<NSString *, NSString *> *testResults;
18+
@property(nonatomic, weak) NSObject<FlutterPluginRegistrar> *registrar;
1819

1920
- (instancetype)init NS_DESIGNATED_INITIALIZER;
2021

@@ -45,9 +46,12 @@ - (instancetype)init {
4546
}
4647

4748
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
49+
IntegrationTestPlugin *instance = [self instance];
50+
instance.registrar = registrar;
4851
FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:kIntegrationTestPluginChannel
4952
binaryMessenger:registrar.messenger];
50-
[registrar addMethodCallDelegate:[self instance] channel:channel];
53+
[registrar addMethodCallDelegate:instance channel:channel];
54+
[registrar addSceneDelegate:instance];
5155
}
5256

5357
/// Handle method calls from Dart code:
@@ -78,17 +82,13 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
7882
}
7983

8084
- (UIImage *)capturePngScreenshot {
81-
// Get all windows in the app
85+
UIWindowScene *scene = self.registrar.viewController.view.window.windowScene;
8286
#pragma clang diagnostic push
8387
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
84-
// TODO(jmagman) Use scenes instead of deprecated windows. See
85-
// https://github.com/flutter/flutter/issues/154365
86-
NSArray<UIWindow *> *windows = [UIApplication sharedApplication].windows;
88+
NSArray<UIWindow *> *windows = scene ? scene.windows : [UIApplication sharedApplication].windows;
89+
CGRect screenBounds = scene.screen ? scene.screen.bounds : [UIScreen mainScreen].bounds;
8790
#pragma clang diagnostic pop
8891

89-
// Find the overall bounding rect for all windows
90-
CGRect screenBounds = [UIScreen mainScreen].bounds;
91-
9292
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithBounds:screenBounds];
9393
UIImage *screenshot =
9494
[renderer imageWithActions:^(UIGraphicsImageRendererContext *_Nonnull rendererContext) {

packages/integration_test/ios/integration_test/Sources/integration_test/include/IntegrationTestPlugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
88

99
/** A Flutter plugin that's responsible for communicating the test results back
1010
* to iOS XCTest. */
11-
@interface IntegrationTestPlugin : NSObject <FlutterPlugin>
11+
@interface IntegrationTestPlugin : NSObject <FlutterPlugin, FlutterSceneLifeCycleDelegate>
1212

1313
/**
1414
* Test results that are sent from Dart when integration test completes. Before the

0 commit comments

Comments
 (0)