prevents sliver app bar from changing semantics tree when it is not necesaary (#61012)

This commit is contained in:
chunhtai 2020-07-08 18:21:08 -07:00 committed by GitHub
parent 06b301cdfc
commit 496ef4f77e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 59 deletions

View file

@ -258,27 +258,10 @@ abstract class RenderSliverPersistentHeader extends RenderSliver with RenderObje
}
}
/// Whether the [SemanticsNode]s associated with this [RenderSliver] should
/// be excluded from the semantic scrolling area.
///
/// [RenderSliver]s that stay on the screen even though the user has scrolled
/// past them (e.g. a pinned app bar) should set this to true.
@protected
bool get excludeFromSemanticsScrolling => _excludeFromSemanticsScrolling;
bool _excludeFromSemanticsScrolling = false;
set excludeFromSemanticsScrolling(bool value) {
if (_excludeFromSemanticsScrolling == value)
return;
_excludeFromSemanticsScrolling = value;
markNeedsSemanticsUpdate();
}
@override
void describeSemanticsConfiguration(SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config);
if (_excludeFromSemanticsScrolling)
config.addTagForChildren(RenderViewport.excludeFromScrolling);
config.addTagForChildren(RenderViewport.excludeFromScrolling);
}
@override
@ -375,7 +358,6 @@ abstract class RenderSliverPinnedPersistentHeader extends RenderSliverPersistent
final SliverConstraints constraints = this.constraints;
final double maxExtent = this.maxExtent;
final bool overlapsContent = constraints.overlap > 0.0;
excludeFromSemanticsScrolling = overlapsContent || (constraints.scrollOffset > maxExtent - minExtent);
layoutChild(constraints.scrollOffset, maxExtent, overlapsContent: overlapsContent);
final double effectiveRemainingPaintExtent = math.max(0, constraints.remainingPaintExtent - constraints.overlap);
final double layoutExtent = (maxExtent - constraints.scrollOffset).clamp(0.0, effectiveRemainingPaintExtent) as double;
@ -575,7 +557,6 @@ abstract class RenderSliverFloatingPersistentHeader extends RenderSliverPersiste
} else {
_effectiveScrollOffset = constraints.scrollOffset;
}
excludeFromSemanticsScrolling = _effectiveScrollOffset <= constraints.scrollOffset;
final bool overlapsContent = _effectiveScrollOffset < constraints.scrollOffset;
layoutChild(

View file

@ -1647,22 +1647,20 @@ void main() {
TestSemantics(
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
children: <TestSemantics>[
TestSemantics(
children: <TestSemantics>[
TestSemantics(
label: 'Leading',
textDirection: TextDirection.ltr,
),
TestSemantics(
label: 'Action 1',
textDirection: TextDirection.ltr,
),
],
label: 'Leading',
textDirection: TextDirection.ltr,
),
TestSemantics(
label: 'Action 1',
textDirection: TextDirection.ltr,
),
],
),
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
),
],
),
],

View file

@ -79,6 +79,20 @@ void _tests() {
TestSemantics(
id: 2,
children: <TestSemantics>[
TestSemantics(
id: 7,
children: <TestSemantics>[
TestSemantics(
id: 8,
flags: <SemanticsFlag>[
SemanticsFlag.namesRoute,
SemanticsFlag.isHeader,
],
label: 'Semantics Test with Slivers',
textDirection: TextDirection.ltr,
),
],
),
TestSemantics(
id: 9,
flags: <SemanticsFlag>[
@ -86,20 +100,6 @@ void _tests() {
],
actions: <SemanticsAction>[SemanticsAction.scrollUp],
children: <TestSemantics>[
TestSemantics(
id: 7,
children: <TestSemantics>[
TestSemantics(
id: 8,
flags: <SemanticsFlag>[
SemanticsFlag.namesRoute,
SemanticsFlag.isHeader,
],
label: 'Semantics Test with Slivers',
textDirection: TextDirection.ltr,
),
],
),
TestSemantics(
id: 3,
label: 'Item 0',
@ -226,6 +226,20 @@ void _tests() {
TestSemantics(
id: 2,
children: <TestSemantics>[
TestSemantics(
id: 7,
children: <TestSemantics>[
TestSemantics(
id: 8,
flags: <SemanticsFlag>[
SemanticsFlag.namesRoute,
SemanticsFlag.isHeader,
],
label: 'Semantics Test with Slivers',
textDirection: TextDirection.ltr,
),
],
),
TestSemantics(
id: 9,
flags: <SemanticsFlag>[
@ -236,20 +250,6 @@ void _tests() {
SemanticsAction.scrollDown,
],
children: <TestSemantics>[
TestSemantics(
id: 7,
children: <TestSemantics>[
TestSemantics(
id: 8,
flags: <SemanticsFlag>[
SemanticsFlag.namesRoute,
SemanticsFlag.isHeader,
],
label: 'Semantics Test with Slivers',
textDirection: TextDirection.ltr,
),
],
),
TestSemantics(
id: 3,
label: 'Item 0',