Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit feb6ec3

Browse files
author
Chris Yang
committed
ignore layout change if application is inactive
test fix typo
1 parent 160b8cf commit feb6ec3

File tree

4 files changed

+65
-6
lines changed

4 files changed

+65
-6
lines changed

shell/platform/darwin/ios/framework/Source/FlutterViewController.mm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,6 @@ - (void)dealloc {
817817

818818
- (void)applicationBecameActive:(NSNotification*)notification {
819819
TRACE_EVENT0("flutter", "applicationBecameActive");
820-
self.view.accessibilityElementsHidden = NO;
821820
if (_viewportMetrics.physical_width) {
822821
[self surfaceUpdated:YES];
823822
}
@@ -826,7 +825,6 @@ - (void)applicationBecameActive:(NSNotification*)notification {
826825

827826
- (void)applicationWillResignActive:(NSNotification*)notification {
828827
TRACE_EVENT0("flutter", "applicationWillResignActive");
829-
self.view.accessibilityElementsHidden = YES;
830828
[self goToApplicationLifecycle:@"AppLifecycleState.inactive"];
831829
}
832830

shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ - (void)testHideOverlay {
932932
engine.viewController = nil;
933933
}
934934

935-
- (void)testHideA11yElements {
935+
- (void)testDoNotHideA11yElements {
936936
FlutterDartProject* project = [[FlutterDartProject alloc] init];
937937
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"foobar" project:project];
938938
[engine createShell:@"" libraryURI:@"" initialRoute:nil];
@@ -943,7 +943,7 @@ - (void)testHideA11yElements {
943943
[[NSNotificationCenter defaultCenter]
944944
postNotificationName:UIApplicationWillResignActiveNotification
945945
object:nil];
946-
XCTAssertTrue(realVC.view.accessibilityElementsHidden);
946+
XCTAssertFalse(realVC.view.accessibilityElementsHidden);
947947
[[NSNotificationCenter defaultCenter]
948948
postNotificationName:UIApplicationDidBecomeActiveNotification
949949
object:nil];

shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ void PostAccessibilityNotification(UIAccessibilityNotifications notification,
200200
for (SemanticsObject* object in [objects_ allValues]) {
201201
[object accessibilityBridgeDidFinishUpdate];
202202
}
203-
204-
if (!ios_delegate_->IsFlutterViewControllerPresentingModalViewController(view_controller_)) {
203+
if (!ios_delegate_->IsFlutterViewControllerPresentingModalViewController(view_controller_) &&
204+
[UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
205205
layoutChanged = layoutChanged || [doomed_uids count] > 0;
206206

207207
if (routeChanged) {

shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,67 @@ - (void)testAnnouncesIgnoresLayoutChangeWhenModal {
16181618
XCTAssertEqual([accessibility_notifications count], 0ul);
16191619
}
16201620

1621+
- (void)testAnnouncesIgnoresLayoutChangeWhenApplicationIsInactive {
1622+
flutter::MockDelegate mock_delegate;
1623+
auto thread_task_runner = CreateNewThread("AccessibilityBridgeTest");
1624+
flutter::TaskRunners runners(/*label=*/self.name.UTF8String,
1625+
/*platform=*/thread_task_runner,
1626+
/*raster=*/thread_task_runner,
1627+
/*ui=*/thread_task_runner,
1628+
/*io=*/thread_task_runner);
1629+
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
1630+
/*delegate=*/mock_delegate,
1631+
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
1632+
/*platform_views_controller=*/nil,
1633+
/*task_runners=*/runners);
1634+
id mockFlutterView = OCMClassMock([FlutterView class]);
1635+
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
1636+
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
1637+
1638+
NSMutableArray<NSDictionary<NSString*, id>*>* accessibility_notifications =
1639+
[[[NSMutableArray alloc] init] autorelease];
1640+
auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
1641+
ios_delegate->on_PostAccessibilityNotification_ =
1642+
[accessibility_notifications](UIAccessibilityNotifications notification, id argument) {
1643+
[accessibility_notifications addObject:@{
1644+
@"notification" : @(notification),
1645+
@"argument" : argument ? argument : [NSNull null],
1646+
}];
1647+
};
1648+
__block auto bridge =
1649+
std::make_unique<flutter::AccessibilityBridge>(/*view_controller=*/mockFlutterViewController,
1650+
/*platform_view=*/platform_view.get(),
1651+
/*platform_views_controller=*/nil,
1652+
/*ios_delegate=*/std::move(ios_delegate));
1653+
id mockApplication = OCMPartialMock([UIApplication sharedApplication]);
1654+
OCMStub([mockApplication applicationState]).andReturn(UIApplicationStateInactive);
1655+
1656+
flutter::CustomAccessibilityActionUpdates actions;
1657+
flutter::SemanticsNodeUpdates nodes;
1658+
1659+
flutter::SemanticsNode child_node;
1660+
child_node.id = 1;
1661+
child_node.label = "child_node";
1662+
nodes[child_node.id] = child_node;
1663+
flutter::SemanticsNode root_node;
1664+
root_node.id = kRootNodeId;
1665+
root_node.label = "root";
1666+
root_node.childrenInTraversalOrder = {1};
1667+
root_node.childrenInHitTestOrder = {1};
1668+
nodes[root_node.id] = root_node;
1669+
bridge->UpdateSemantics(/*nodes=*/nodes, /*actions=*/actions);
1670+
1671+
// Removes child_node to simulate a layout change.
1672+
flutter::SemanticsNodeUpdates new_nodes;
1673+
flutter::SemanticsNode new_root_node;
1674+
new_root_node.id = kRootNodeId;
1675+
new_root_node.label = "root";
1676+
new_nodes[new_root_node.id] = new_root_node;
1677+
bridge->UpdateSemantics(/*nodes=*/new_nodes, /*actions=*/actions);
1678+
1679+
XCTAssertEqual([accessibility_notifications count], 0ul);
1680+
}
1681+
16211682
- (void)testAnnouncesIgnoresScrollChangeWhenModal {
16221683
flutter::MockDelegate mock_delegate;
16231684
auto thread_task_runner = CreateNewThread("AccessibilityBridgeTest");

0 commit comments

Comments
 (0)