Skip to content

Commit 6dec84a

Browse files
hellohuanlinsuryaKommana2662
authored andcommitted
[iPhone Duo] Use the correct UIScreen to report the display size and update when fold/unfold (flutter#195199)
On iPhone Duo, `UIScreen.mainScreen` always refers to the outer display. The iOS embedder used `UIScreen.mainScreen`, so when the app is on the inner display, `PlatformDispatcher.displays` reports the wrong screen. This PR ensures the embedder to report the correct screen size to the framework, and when switch between inner/outer screens, update the framework with the new size. ## Why still need `UIScreen.mainScreen` fallback The framework can read display information as soon as the isolate launches, before any view is in a window (see this test project flutter#195177 (comment)). At that point we do not know which screen the FlutterVC will be added to (if we ever add it to the screen). MainScreen remains a best-effort initial guess (better than a `.zero` size since flutter developers may have already depend on the value). It is corrected as soon as the view is laid out in a window. `_hasSentDisplays` makes the engine use the `UIScreen.mainScreen` fallback only for the very first display it sends, before any view is in a window. After that, if the view isn't in a window (e.g. a newly attached view controller whose view isn't loaded yet), the engine keeps the last reported display instead of replacing it with the `mainScreen` guess. The flag resets when a new shell is adopted, so each new shell still gets an initial display. ## Why not fallback based on hinge state? 1. Hinge API only works for a view that's already in a window. 2. There's no dedicated API to get the inner display (unless with another deprecated `UIScreen.screens` API which isn't great either). 3. Open state could use both inner and outer displays (accessory scene) ## Why change in `SemanticsObject` is simpler than `FlutterEngine/VC` Because `SemanticsObject` is a "pull" model, where we simply need to check which screen when accessing it. On the other hand, `FlutterEngine/VC` is a "push" model, where we have to make sure to update the value when screen changes. ## Integration test I don't think there's a `simctl` sub-command that allows us to fold/unfold the simulator. We could add a integration test in the future if such api become available. ## Manual test I have manually verified using [this test project](flutter#195177 (comment)), and confirmed the reported value is correct, and updated correctly once fold/unfold Scenario | Window screen | Before (stock engine) | After (this PR) -- | -- | -- | -- Launch closed | 1398x2034 | 1398x2034 | 1398x2034 Closed → open | 2007x2853 | ❌ 1398x2034 | ✅ 2007x2853 Open → closed | 1398x2034 | 1398x2034 | ✅ 1398x2034 Launch open (first read in main()) | 2007x2853 | ❌ 1398x2034 for the whole session | ✅ 2007x2853 Working towards flutter#195177 *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 [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [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 in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [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. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **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 [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/CONTRIBUTING.ai.md [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 [flutter/website]: https://github.com/flutter/website [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 e3285b9 commit 6dec84a

8 files changed

Lines changed: 255 additions & 5 deletions

File tree

‎engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine+Test.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ThreadHost;
3838
NS_SWIFT_UI_ACTOR;
3939
- (const flutter::ThreadHost&)threadHost;
4040
- (void)updateDisplays;
41+
- (void)sendDisplayWithScreenNativeSize:(CGSize)screenNativeSize scale:(CGFloat)scale;
4142
- (void)flutterTextInputView:(FlutterTextInputView*)textInputView
4243
performAction:(FlutterTextInputAction)action
4344
withClient:(int)client;

‎engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ @implementation FlutterEngine {
205205

206206
FlutterFMLTaskRunner* _platformTaskRunnerWrapper;
207207
FlutterFMLTaskRunner* _rasterTaskRunnerWrapper;
208+
209+
// The display information last sent to the framework by `updateDisplays`.
210+
BOOL _hasSentDisplays;
211+
CGSize _lastSentScreenNativeSize;
212+
CGFloat _lastSentScreenScale;
208213
}
209214

210215
- (int64_t)engineIdentifier {
@@ -832,6 +837,8 @@ - (void)launchEngine:(NSString*)entrypoint
832837
- (void)adoptShell:(std::unique_ptr<flutter::Shell>)shell {
833838
FML_DCHECK(shell);
834839
_shell = std::move(shell);
840+
// A new shell has not received any display information yet.
841+
_hasSentDisplays = NO;
835842
_platformTaskRunnerWrapper = [[FlutterFMLTaskRunner alloc]
836843
initWithTaskRunner:_shell->GetTaskRunners().GetPlatformTaskRunner()];
837844
_rasterTaskRunnerWrapper = [[FlutterFMLTaskRunner alloc]
@@ -1025,13 +1032,37 @@ - (void)updateDisplays {
10251032
// Tests may do this.
10261033
return;
10271034
}
1035+
// Prefer the screen that the view is on. Fallback to main screen if not available (e.g. the
1036+
// Flutter view hasn't been added to any screen).
1037+
UIScreen* screen = self.viewController.viewIfLoaded.window.windowScene.screen;
1038+
if (!screen) {
1039+
if (_hasSentDisplays) {
1040+
// Keep the last reported display, rather than regressing to a guess.
1041+
return;
1042+
}
1043+
// The framework can read the display information as soon as the isolate launches, before any
1044+
// view is on screen (e.g. a headless or pre-warmed engine). Use `UIScreen.mainScreen` as a
1045+
// best-effort guess until the view is in a window.
1046+
screen = UIScreen.mainScreen;
1047+
}
1048+
CGSize screen_size = screen.nativeBounds.size;
1049+
CGFloat scale = screen.scale;
1050+
if (_hasSentDisplays && CGSizeEqualToSize(screen_size, _lastSentScreenNativeSize) &&
1051+
scale == _lastSentScreenScale) {
1052+
return;
1053+
}
1054+
_hasSentDisplays = YES;
1055+
_lastSentScreenNativeSize = screen_size;
1056+
_lastSentScreenScale = scale;
1057+
[self sendDisplayWithScreenNativeSize:screen_size scale:scale];
1058+
}
1059+
1060+
- (void)sendDisplayWithScreenNativeSize:(CGSize)screenNativeSize scale:(CGFloat)scale {
10281061
auto vsync_waiter = _shell->GetVsyncWaiter().lock();
10291062
auto vsync_waiter_ios = std::static_pointer_cast<flutter::VsyncWaiterIOS>(vsync_waiter);
10301063
std::vector<std::unique_ptr<flutter::Display>> displays;
1031-
auto screen_size = UIScreen.mainScreen.nativeBounds.size;
1032-
auto scale = UIScreen.mainScreen.scale;
10331064
displays.push_back(std::make_unique<flutter::VariableRefreshRateDisplay>(
1034-
0, vsync_waiter_ios, screen_size.width, screen_size.height, scale));
1065+
0, vsync_waiter_ios, screenNativeSize.width, screenNativeSize.height, scale));
10351066
_shell->OnDisplayUpdates(std::move(displays));
10361067
}
10371068

‎engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngineTest.mm‎

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@
4343
private:
4444
TestPlatformMessageResponse() = default;
4545
};
46+
47+
// Returns a mock view controller whose view is in a window on a screen with the given native size
48+
// and scale.
49+
id CreateMockViewControllerOnScreen(CGSize screenNativeSize, CGFloat screenScale) {
50+
UIScreen* screen = OCMClassMock([UIScreen class]);
51+
OCMStub([screen nativeBounds]).andDo(^(NSInvocation* invocation) {
52+
CGRect nativeBounds = CGRectMake(0, 0, screenNativeSize.width, screenNativeSize.height);
53+
[invocation setReturnValue:&nativeBounds];
54+
});
55+
OCMStub([screen scale]).andDo(^(NSInvocation* invocation) {
56+
CGFloat scale = screenScale;
57+
[invocation setReturnValue:&scale];
58+
});
59+
UIWindowScene* windowScene = OCMClassMock([UIWindowScene class]);
60+
OCMStub([windowScene screen]).andReturn(screen);
61+
UIWindow* window = OCMClassMock([UIWindow class]);
62+
OCMStub([window windowScene]).andReturn(windowScene);
63+
UIView* view = OCMClassMock([UIView class]);
64+
OCMStub([view window]).andReturn(window);
65+
FlutterViewController* viewController = OCMClassMock([FlutterViewController class]);
66+
OCMStub([viewController viewIfLoaded]).andReturn(view);
67+
return viewController;
68+
}
4669
} // namespace
4770

