mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This PR fixes https://github.com/flutter/flutter/issues/128468 by changing the relationship between semantics nodes and their roles from this: ``` SemanticsNode one-to-many RoleManager ``` To this: ``` SemanticsNode one-to-one PrimaryRoleManager one-to-many RoleManager ``` Previously a node would simply have multiple role managers, some of which would be responsible for setting the `role` attribute. It wasn't clear which role manager should be doing this. It also wasn't clear which role managers were safe to reuse across multiple types of nodes. This led to the unfortunate situation in https://github.com/flutter/flutter/issues/128468 where `LabelAndValue` ended up overriding the role assigned by `Checkable`. With this PR, a `SemanticsNode` has exactly one `PrimaryRoleManager`. A primary role manager is responsible for setting the `role` attribute, and importantly, it's the _only_ thing responsible for it. It's _not safe_ to share primary role managers across different kinds of nodes. They are meant to provide very specific functionality for the widget's main role. OTOH, a non-primary `RoleManager` provides a piece of functionality that's safe to share. A `Checkable` is a `PrimaryRoleManager` and is the only thing that decides on the `role` attribute. `LabelAndValue` is now a `RoleManager` that's not responsible for setting the role. It's only responsible for `aria-label`. No more confusion. This also drastically simplifies the logic for role assignment. There's no more [logical soup](d4889c682d/lib/web_ui/lib/src/engine/semantics/semantics.dart (L1340)) attempting to find a good subset of roles to assign to a node. [Finding](93df91df95/lib/web_ui/lib/src/engine/semantics/semantics.dart (L1477)) and [instantiating](93df91df95/lib/web_ui/lib/src/engine/semantics/semantics.dart (L1498)) primary roles are very linear steps, as is [assigning a set of secondary roles](93df91df95/lib/web_ui/lib/src/engine/semantics/image.dart (L16)).
Description
Flutter makes it easy and fast to build beautiful apps for mobile and beyond
androidapp-frameworkcross-platformdartdart-platformdesktopflutterflutter-packagefuchsiaioslinux-desktopmacosmaterial-designmobilemobile-developmentskiawebweb-frameworkwindows
2.5 GiB
Languages
Dart
75%
C++
16.5%
Objective-C++
2.9%
Java
2.8%
Objective-C
0.7%
Other
1.9%