Unverified Commit c5047e0a authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

2DScrollView - Fix drag when one axis does not have enough content (#145566)

Fixes https://github.com/flutter/flutter/issues/144982
For reference, may have to do with #138442 when we reworked the gesture handling. The adjustments to the comments here were certainly from #138442 not updating them. Confused myself for a minute or two. 🙃
parent 14774b95
......@@ -1982,6 +1982,7 @@ class TwoDimensionalScrollableState extends State<TwoDimensionalScrollable> {
viewportBuilder: (BuildContext context, ViewportOffset verticalOffset) {
return _HorizontalInnerDimension(
key: _horizontalInnerScrollableKey,
verticalOuterKey: _verticalOuterScrollableKey,
axisDirection: widget.horizontalDetails.direction,
controller: widget.horizontalDetails.controller
?? _horizontalFallbackController!,
......@@ -2250,9 +2251,9 @@ class _VerticalOuterDimensionState extends ScrollableState {
if (value) {
// Replaces the typical vertical/horizontal drag gesture recognizers
// with a pan gesture recognizer to allow bidirectional scrolling.
// Based on the diagonalDragBehavior, valid horizontal deltas are
// applied to this scrollable, while vertical deltas are routed to
// the vertical scrollable.
// Based on the diagonalDragBehavior, valid vertical deltas are
// applied to this scrollable, while horizontal deltas are routed to
// the horizontal scrollable.
_gestureRecognizers = <Type, GestureRecognizerFactory>{
PanGestureRecognizer: GestureRecognizerFactoryWithHandlers<PanGestureRecognizer>(
() => PanGestureRecognizer(supportedDevices: _configuration.dragDevices),
......@@ -2303,6 +2304,7 @@ class _VerticalOuterDimensionState extends ScrollableState {
class _HorizontalInnerDimension extends Scrollable {
const _HorizontalInnerDimension({
super.key,
required this.verticalOuterKey,
required super.viewportBuilder,
required super.axisDirection,
super.controller,
......@@ -2315,6 +2317,7 @@ class _HorizontalInnerDimension extends Scrollable {
this.diagonalDragBehavior = DiagonalDragBehavior.none,
}) : assert(axisDirection == AxisDirection.left || axisDirection == AxisDirection.right);
final GlobalKey<ScrollableState> verticalOuterKey;
final DiagonalDragBehavior diagonalDragBehavior;
@override
......@@ -2324,6 +2327,7 @@ class _HorizontalInnerDimension extends Scrollable {
class _HorizontalInnerDimensionState extends ScrollableState {
late ScrollableState verticalScrollable;
GlobalKey<ScrollableState> get verticalOuterKey => (widget as _HorizontalInnerDimension).verticalOuterKey;
DiagonalDragBehavior get diagonalDragBehavior => (widget as _HorizontalInnerDimension).diagonalDragBehavior;
@override
......@@ -2379,9 +2383,12 @@ class _HorizontalInnerDimensionState extends ScrollableState {
case DiagonalDragBehavior.free:
if (value) {
// If a type of diagonal scrolling is enabled, a panning gesture
// recognizer will be created for the _InnerDimension. So in this
// case, the _OuterDimension does not require a gesture recognizer.
// recognizer will be created for the _VerticalOuterDimension. So in
// this case, the _HorizontalInnerDimension does not require a gesture
// recognizer, meanwhile we should ensure the outer dimension has
// updated in case it did not have enough content to enable dragging.
_gestureRecognizers = const <Type, GestureRecognizerFactory>{};
verticalOuterKey.currentState!.setCanDrag(value);
// Cancel the active hold/drag (if any) because the gesture recognizers
// will soon be disposed by our RawGestureDetector, and we won't be
// receiving pointer up events to cancel the hold/drag.
......
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