4871
/// A `FlutterTexture` that vends no frames. Used to obtain a registered texture id.
@@ -523,6 +546,109 @@ - (void)testFlutterEngineUpdatesDisplays {
523546
OCMVerify(times(2), [mockEngine updateDisplays]);
524547
}
525548

549+
- (void)testUpdateDisplaysFallsBackToMainScreenBeforeViewIsInWindow {
550+
FlutterEngine* engine = [[FlutterEngine alloc] init];
551+
id mockEngine = OCMPartialMock(engine);
552+
553+
// The framework can read the display as soon as the isolate launches, before any view controller
554+
// is attached, so `run` must send a display even though there is no screen to ask yet.
555+
[engine run];
556+
557+
CGSize mainScreenNativeSize = UIScreen.mainScreen.nativeBounds.size;
558+
CGFloat mainScreenScale = UIScreen.mainScreen.scale;
559+
OCMVerify(times(1), [mockEngine sendDisplayWithScreenNativeSize:mainScreenNativeSize
560+
scale:mainScreenScale]);
561+
}
562+
563+
- (void)testUpdateDisplaysUsesScreenOfViewWindow {
564+
FlutterEngine* engine = [[FlutterEngine alloc] init];
565+
id mockEngine = OCMPartialMock(engine);
566+
__block id viewController = nil;
567+
OCMStub([mockEngine viewController]).andDo(^(NSInvocation* invocation) {
568+
__unsafe_unretained id value = viewController;
569+
[invocation setReturnValue:&value];
570+
});
571+
[engine run];
572+
573+
viewController = CreateMockViewControllerOnScreen(CGSizeMake(1001, 2002), 3);
574+
[engine updateDisplays];
575+
576+
OCMVerify(times(1), [mockEngine sendDisplayWithScreenNativeSize:CGSizeMake(1001, 2002) scale:3]);
577+
}
578+
579+
- (void)testUpdateDisplaysDoesNotResendUnchangedDisplay {
580+
FlutterEngine* engine = [[FlutterEngine alloc] init];
581+
id mockEngine = OCMPartialMock(engine);
582+
__block id viewController = nil;
583+
OCMStub([mockEngine viewController]).andDo(^(NSInvocation* invocation) {
584+
__unsafe_unretained id value = viewController;
585+
[invocation setReturnValue:&value];
586+
});
587+
[engine run];
588+
589+
viewController = CreateMockViewControllerOnScreen(CGSizeMake(1001, 2002), 3);
590+
[engine updateDisplays];
591+
[engine updateDisplays];
592+
// A different view controller on a screen with the same size and scale.
593+
viewController = CreateMockViewControllerOnScreen(CGSizeMake(1001, 2002), 3);
594+
[engine updateDisplays];
595+
596+
OCMVerify(times(1), [mockEngine sendDisplayWithScreenNativeSize:CGSizeMake(1001, 2002) scale:3]);
597+
}
598+
599+
- (void)testUpdateDisplaysResendsWhenScreenChanges {
600+
FlutterEngine* engine = [[FlutterEngine alloc] init];
601+
id mockEngine = OCMPartialMock(engine);
602+
__block id viewController = nil;
603+
OCMStub([mockEngine viewController]).andDo(^(NSInvocation* invocation) {
604+
__unsafe_unretained id value = viewController;
605+
[invocation setReturnValue:&value];
606+
});
607+
[engine run];
608+
609+
// E.g. moving between the outer and inner displays of a device with multiple built-in displays.
610+
viewController = CreateMockViewControllerOnScreen(CGSizeMake(1001, 2002), 3);
611+
[engine updateDisplays];
612+
viewController = CreateMockViewControllerOnScreen(CGSizeMake(3003, 4004), 3);
613+
[engine updateDisplays];
614+
viewController = CreateMockViewControllerOnScreen(CGSizeMake(1001, 2002), 3);
615+
[engine updateDisplays];
616+
// Same size, different scale.
617+
viewController = CreateMockViewControllerOnScreen(CGSizeMake(1001, 2002), 2);
618+
[engine updateDisplays];
619+
620+
OCMVerify(times(2), [mockEngine sendDisplayWithScreenNativeSize:CGSizeMake(1001, 2002) scale:3]);
621+
OCMVerify(times(1), [mockEngine sendDisplayWithScreenNativeSize:CGSizeMake(3003, 4004) scale:3]);
622+
OCMVerify(times(1), [mockEngine sendDisplayWithScreenNativeSize:CGSizeMake(1001, 2002) scale:2]);
623+
}
624+
625+
- (void)testUpdateDisplaysKeepsLastDisplayWhenViewIsNotInWindow {
626+
FlutterEngine* engine = [[FlutterEngine alloc] init];
627+
id mockEngine = OCMPartialMock(engine);
628+
__block id viewController = nil;
629+
OCMStub([mockEngine viewController]).andDo(^(NSInvocation* invocation) {
630+
__unsafe_unretained id value = viewController;
631+
[invocation setReturnValue:&value];
632+
});
633+
[engine run];
634+
635+
viewController = CreateMockViewControllerOnScreen(CGSizeMake(1001, 2002), 3);
636+
[engine updateDisplays];
637+
// A view controller whose view is not loaded (e.g. a newly attached view controller).
638+
viewController = OCMClassMock([FlutterViewController class]);
639+
[engine updateDisplays];
640+
// No view controller.
641+
viewController = nil;
642+
[engine updateDisplays];
643+
644+
// Only the initial display (from `run`) used the `UIScreen.mainScreen` fallback.
645+
CGSize mainScreenNativeSize = UIScreen.mainScreen.nativeBounds.size;
646+
CGFloat mainScreenScale = UIScreen.mainScreen.scale;
647+
OCMVerify(times(1), [mockEngine sendDisplayWithScreenNativeSize:mainScreenNativeSize
648+
scale:mainScreenScale]);
649+
OCMVerify(times(1), [mockEngine sendDisplayWithScreenNativeSize:CGSizeMake(1001, 2002) scale:3]);
650+
}
651+
526652
- (void)testLifeCycleNotificationDidEnterBackgroundForApplication {
527653
FlutterDartProject* project = [[FlutterDartProject alloc] init];
528654
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"foobar" project:project];

