-
Notifications
You must be signed in to change notification settings - Fork 28.7k
SliverSemantics #167300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
SliverSemantics #167300
Conversation
cd37169
to
b42e20d
Compare
02769d5
to
7202c32
Compare
7202c32
to
ad7e10d
Compare
432ea93
to
88b0c8a
Compare
152fe42
to
172f614
Compare
172f614
to
763928e
Compare
}); | ||
|
||
testWidgets( | ||
'does not merge conflicting actions even if one of them is blocked with Semantics widget', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too sure if the expected explicitChildNodes: true
is the way to solve the issues with this test.
For context this test comes from:
flutter/packages/flutter/test/widgets/semantics_test.dart
Lines 1588 to 1622 in 48c6ef2
testWidgets('does not merge conflicting actions even if one of them is blocked', ( | |
WidgetTester tester, | |
) async { | |
final UniqueKey key = UniqueKey(); | |
await tester.pumpWidget( | |
MaterialApp( | |
home: Semantics( | |
key: key, | |
container: true, | |
child: Column( | |
children: <Widget>[ | |
Semantics( | |
blockUserActions: true, | |
label: 'label1', | |
onTap: () {}, | |
child: const SizedBox(width: 10, height: 10), | |
), | |
Semantics( | |
label: 'label2', | |
onTap: () {}, | |
child: const SizedBox(width: 10, height: 10), | |
), | |
], | |
), | |
), | |
), | |
); | |
final SemanticsNode node = tester.getSemantics(find.byKey(key)); | |
expect( | |
node, | |
matchesSemantics( | |
children: <Matcher>[containsSemantics(label: 'label1'), containsSemantics(label: 'label2')], | |
), | |
); | |
}); |
In the test above the nodes under Column
are not merged, but in this sliver test, the nodes under SliverList
are merged, unless I use explicitChildNodes
true in the SliverSemantics
widget above the SliverList
. I debugged and found that the cause for this is because SliverList adds semantics indexes with IndexedSemantics
. If we do addSemanticIndexes: false
, then this test also passes.
In the original test from semantics_test.dart
if I add an IndexedSemantics
around each child of the Column
then we run into the same issue where the nodes under the Column
are merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created an issue #170485 and updated test to use SliverToBoxAdapter
-> Column
for now.
Google testing is failing because there already exists a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall approach LGTM, just some suggestions to make code a bit cleaner
/// for their subtree. | ||
mixin SemanticsAnnotationsMixin on RenderObject { | ||
/// Initializes the semantics annotations for this mixin. | ||
void initSemanticsAnnotations({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is not meant to be developer facing API. I will turn all the parameter to be required just so that one day we add parameter to the list, we won't forget to update all the internal reference
/// A sliver that annotates its subtree with a description of the meaning of | ||
/// the slivers. | ||
/// | ||
/// Used by assistive technologies, search engines, and other semantic analysis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this use template to deduplicate the doc between this and Semantics widget
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, but do you think both should point to the same youtube video since the video talks about the Semantics
widget. They're essentially used the same way, but it may be confusing to some? What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I think this is confusing. I think we should exclude the video out of sliver version of doc
/// | ||
/// See also: | ||
/// | ||
/// * [SemanticsProperties], which contains a complete documentation for each |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a link to Semantics widget
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for the breadcumb in Semantics widget.
/// to create semantic boundaries that are either writable or not for children. | ||
final bool explicitChildNodes; | ||
|
||
/// Whether to replace all child semantics with this node. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
most of this can be doc string
|
||
/// Contains properties used by assistive technologies to make the application | ||
/// more accessible. | ||
final SemanticsProperties properties; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can any of these and the Semantics counter part to be factored out into a mixin. Asking this because adding a flag/property in semantics is already cumbersome, would appreciate we don't add another place that needs to be updated...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! I'll look into ways we can do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about this approach? f22a87a
(#167300)
A base class used by both Semantics
and SliverSemantics
called SemanticsBase
where SemanticsBase
has its own constructor with every field marked as required
. This enforces its subclasses to add that field to their constructor whenever a new one is added to SemanticsBase
.
In this world, when we add a new field to SemanticsBase
and mark it required, an analyzer error will appear pointing us to add the same field to its subclasses Semantics
and SliverSemantics
.
763928e
to
820c45d
Compare
3e881a7
to
5587ac5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, would be good if we can make it private, but not blocking the pr merge
/// be enabled using [WidgetsApp.showSemanticsDebugger], | ||
/// [MaterialApp.showSemanticsDebugger], or [CupertinoApp.showSemanticsDebugger]. | ||
/// {@endtemplate} | ||
sealed class SemanticsBase extends SingleChildRenderObjectWidget { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for refactor this out it is a lot less duplicated code now, I wonder if this can be private? not sure whether the api doc still work if we make it private though.
Fixes #166785
Pre-launch Checklist
///
).