Commit d76f5652 authored by Adam Barth's avatar Adam Barth

Merge pull request #1120 from abarth/fewer_handlers

Don't register gesture detectors when Scrollable can't scroll
parents dfab52c7 707d8606
...@@ -19,6 +19,9 @@ abstract class ScrollBehavior { ...@@ -19,6 +19,9 @@ abstract class ScrollBehavior {
/// The new scroll offset to use when the user attempts to scroll from the given offset by the given delta /// The new scroll offset to use when the user attempts to scroll from the given offset by the given delta
double applyCurve(double scrollOffset, double scrollDelta); double applyCurve(double scrollOffset, double scrollDelta);
/// Whether this scroll behavior currently permits scrolling
bool get isScrollable => true;
} }
/// A scroll behavior for a scrollable widget with linear extent /// A scroll behavior for a scrollable widget with linear extent
......
...@@ -9,6 +9,7 @@ import 'dart:sky' as sky; ...@@ -9,6 +9,7 @@ import 'dart:sky' as sky;
import 'package:newton/newton.dart'; import 'package:newton/newton.dart';
import 'package:sky/animation.dart'; import 'package:sky/animation.dart';
import 'package:sky/gestures/constants.dart'; import 'package:sky/gestures/constants.dart';
import 'package:sky/gestures/scroll.dart';
import 'package:sky/src/rendering/box.dart'; import 'package:sky/src/rendering/box.dart';
import 'package:sky/src/rendering/viewport.dart'; import 'package:sky/src/rendering/viewport.dart';
import 'package:sky/src/widgets/basic.dart'; import 'package:sky/src/widgets/basic.dart';
...@@ -79,13 +80,25 @@ abstract class Scrollable extends StatefulComponent { ...@@ -79,13 +80,25 @@ abstract class Scrollable extends StatefulComponent {
Widget buildContent(); Widget buildContent();
GestureDragUpdateCallback _getDragUpdateHandler(ScrollDirection direction) {
if (scrollDirection != direction || !scrollBehavior.isScrollable)
return null;
return scrollBy;
}
GestureDragEndCallback _getDragEndHandler(ScrollDirection direction) {
if (scrollDirection != direction || !scrollBehavior.isScrollable)
return null;
return _maybeSettleScrollOffset;
}
Widget build() { Widget build() {
return new GestureDetector( return new GestureDetector(
onVerticalDragUpdate: scrollDirection == ScrollDirection.vertical ? scrollBy : null, onVerticalDragUpdate: _getDragUpdateHandler(ScrollDirection.vertical),
onVerticalDragEnd: scrollDirection == ScrollDirection.vertical ? _maybeSettleScrollOffset : null, onVerticalDragEnd: _getDragEndHandler(ScrollDirection.vertical),
onHorizontalDragUpdate: scrollDirection == ScrollDirection.horizontal ? scrollBy : null, onHorizontalDragUpdate: _getDragUpdateHandler(ScrollDirection.horizontal),
onHorizontalDragEnd: scrollDirection == ScrollDirection.horizontal ? _maybeSettleScrollOffset : null, onHorizontalDragEnd: _getDragEndHandler(ScrollDirection.horizontal),
onFling: _handleFling, onFling: scrollBehavior.isScrollable ? _handleFling : null,
child: new Listener( child: new Listener(
child: buildContent(), child: buildContent(),
onPointerDown: _handlePointerDown, onPointerDown: _handlePointerDown,
......
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