‎engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ NS_ASSUME_NONNULL_BEGIN
128128
- (void)sendDeepLinkToFramework:(NSURL*)url completionHandler:(void (^)(BOOL success))completion;
129129

130130
- (void)onStatusBarTap;
131+
132+
/**
133+
* Sends display information for the screen that the view controller's view is on, if it differs
134+
* from the display last sent to the framework.
135+
*
136+
* If the view isn't in a window, keeps the last display sent. If no display has been sent yet,
137+
* sends `UIScreen.mainScreen` as a best-effort initial display.
138+
*/
139+
- (void)updateDisplays;
131140
@end
132141

133142
@interface FlutterImplicitEngineBridgeImpl : NSObject <FlutterImplicitEngineBridge>

‎engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,7 @@ - (void)viewDidLayoutSubviews {
13441344
[self checkAndUpdateAutoResizeConstraints];
13451345
[self setViewportMetricsPaddings];
13461346
[self updateViewportMetricsIfNeeded];
1347+
[self updateEngineDisplays];
13471348

13481349
// There is no guarantee that UIKit will layout subviews when the application/scene is in the
13491350
// foreground. Creating the surface when backgrounded will cause app termination, so in that
@@ -1355,6 +1356,16 @@ - (void)viewDidLayoutSubviews {
13551356
}
13561357
}
13571358

