API Reference 0.7.1rikulo_gestureHoldGesture

HoldGesture abstract class

A touch-and-hold gesture handler.

abstract class HoldGesture extends Gesture {
 final int _duration;
 final int _movementLimit;
 final HoldGestureStart _start;
 final HoldGestureAction _action;
 HoldGestureState _state;
 bool _disabled = false;
 
 /** Constructor.
  *
  * + [start] is the callback before starting monitoring the touch-and-hold
  * gesture. If it returns false, the monitoring will be cancelled.
  * + [action] is the callback when the touch-and-hold gesture is executed.
  * + [duration] is the duration that a user has to hold before calling the action.
  * Default: 1000 (unit: milliseconds)
  * + [movementLimit] is the allowed movement to consider if a user is holding a touch.
  * Default: 3 (unit: pixels)
  */
 factory HoldGesture(Element owner, HoldGestureAction action,
 {HoldGestureStart start, int duration: 1000, num movementLimit: 3}) {
   return browser.touch ?
     new _TouchHoldGesture(owner, action, start, duration, movementLimit):
     new _MouseHoldGesture(owner, action, start, duration, movementLimit);
 }
 
 HoldGesture._init(this.owner, this._action, this._start, this._duration, 
 this._movementLimit) {
   _listen();
 }
 
 /** The element that owns this handler.
  */
 final Element owner;

 @override  
 void destroy() {
   _stop();
   _unlisten();
 }
 @override  
 void stop() {
   _stop();
 }
 @override  
 void disable() {
   _stop();
   _disabled = true;
 }
 @override  
 void enable() {
   _disabled = false;
 }
 
 void _listen();
 void _unlisten();
 
 void _touchStart(EventTarget target, int time, Point position) {
   if (_disabled)
     return;
   
   _stop();
   _state = new HoldGestureState._(this, target, time, position);
   
   if (_start != null && identical(_start(_state), false)) {
     _stop();
     return;
   }
   
   _state._timer = new Timer(new Duration(milliseconds: _duration), _call);
 }
 void _touchMove(int time, Point position) {
   if (_state != null && Points.norm(position - _state.position) > _movementLimit)
     _stop();
 }
 void _touchEnd() => _stop();
 
 void _call() {
   final HoldGestureState state = _state;
   _stop();
   if (_action != null && state != null) {
     state._time = new DateTime.now().millisecondsSinceEpoch;
     _action(state);
   }
 }
 void _stop() {
   if (_state != null) {
     if (_state._timer != null) {
       _state._timer.cancel();
       _state._timer = null;
     }
     _state = null;
   }
 }
}

Extends

Gesture > HoldGesture

Constructors

factory HoldGesture(Element owner, HoldGestureAction action, {HoldGestureStart start, int duration: 1000, num movementLimit: 3}) #

Constructor.

  • start is the callback before starting monitoring the touch-and-hold gesture. If it returns false, the monitoring will be cancelled.

  • action is the callback when the touch-and-hold gesture is executed.
  • duration is the duration that a user has to hold before calling the action. Default: 1000 (unit: milliseconds)

  • movementLimit is the allowed movement to consider if a user is holding a touch. Default: 3 (unit: pixels)

factory HoldGesture(Element owner, HoldGestureAction action,
{HoldGestureStart start, int duration: 1000, num movementLimit: 3}) {
 return browser.touch ?
   new _TouchHoldGesture(owner, action, start, duration, movementLimit):
   new _MouseHoldGesture(owner, action, start, duration, movementLimit);
}

Properties

final Element owner #

The element that owns this handler.

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() {
 _stop();
}