diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm index 763826f99f..49c5b14516 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm @@ -206,14 +206,16 @@ void AccessibilityBridge::UpdateSemantics(flutter::SemanticsNodeUpdates nodes, [objects_ removeObjectsForKeys:doomed_uids]; layoutChanged = layoutChanged || [doomed_uids count] > 0; - // We should send out only one notification per semantics update. + if (routeChanged) { if (!ios_delegate_->IsFlutterViewControllerPresentingModalViewController(view_controller_)) { NSString* routeName = [lastAdded routeName]; ios_delegate_->PostAccessibilityNotification(UIAccessibilityScreenChangedNotification, routeName); } - } else if (layoutChanged) { + } + + if (layoutChanged) { SemanticsObject* nextToFocus = nil; // This property will be -1 if the focus is outside of the flutter // application. In this case, we should not refocus anything. diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm index 260a7eb19a..35fd8aac9f 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm @@ -344,6 +344,102 @@ fml::RefPtr CreateNewThread(std::string name) { UIAccessibilityScreenChangedNotification); } +- (void)testAnnouncesRouteChangesAndLayoutChangeInOneUpdate { + flutter::MockDelegate mock_delegate; + auto thread_task_runner = CreateNewThread("AccessibilityBridgeTest"); + flutter::TaskRunners runners(/*label=*/self.name.UTF8String, + /*platform=*/thread_task_runner, + /*raster=*/thread_task_runner, + /*ui=*/thread_task_runner, + /*io=*/thread_task_runner); + auto platform_view = std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/nil, + /*task_runners=*/runners); + id mockFlutterView = OCMClassMock([FlutterView class]); + id mockFlutterViewController = OCMClassMock([FlutterViewController class]); + OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView); + + NSMutableArray*>* accessibility_notifications = + [[[NSMutableArray alloc] init] autorelease]; + auto ios_delegate = std::make_unique(); + ios_delegate->on_PostAccessibilityNotification_ = + [accessibility_notifications](UIAccessibilityNotifications notification, id argument) { + [accessibility_notifications addObject:@{ + @"notification" : @(notification), + @"argument" : argument ? argument : [NSNull null], + }]; + }; + __block auto bridge = + std::make_unique(/*view_controller=*/mockFlutterViewController, + /*platform_view=*/platform_view.get(), + /*platform_views_controller=*/nil, + /*ios_delegate=*/std::move(ios_delegate)); + + flutter::CustomAccessibilityActionUpdates actions; + flutter::SemanticsNodeUpdates nodes; + + flutter::SemanticsNode node1; + node1.id = 1; + node1.label = "node1"; + node1.flags = static_cast(flutter::SemanticsFlags::kScopesRoute) | + static_cast(flutter::SemanticsFlags::kNamesRoute); + nodes[node1.id] = node1; + flutter::SemanticsNode node3; + node3.id = 3; + node3.label = "node3"; + nodes[node3.id] = node3; + flutter::SemanticsNode root_node; + root_node.id = kRootNodeId; + root_node.flags = static_cast(flutter::SemanticsFlags::kScopesRoute); + root_node.childrenInTraversalOrder = {1, 3}; + root_node.childrenInHitTestOrder = {1, 3}; + nodes[root_node.id] = root_node; + bridge->UpdateSemantics(/*nodes=*/nodes, /*actions=*/actions); + + XCTAssertEqual([accessibility_notifications count], 1ul); + XCTAssertEqualObjects(accessibility_notifications[0][@"argument"], @"node1"); + XCTAssertEqual([accessibility_notifications[0][@"notification"] unsignedIntValue], + UIAccessibilityScreenChangedNotification); + + // Simulates the focusing on the node 0. + bridge->AccessibilityObjectDidBecomeFocused(0); + + flutter::SemanticsNodeUpdates new_nodes; + + flutter::SemanticsNode new_node1; + new_node1.id = 1; + new_node1.label = "new_node1"; + new_node1.flags = static_cast(flutter::SemanticsFlags::kScopesRoute) | + static_cast(flutter::SemanticsFlags::kNamesRoute); + new_node1.childrenInTraversalOrder = {2}; + new_node1.childrenInHitTestOrder = {2}; + new_nodes[new_node1.id] = new_node1; + flutter::SemanticsNode new_node2; + new_node2.id = 2; + new_node2.label = "new_node2"; + new_node2.flags = static_cast(flutter::SemanticsFlags::kScopesRoute) | + static_cast(flutter::SemanticsFlags::kNamesRoute); + new_nodes[new_node2.id] = new_node2; + flutter::SemanticsNode new_root_node; + new_root_node.id = kRootNodeId; + new_root_node.flags = static_cast(flutter::SemanticsFlags::kScopesRoute); + new_root_node.childrenInTraversalOrder = {1}; + new_root_node.childrenInHitTestOrder = {1}; + new_nodes[new_root_node.id] = new_root_node; + bridge->UpdateSemantics(/*nodes=*/new_nodes, /*actions=*/actions); + XCTAssertEqual([accessibility_notifications count], 3ul); + XCTAssertEqualObjects(accessibility_notifications[1][@"argument"], @"new_node2"); + XCTAssertEqual([accessibility_notifications[1][@"notification"] unsignedIntValue], + UIAccessibilityScreenChangedNotification); + SemanticsObject* focusObject = accessibility_notifications[2][@"argument"]; + // It should still focus the root. + XCTAssertEqual([focusObject uid], 0); + XCTAssertEqual([accessibility_notifications[2][@"notification"] unsignedIntValue], + UIAccessibilityLayoutChangedNotification); +} + - (void)testAnnouncesRouteChangesWhenAddAdditionalRoute { flutter::MockDelegate mock_delegate; auto thread_task_runner = CreateNewThread("AccessibilityBridgeTest");