Skip to content

Commit

Permalink
Adding a cancelled flag to DraggableEvent to indicate if a drag e…
Browse files Browse the repository at this point in the history
…nded

because of a cancelling operation like `esc` key, etc.
  • Loading branch information
marcojakob committed Jul 22, 2014
1 parent 88a0367 commit 1504d0b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Changelog

## Version 0.1.2 (?)
## Version 0.1.2 (2014-07-22)

* Correcting small bug that occurred when setSelectionRange() was called on
an element that does not support it.
* Fix Pointer Event bug: Too many event listeners in move, end, cancel.
* Fix for Bug #1 - Not working in Windows 8.1 IE11
* Adding a `cancelled` flag to `DraggableEvent` to indicate if a drag ended
because of a cancelling operation like `esc` key, etc.


## Version 0.1.1 (2014-07-21)
Expand Down
21 changes: 13 additions & 8 deletions lib/src/draggable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,10 @@ class Draggable {
* be a [TouchEvent], a [MouseEvent], a [KeyboardEvent], or a [Event] (when
* focus is lost).
*
* The [target] is the actual target receiving the event.
*
* The [position] is the page position of the event.
* Set [cancelled] to true to indicate that this drag ended through a
* cancel oparation like hitting the `esc` key.
*/
void _handleDragEnd(Event event) {
void _handleDragEnd(Event event, {cancelled: false}) {
// Only handle drag end if the user actually did drag and not just clicked.
if (_currentDrag.started) {

Expand All @@ -253,7 +252,8 @@ class Draggable {

// Fire dragEnd event.
if (_onDragEnd != null) {
_onDragEnd.add(new DraggableEvent._(event, _currentDrag));
_onDragEnd.add(new DraggableEvent._(event, _currentDrag,
cancelled: cancelled));
}

// Prevent TouchEvent from emulating a click after touchEnd event.
Expand Down Expand Up @@ -438,14 +438,19 @@ class DraggableEvent {
/// position).
final Point position;

/// Indicates if this [DraggableEvent] was [cancelled]. This is currently
/// only used for [onDragEnd] events to indicate a drag end through a
/// cancelling oparation like `esc` key or windows loosing focus.
final bool cancelled;

/**
* Private constructor for [DraggableEvent].
*/
DraggableEvent._(this.originalEvent, _DragInfo dragInfo)
DraggableEvent._(this.originalEvent, _DragInfo dragInfo, {this.cancelled: false})
: draggableElement = dragInfo.element,
avatarHandler = dragInfo.avatarHandler,
startPosition = dragInfo.startPosition,
position = dragInfo.position,
avatarHandler = dragInfo.avatarHandler;
position = dragInfo.position;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/src/draggable_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ abstract class _EventManager {
* Handles all cancel events (touchCancel and pointerCancel).
*/
void handleCancel(Event event) {
// Drag end.
drg._handleDragEnd(event);
// Drag end with the cancelled flag.
drg._handleDragEnd(event, cancelled: true);
}

/**
Expand Down

0 comments on commit 1504d0b

Please sign in to comment.