Commit 46b316c4 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Change RawGestureDetector API to be better for strong mode Dart. (#10553)

parent b5365d93
...@@ -189,10 +189,13 @@ class _PointDemoState extends State<_PointDemo> { ...@@ -189,10 +189,13 @@ class _PointDemoState extends State<_PointDemo> {
return new RawGestureDetector( return new RawGestureDetector(
behavior: _dragTarget == null ? HitTestBehavior.deferToChild : HitTestBehavior.opaque, behavior: _dragTarget == null ? HitTestBehavior.deferToChild : HitTestBehavior.opaque,
gestures: <Type, GestureRecognizerFactory>{ gestures: <Type, GestureRecognizerFactory>{
ImmediateMultiDragGestureRecognizer: (ImmediateMultiDragGestureRecognizer recognizer) { // ignore: map_value_type_not_assignable, https://github.com/flutter/flutter/issues/5771 ImmediateMultiDragGestureRecognizer: new GestureRecognizerFactoryWithHandlers<ImmediateMultiDragGestureRecognizer>(
return (recognizer ??= new ImmediateMultiDragGestureRecognizer()) () => new ImmediateMultiDragGestureRecognizer(),
..onStart = _handleOnStart; (ImmediateMultiDragGestureRecognizer instance) {
} instance
..onStart = _handleOnStart;
},
),
}, },
child: new ClipRect( child: new ClipRect(
child: new CustomPaint( child: new CustomPaint(
...@@ -359,10 +362,13 @@ class _RectangleDemoState extends State<_RectangleDemo> { ...@@ -359,10 +362,13 @@ class _RectangleDemoState extends State<_RectangleDemo> {
return new RawGestureDetector( return new RawGestureDetector(
behavior: _dragTarget == null ? HitTestBehavior.deferToChild : HitTestBehavior.opaque, behavior: _dragTarget == null ? HitTestBehavior.deferToChild : HitTestBehavior.opaque,
gestures: <Type, GestureRecognizerFactory>{ gestures: <Type, GestureRecognizerFactory>{
ImmediateMultiDragGestureRecognizer: (ImmediateMultiDragGestureRecognizer recognizer) { // ignore: map_value_type_not_assignable, https://github.com/flutter/flutter/issues/5771 ImmediateMultiDragGestureRecognizer: new GestureRecognizerFactoryWithHandlers<ImmediateMultiDragGestureRecognizer>(
return (recognizer ??= new ImmediateMultiDragGestureRecognizer()) () => new ImmediateMultiDragGestureRecognizer(),
..onStart = _handleOnStart; (ImmediateMultiDragGestureRecognizer instance) {
} instance
..onStart = _handleOnStart;
},
),
}, },
child: new ClipRect( child: new ClipRect(
child: new CustomPaint( child: new CustomPaint(
......
...@@ -721,18 +721,22 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -721,18 +721,22 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
NavigationGestureController _backGestureController; NavigationGestureController _backGestureController;
bool _shouldHandleBackGesture() { bool _shouldHandleBackGesture() {
assert(mounted);
return Theme.of(context).platform == TargetPlatform.iOS && Navigator.canPop(context); return Theme.of(context).platform == TargetPlatform.iOS && Navigator.canPop(context);
} }
void _handleDragStart(DragStartDetails details) { void _handleDragStart(DragStartDetails details) {
assert(mounted);
_backGestureController = Navigator.of(context).startPopGesture(); _backGestureController = Navigator.of(context).startPopGesture();
} }
void _handleDragUpdate(DragUpdateDetails details) { void _handleDragUpdate(DragUpdateDetails details) {
assert(mounted);
_backGestureController?.dragUpdate(details.primaryDelta / context.size.width); _backGestureController?.dragUpdate(details.primaryDelta / context.size.width);
} }
void _handleDragEnd(DragEndDetails details) { void _handleDragEnd(DragEndDetails details) {
assert(mounted);
final bool willPop = _backGestureController?.dragEnd(details.velocity.pixelsPerSecond.dx / context.size.width) ?? false; final bool willPop = _backGestureController?.dragEnd(details.velocity.pixelsPerSecond.dx / context.size.width) ?? false;
if (willPop) if (willPop)
_currentBottomSheet?.close(); _currentBottomSheet?.close();
...@@ -740,6 +744,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -740,6 +744,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
} }
void _handleDragCancel() { void _handleDragCancel() {
assert(mounted);
final bool willPop = _backGestureController?.dragEnd(0.0) ?? false; final bool willPop = _backGestureController?.dragEnd(0.0) ?? false;
if (willPop) if (willPop)
_currentBottomSheet?.close(); _currentBottomSheet?.close();
......
...@@ -327,32 +327,38 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin ...@@ -327,32 +327,38 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin
switch (widget.axis) { switch (widget.axis) {
case Axis.vertical: case Axis.vertical:
_gestureRecognizers = <Type, GestureRecognizerFactory>{ _gestureRecognizers = <Type, GestureRecognizerFactory>{
VerticalDragGestureRecognizer: (VerticalDragGestureRecognizer recognizer) { // ignore: map_value_type_not_assignable, https://github.com/flutter/flutter/issues/7173 VerticalDragGestureRecognizer: new GestureRecognizerFactoryWithHandlers<VerticalDragGestureRecognizer>(
return (recognizer ??= new VerticalDragGestureRecognizer()) () => new VerticalDragGestureRecognizer(),
..onDown = _handleDragDown (VerticalDragGestureRecognizer instance) {
..onStart = _handleDragStart instance
..onUpdate = _handleDragUpdate ..onDown = _handleDragDown
..onEnd = _handleDragEnd ..onStart = _handleDragStart
..onCancel = _handleDragCancel ..onUpdate = _handleDragUpdate
..minFlingDistance = _physics?.minFlingDistance ..onEnd = _handleDragEnd
..minFlingVelocity = _physics?.minFlingVelocity ..onCancel = _handleDragCancel
..maxFlingVelocity = _physics?.maxFlingVelocity; ..minFlingDistance = _physics?.minFlingDistance
} ..minFlingVelocity = _physics?.minFlingVelocity
..maxFlingVelocity = _physics?.maxFlingVelocity;
},
),
}; };
break; break;
case Axis.horizontal: case Axis.horizontal:
_gestureRecognizers = <Type, GestureRecognizerFactory>{ _gestureRecognizers = <Type, GestureRecognizerFactory>{
HorizontalDragGestureRecognizer: (HorizontalDragGestureRecognizer recognizer) { // ignore: map_value_type_not_assignable, https://github.com/flutter/flutter/issues/7173 HorizontalDragGestureRecognizer: new GestureRecognizerFactoryWithHandlers<HorizontalDragGestureRecognizer>(
return (recognizer ??= new HorizontalDragGestureRecognizer()) () => new HorizontalDragGestureRecognizer(),
..onDown = _handleDragDown (HorizontalDragGestureRecognizer instance) {
..onStart = _handleDragStart instance
..onUpdate = _handleDragUpdate ..onDown = _handleDragDown
..onEnd = _handleDragEnd ..onStart = _handleDragStart
..onCancel = _handleDragCancel ..onUpdate = _handleDragUpdate
..minFlingDistance = _physics?.minFlingDistance ..onEnd = _handleDragEnd
..minFlingVelocity = _physics?.minFlingVelocity ..onCancel = _handleDragCancel
..maxFlingVelocity = _physics?.maxFlingVelocity; ..minFlingDistance = _physics?.minFlingDistance
} ..minFlingVelocity = _physics?.minFlingVelocity
..maxFlingVelocity = _physics?.maxFlingVelocity;
},
),
}; };
break; break;
} }
......
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