API Reference 0.7.1rikulo_gestureDragGesture

DragGesture abstract class

A touch-and-drag gesture handler

abstract class DragGesture extends Gesture {
 final DragGestureStart _start;
 final DragGestureMove _move;
 final DragGestureEnd _end;
 DragGestureState _state;
 bool _disabled = false;

 /** Constructor.
  *
  * + [owner] is the owner of this drag gesture.
  * + [start] is the callback before starting dragging. The returned element
  * will be the element being moved.
  * If it returns false, the dragging won't be activated.
  * + [end] is the callback when the dragging is ended. Unlike other callbacks,
  * it must be specified.
  * + [move] is the allowed movement to consider if a user is dragging a touch.
  * The user has to drag more than this number to activate the dragging.
  * If negative, it is ignored, i.e., it is considered as dragging as long
  * as the touch starts.
  * Default: -1 (unit: pixels)
  */
 factory DragGesture(Element owner, {DragGestureStart start, 
 DragGestureMove move, DragGestureEnd end})
 => browser.touch ?
     new _TouchDragGesture(owner, start: start, move: move, end: end) :
     new _MouseDragGesture(owner, start: start, move: move, end: end);
 //for subclass to call
 DragGesture._init(this.owner, this._start, this._move, this._end) {
   _listen();
 }
 /** The element that owns this drag gesture (never null).
  */
 final Element owner;

 @override
 void destroy() {
   stop();
   _unlisten();
 }
 @override
 void disable() {
   stop();
   _disabled = true;
 }
 @override
 void enable() {
   _disabled = false;
 }
 @override
 void stop() {
   _state = null;
 }
 
 void _listen();
 void _unlisten();
 
 void _touchStart(Element target, Point position, int time) {
   if (_disabled)
     return;
   stop();

   _state = new DragGestureState._(this, target, position, time);
   if (_start != null && identical(_start(_state), false))
     stop();
 }
 void _touchMove(Point position, int time) {
   if (_state != null) {
     _state.snapshot(position, time);
     
     if (_move != null && identical(_move(_state), false))
       stop();
   }
 }
 void _touchEnd() {
   if (_state != null && _end != null)
     _end(_state);
   stop();
 }
}

Extends

Gesture > DragGesture

Constructors

factory DragGesture(Element owner, {DragGestureStart start, DragGestureMove move, DragGestureEnd end}) #

Constructor.

  • owner is the owner of this drag gesture.
  • start is the callback before starting dragging. The returned element will be the element being moved. If it returns false, the dragging won't be activated.

  • end is the callback when the dragging is ended. Unlike other callbacks, it must be specified.

  • move is the allowed movement to consider if a user is dragging a touch. The user has to drag more than this number to activate the dragging. If negative, it is ignored, i.e., it is considered as dragging as long as the touch starts. Default: -1 (unit: pixels)

factory DragGesture(Element owner, {DragGestureStart start, 
DragGestureMove move, DragGestureEnd end})
=> browser.touch ?
   new _TouchDragGesture(owner, start: start, move: move, end: end) :
   new _MouseDragGesture(owner, start: start, move: move, end: end);

Properties

final Element owner #

The element that owns this drag gesture (never null).

final Element owner

Methods

void destroy() #

Destroy the gesture. It shall be called to clean up, if it is no longer in use.

docs inherited from Gesture
@override
void destroy() {
 stop();
 _unlisten();
}

void disable() #

Disable the gesture. The current action will be immediately stopped, if any.

docs inherited from Gesture
@override
void disable() {
 stop();
 _disabled = true;
}

void enable() #

Enable the gesture.

docs inherited from Gesture
@override
void enable() {
 _disabled = false;
}

void stop() #

Stop the current action, if any.

docs inherited from Gesture
@override
void stop() {
 _state = null;
}