prevent ios accessibility bridge from sending notification when modal (flutter/engine#26328)
This commit is contained in:
@@ -205,25 +205,25 @@ void AccessibilityBridge::UpdateSemantics(flutter::SemanticsNodeUpdates nodes,
|
||||
VisitObjectsRecursivelyAndRemove(root, doomed_uids);
|
||||
[objects_ removeObjectsForKeys:doomed_uids];
|
||||
|
||||
layoutChanged = layoutChanged || [doomed_uids count] > 0;
|
||||
if (!ios_delegate_->IsFlutterViewControllerPresentingModalViewController(view_controller_)) {
|
||||
layoutChanged = layoutChanged || [doomed_uids count] > 0;
|
||||
|
||||
if (routeChanged) {
|
||||
if (!ios_delegate_->IsFlutterViewControllerPresentingModalViewController(view_controller_)) {
|
||||
if (routeChanged) {
|
||||
NSString* routeName = [lastAdded routeName];
|
||||
ios_delegate_->PostAccessibilityNotification(UIAccessibilityScreenChangedNotification,
|
||||
routeName);
|
||||
}
|
||||
}
|
||||
|
||||
if (layoutChanged) {
|
||||
ios_delegate_->PostAccessibilityNotification(UIAccessibilityLayoutChangedNotification,
|
||||
FindNextFocusableIfNecessary());
|
||||
} else if (scrollOccured) {
|
||||
// TODO(chunhtai): figure out what string to use for notification. At this
|
||||
// point, it is guarantee the previous focused object is still in the tree
|
||||
// so that we don't need to worry about focus lost. (e.g. "Screen 0 of 3")
|
||||
ios_delegate_->PostAccessibilityNotification(UIAccessibilityPageScrolledNotification,
|
||||
FindNextFocusableIfNecessary());
|
||||
if (layoutChanged) {
|
||||
ios_delegate_->PostAccessibilityNotification(UIAccessibilityLayoutChangedNotification,
|
||||
FindNextFocusableIfNecessary());
|
||||
} else if (scrollOccured) {
|
||||
// TODO(chunhtai): figure out what string to use for notification. At this
|
||||
// point, it is guarantee the previous focused object is still in the tree
|
||||
// so that we don't need to worry about focus lost. (e.g. "Screen 0 of 3")
|
||||
ios_delegate_->PostAccessibilityNotification(UIAccessibilityPageScrolledNotification,
|
||||
FindNextFocusableIfNecessary());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1090,7 +1090,6 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
|
||||
|
||||
flutter::SemanticsNode route_node;
|
||||
route_node.id = 1;
|
||||
route_node.label = label;
|
||||
route_node.flags = static_cast<int32_t>(flutter::SemanticsFlags::kScopesRoute) |
|
||||
static_cast<int32_t>(flutter::SemanticsFlags::kNamesRoute);
|
||||
route_node.label = "route";
|
||||
@@ -1106,6 +1105,122 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
|
||||
XCTAssertEqual([accessibility_notifications count], 0ul);
|
||||
}
|
||||
|
||||
- (void)testAnnouncesIgnoresLayoutChangeWhenModal {
|
||||
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<flutter::PlatformViewIOS>(
|
||||
/*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<NSDictionary<NSString*, id>*>* accessibility_notifications =
|
||||
[[[NSMutableArray alloc] init] autorelease];
|
||||
auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
|
||||
ios_delegate->on_PostAccessibilityNotification_ =
|
||||
[accessibility_notifications](UIAccessibilityNotifications notification, id argument) {
|
||||
[accessibility_notifications addObject:@{
|
||||
@"notification" : @(notification),
|
||||
@"argument" : argument ? argument : [NSNull null],
|
||||
}];
|
||||
};
|
||||
ios_delegate->result_IsFlutterViewControllerPresentingModalViewController_ = true;
|
||||
__block auto bridge =
|
||||
std::make_unique<flutter::AccessibilityBridge>(/*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 child_node;
|
||||
child_node.id = 1;
|
||||
child_node.label = "child_node";
|
||||
nodes[child_node.id] = child_node;
|
||||
flutter::SemanticsNode root_node;
|
||||
root_node.id = kRootNodeId;
|
||||
root_node.label = "root";
|
||||
root_node.childrenInTraversalOrder = {1};
|
||||
root_node.childrenInHitTestOrder = {1};
|
||||
nodes[root_node.id] = root_node;
|
||||
bridge->UpdateSemantics(/*nodes=*/nodes, /*actions=*/actions);
|
||||
|
||||
// Removes child_node to simulate a layout change.
|
||||
flutter::SemanticsNodeUpdates new_nodes;
|
||||
flutter::SemanticsNode new_root_node;
|
||||
new_root_node.id = kRootNodeId;
|
||||
new_root_node.label = "root";
|
||||
new_nodes[new_root_node.id] = new_root_node;
|
||||
bridge->UpdateSemantics(/*nodes=*/new_nodes, /*actions=*/actions);
|
||||
|
||||
XCTAssertEqual([accessibility_notifications count], 0ul);
|
||||
}
|
||||
|
||||
- (void)testAnnouncesIgnoresScrollChangeWhenModal {
|
||||
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<flutter::PlatformViewIOS>(
|
||||
/*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<NSDictionary<NSString*, id>*>* accessibility_notifications =
|
||||
[[[NSMutableArray alloc] init] autorelease];
|
||||
auto ios_delegate = std::make_unique<flutter::MockIosDelegate>();
|
||||
ios_delegate->on_PostAccessibilityNotification_ =
|
||||
[accessibility_notifications](UIAccessibilityNotifications notification, id argument) {
|
||||
[accessibility_notifications addObject:@{
|
||||
@"notification" : @(notification),
|
||||
@"argument" : argument ? argument : [NSNull null],
|
||||
}];
|
||||
};
|
||||
ios_delegate->result_IsFlutterViewControllerPresentingModalViewController_ = true;
|
||||
__block auto bridge =
|
||||
std::make_unique<flutter::AccessibilityBridge>(/*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 root_node;
|
||||
root_node.id = kRootNodeId;
|
||||
root_node.label = "root";
|
||||
root_node.scrollPosition = 1;
|
||||
nodes[root_node.id] = root_node;
|
||||
bridge->UpdateSemantics(/*nodes=*/nodes, /*actions=*/actions);
|
||||
|
||||
// Removes child_node to simulate a layout change.
|
||||
flutter::SemanticsNodeUpdates new_nodes;
|
||||
flutter::SemanticsNode new_root_node;
|
||||
new_root_node.id = kRootNodeId;
|
||||
new_root_node.label = "root";
|
||||
new_root_node.scrollPosition = 2;
|
||||
new_nodes[new_root_node.id] = new_root_node;
|
||||
bridge->UpdateSemantics(/*nodes=*/new_nodes, /*actions=*/actions);
|
||||
|
||||
XCTAssertEqual([accessibility_notifications count], 0ul);
|
||||
}
|
||||
|
||||
- (void)testAccessibilityMessageAfterDeletion {
|
||||
flutter::MockDelegate mock_delegate;
|
||||
auto thread = std::make_unique<fml::Thread>("AccessibilityBridgeTest");
|
||||
|
||||
Reference in New Issue
Block a user