1359+
// Asks the engine to send updated display information to the framework, e.g. when the view is first
1360+
// placed in a window, or moves between the inner and outer displays of a device with multiple
1361+
// built-in displays. The engine skips the update if the display information has not changed.
1362+
- (void)updateEngineDisplays {
1363+
if (self.engine.viewController != self) {
1364+
return;
1365+
}
1366+
[self.engine updateDisplays];
1367+
}
1368+
13581369
- (BOOL)isAutoResizable {
13591370
return self.flutterView.autoResizable;
13601371
}

‎engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,33 @@ - (void)testUpdatedViewportMetricsDoesNotResizeFlutterViewWhenNotAutoResizable {
14151415
OCMVerifyAll(mockVC);
14161416
}
14171417

1418+
- (void)testViewDidLayoutSubviewsUpdatesEngineDisplays {
1419+
FlutterEngine* mockEngine = OCMPartialMock([[FlutterEngine alloc] init]);
1420+
[mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1421+
FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:mockEngine
1422+
nibName:nil
1423+
bundle:nil];
1424+
1425+
// Layout is when the view may have moved to a different screen (e.g. between the inner and outer
1426+
// displays of a device with multiple built-in displays).
1427+
OCMExpect([mockEngine updateDisplays]);
1428+
[viewController viewDidLayoutSubviews];
1429+
OCMVerifyAll((id)mockEngine);
1430+
}
1431+
1432+
- (void)testViewDidLayoutSubviewsDoesNotUpdateEngineDisplaysWhenNotEngineViewController {
1433+
FlutterEngine* mockEngine = OCMPartialMock([[FlutterEngine alloc] init]);
1434+
[mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1435+
FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:mockEngine
1436+
nibName:nil
1437+
bundle:nil];
1438+
mockEngine.viewController = nil;
1439+
1440+
OCMReject([mockEngine updateDisplays]);
1441+
[viewController viewDidLayoutSubviews];
1442+
OCMVerifyAll((id)mockEngine);
1443+
}
1444+
14181445
- (void)testUpdateViewportMetricsIfNeeded_DoesNotInvokeEngineWhenShouldBeIgnoredDuringRotation {
14191446
FlutterEngine* mockEngine = OCMPartialMock([[FlutterEngine alloc] init]);
14201447
[mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];

‎engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,8 +1028,11 @@ - (CGRect)accessibilityFrame {
10281028
// Even if it's marked accessible, VoiceControl labels will not appear if it's too
10291029
// spatially distant. Set the frame to be the max screen size so all children are guaraenteed
10301030
// to be contained.
1031-
1032-
return UIScreen.mainScreen.bounds;
1031+
//
1032+
// Prefer the screen that the view is on. Fallback to main screen if not available (e.g. the
1033+
// Flutter view hasn't been added to any screen).
1034+
UIScreen* screen = self.semanticsObject.bridgeView.window.windowScene.screen;
1035+
return (screen ?: UIScreen.mainScreen).bounds;
10331036
}
10341037

10351038
- (id)accessibilityContainer {

‎engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,48 @@ - (void)testSemanticsObjectContainerAccessibilityFrameCoversEntireScreen {
799799
XCTAssertTrue(CGRectEqualToRect(container.accessibilityFrame, UIScreen.mainScreen.bounds));
800800
}
801801

802+
- (void)testSemanticsObjectContainerAccessibilityFrameUsesScreenOfBridgeViewWindow {
803+
flutter::testing::MockAccessibilityBridge* mock = new flutter::testing::MockAccessibilityBridge();
804+
mock->isVoiceOverRunningValue = true;
805+
fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
806+
fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
807+
808+
flutter::SemanticsNode parent;
809+
parent.id = 0;
810+
811+
flutter::SemanticsNode child;
812+
child.id = 1;
813+
child.rect = SkRect::MakeXYWH(0, 0, 100, 100);
814+
parent.childrenInTraversalOrder.push_back(1);
815+
816+
FlutterSemanticsObject* parentObject = [[FlutterSemanticsObject alloc] initWithBridge:bridge
817+
uid:0];
818+
[parentObject setSemanticsNode:&parent];
819+
FlutterSemanticsObject* childObject = [[FlutterSemanticsObject alloc] initWithBridge:bridge
820+
uid:1];
821+
[childObject setSemanticsNode:&child];
822+
parentObject.children = @[ childObject ];
823+
824+
// Put the bridge view's window on a screen that is not `UIScreen.mainScreen` (e.g. the inner
825+
// display of a device with multiple built-in displays).
826+
CGRect screenBounds = CGRectMake(0, 0, 951, 669);
827+
UIScreen* mockScreen = OCMClassMock([UIScreen class]);
828+
OCMStub([mockScreen bounds]).andDo(^(NSInvocation* invocation) {
829+
CGRect bounds = screenBounds;
830+
[invocation setReturnValue:&bounds];
831+
});
832+
UIWindowScene* mockWindowScene = OCMClassMock([UIWindowScene class]);
833+
OCMStub([mockWindowScene screen]).andReturn(mockScreen);
834+
UIWindow* mockWindow = OCMPartialMock(mock->view().window);
835+
OCMStub([mockWindow windowScene]).andReturn(mockWindowScene);
836+
837+
SemanticsObjectContainer* container =
838+
static_cast<SemanticsObjectContainer*>(parentObject.accessibilityContainer);
839+
XCTAssertTrue(CGRectEqualToRect(container.accessibilityFrame, screenBounds));
840+
841+
[(id)mockWindow stopMocking];
842+
}
843+
802844
- (void)testRootSemanticsObjectContainerAccessibilityContainerIsBridgeView {
803845
flutter::testing::MockAccessibilityBridge* mock = new flutter::testing::MockAccessibilityBridge();
804846
mock->isVoiceOverRunningValue = true;

0 commit comments

Comments
 (0)