Unverified Commit b32c77a0 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Use scrollPhysics.allowImplicitScrolling to configure scrollable semantics (#20210)

parent 57d8930d
...@@ -3136,6 +3136,18 @@ class SemanticsConfiguration { ...@@ -3136,6 +3136,18 @@ class SemanticsConfiguration {
_setFlag(SemanticsFlag.isObscured, value); _setFlag(SemanticsFlag.isObscured, value);
} }
/// Whether the platform can scroll the semantics node when the user attempts
/// to move focus to an offscreen child.
///
/// For example, a [ListView] widget has implicit scrolling so that users can
/// easily move to the next visible set of children. A [TabBar] widget does
/// not have implicit scrolling, so that users can navigate into the tab
/// body when reaching the end of the tab bar.
bool get hasImplicitScrolling => _hasFlag(SemanticsFlag.hasImplicitScrolling);
set hasImplicitScrolling(bool value) {
_setFlag(SemanticsFlag.hasImplicitScrolling, value);
}
/// The currently selected text (or the position of the cursor) within [value] /// The currently selected text (or the position of the cursor) within [value]
/// if this node represents a text field. /// if this node represents a text field.
TextSelection get textSelection => _textSelection; TextSelection get textSelection => _textSelection;
......
...@@ -508,6 +508,7 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin ...@@ -508,6 +508,7 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin
key: _excludableScrollSemanticsKey, key: _excludableScrollSemanticsKey,
child: result, child: result,
position: position, position: position,
allowImplicitScrolling: widget?.physics?.allowImplicitScrolling ?? false,
); );
} }
...@@ -539,25 +540,39 @@ class _ExcludableScrollSemantics extends SingleChildRenderObjectWidget { ...@@ -539,25 +540,39 @@ class _ExcludableScrollSemantics extends SingleChildRenderObjectWidget {
const _ExcludableScrollSemantics({ const _ExcludableScrollSemantics({
Key key, Key key,
@required this.position, @required this.position,
@required this.allowImplicitScrolling,
Widget child Widget child
}) : assert(position != null), super(key: key, child: child); }) : assert(position != null), super(key: key, child: child);
final ScrollPosition position; final ScrollPosition position;
final bool allowImplicitScrolling;
@override @override
_RenderExcludableScrollSemantics createRenderObject(BuildContext context) => new _RenderExcludableScrollSemantics(position: position); _RenderExcludableScrollSemantics createRenderObject(BuildContext context) {
return new _RenderExcludableScrollSemantics(
position: position,
allowImplicitScrolling: allowImplicitScrolling,
);
}
@override @override
void updateRenderObject(BuildContext context, _RenderExcludableScrollSemantics renderObject) { void updateRenderObject(BuildContext context, _RenderExcludableScrollSemantics renderObject) {
renderObject.position = position; renderObject
..allowImplicitScrolling = allowImplicitScrolling
..position = position;
} }
} }
class _RenderExcludableScrollSemantics extends RenderProxyBox { class _RenderExcludableScrollSemantics extends RenderProxyBox {
_RenderExcludableScrollSemantics({ _RenderExcludableScrollSemantics({
@required ScrollPosition position, @required ScrollPosition position,
@required bool allowImplicitScrolling,
RenderBox child, RenderBox child,
}) : _position = position, assert(position != null), super(child) { }) : _position = position,
_allowImplicitScrolling = allowImplicitScrolling,
assert(position != null), super(child) {
position.addListener(markNeedsSemanticsUpdate); position.addListener(markNeedsSemanticsUpdate);
} }
...@@ -574,12 +589,23 @@ class _RenderExcludableScrollSemantics extends RenderProxyBox { ...@@ -574,12 +589,23 @@ class _RenderExcludableScrollSemantics extends RenderProxyBox {
markNeedsSemanticsUpdate(); markNeedsSemanticsUpdate();
} }
/// Whether this node can be scrolled implicitly.
bool get allowImplicitScrolling => _allowImplicitScrolling;
bool _allowImplicitScrolling;
set allowImplicitScrolling(bool value) {
if (value == _allowImplicitScrolling)
return;
_allowImplicitScrolling = value;
markNeedsSemanticsUpdate();
}
@override @override
void describeSemanticsConfiguration(SemanticsConfiguration config) { void describeSemanticsConfiguration(SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config); super.describeSemanticsConfiguration(config);
config.isSemanticBoundary = true; config.isSemanticBoundary = true;
if (position.haveDimensions) { if (position.haveDimensions) {
config config
..hasImplicitScrolling = allowImplicitScrolling
..scrollPosition = _position.pixels ..scrollPosition = _position.pixels
..scrollExtentMax = _position.maxScrollExtent ..scrollExtentMax = _position.maxScrollExtent
..scrollExtentMin = _position.minScrollExtent; ..scrollExtentMin = _position.minScrollExtent;
......
...@@ -428,6 +428,7 @@ void _defineTests() { ...@@ -428,6 +428,7 @@ void _defineTests() {
flags flags
..remove(SemanticsFlag.hasImplicitScrolling) ..remove(SemanticsFlag.hasImplicitScrolling)
..remove(SemanticsFlag.hasToggledState) ..remove(SemanticsFlag.hasToggledState)
..remove(SemanticsFlag.hasImplicitScrolling)
..remove(SemanticsFlag.isToggled); ..remove(SemanticsFlag.isToggled);
TestSemantics expectedSemantics = new TestSemantics.root( TestSemantics expectedSemantics = new TestSemantics.root(
children: <TestSemantics>[ children: <TestSemantics>[
...@@ -473,6 +474,7 @@ void _defineTests() { ...@@ -473,6 +474,7 @@ void _defineTests() {
flags flags
..remove(SemanticsFlag.hasImplicitScrolling) ..remove(SemanticsFlag.hasImplicitScrolling)
..remove(SemanticsFlag.hasCheckedState) ..remove(SemanticsFlag.hasCheckedState)
..remove(SemanticsFlag.hasImplicitScrolling)
..remove(SemanticsFlag.isChecked); ..remove(SemanticsFlag.isChecked);
expectedSemantics = new TestSemantics.root( expectedSemantics = new TestSemantics.root(
......
...@@ -342,6 +342,9 @@ void main() { ...@@ -342,6 +342,9 @@ void main() {
new TestSemantics.rootChild( new TestSemantics.rootChild(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
flags: <SemanticsFlag>[
SemanticsFlag.hasImplicitScrolling,
],
actions: <SemanticsAction>[SemanticsAction.scrollUp], actions: <SemanticsAction>[SemanticsAction.scrollUp],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
......
...@@ -486,9 +486,9 @@ void main() { ...@@ -486,9 +486,9 @@ void main() {
); );
final List<SemanticsFlag> flags = SemanticsFlag.values.values.toList(); final List<SemanticsFlag> flags = SemanticsFlag.values.values.toList();
flags flags
..remove(SemanticsFlag.hasImplicitScrolling)
..remove(SemanticsFlag.hasToggledState) ..remove(SemanticsFlag.hasToggledState)
..remove(SemanticsFlag.isToggled); ..remove(SemanticsFlag.isToggled)
..remove(SemanticsFlag.hasImplicitScrolling);
TestSemantics expectedSemantics = new TestSemantics.root( TestSemantics expectedSemantics = new TestSemantics.root(
children: <TestSemantics>[ children: <TestSemantics>[
......
...@@ -116,6 +116,7 @@ void _tests() { ...@@ -116,6 +116,7 @@ void _tests() {
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
id: 6, id: 6,
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
id: 4, id: 4,
......
...@@ -384,6 +384,9 @@ void _tests() { ...@@ -384,6 +384,9 @@ void _tests() {
new TestSemantics( new TestSemantics(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
flags: <SemanticsFlag>[
SemanticsFlag.hasImplicitScrolling,
],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
label: 'Item 4', label: 'Item 4',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment