Skip to content

Commit

Permalink
Merge branch 'viewmanager-bubbletarget-ryanjduffy-rebased' into relea…
Browse files Browse the repository at this point in the history
…se-2.6.1-pre.1
  • Loading branch information
aarontam committed Nov 20, 2015
2 parents 21480b8 + 3ffa66a commit 0f635aa
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 75 deletions.
28 changes: 19 additions & 9 deletions src/ViewLayout/ViewLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ var
Layout = require('../Layout'),
rAF = animation.requestAnimationFrame;

// In order to handle DOM events (e.g. ontransitionend), we need to inject ViewLayout into the event
// dispatch chain. Since we can't guarantee the usual event flow would pass through this, we
// override the default behavior to call ViewLayout's event hanlder via a mixin applied to the view
// when it is first setup
var ViewLayoutSupport = {
name: 'enyo.ViewLayoutSupport',
_viewLayout: null,
bubbleUp: kind.inherit(function (sup) {
return function (name, event, sender) {
if (this._viewLayout) this._viewLayout.handleViewEvent(name, event, sender);
return sup.apply(this, arguments);
};
})
};

/**
* Order of operations:
* * `prepareTransition()`
Expand Down Expand Up @@ -80,7 +95,8 @@ module.exports = kind(
*/
setupView: function (view) {
if (view && !view.viewSetup) {
view.set('bubbleTarget', this);
view.extend(ViewLayoutSupport);
view._viewLayout = this;
view.addClass(this.viewClass);
view.viewSetup = true;
}
Expand Down Expand Up @@ -234,14 +250,8 @@ module.exports = kind(
/**
* @private
*/
dispatchBubble: function (name, event, delegate) {
handleViewEvent: function (name, event, sender) {
var handler = this.handlers && this.handlers[name];
if (handler) {
if (this[handler](delegate, event)) {
return true;
}
} else {
return this.container.dispatchBubble(name, event, delegate);
}
if (handler) this[handler](sender, event);
}
});
138 changes: 72 additions & 66 deletions src/ViewManager/ViewManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
* [dragThreshold]{@link module:enyo/ViewManager~ViewManager#dragThreshold}.
*
* @event module:enyo/ViewManager~ViewManager#dismiss
* @property {Boolean} dragging `true` for when dismissing as a result of dragging
* @public
*/

Expand Down Expand Up @@ -224,39 +225,7 @@ var ViewMgr = kind(
*/
classes: 'enyo-viewmanager',

/**
* If `true`, this ViewManager 'floats' over its parent `manager`
*
* @type {Boolean}
* @default false
* @public
*/
floating: false,

/**
* Active view
*
* @type {Control}
* @private
*/
active: null,

/**
* Indicates the logical direction of a view activation. May be used by ViewLayouts to inform the
* direction of their animation
*
* @type {Number}
* @default 0
* @private
*/
direction: 0,

/**
* @private
*/
activeChanged: function (was, is) {
if (was) this.emitViewEvent('deactivate', was);
},
// PUBLIC PROPERTIES

/**
* Determines if and how the default view is activated. The default view is either the first
Expand All @@ -274,15 +243,6 @@ var ViewMgr = kind(
*/
activateDefault: 'auto',

/**
* `true` when this ViewManager has been dismissed
*
* @type {Boolean}
* @default false
* @private
*/
dismissed: false,

/**
* Determines if the view can be dismissed by dragging. The ViewManager can be programmatically
* dismissed via dismiss() regardless of the value of this property. If the ViewManager is the
Expand All @@ -307,15 +267,6 @@ var ViewMgr = kind(
*/
draggable: true,

/**
* `true` when a drag gesture is in process
*
* @type {Boolean}
* @default false
* @private
*/
dragging: false,

/**
* Percent a new view must be dragged into the viewport to be activated on drag release
*
Expand All @@ -326,20 +277,13 @@ var ViewMgr = kind(
dragThreshold: 25,

/**
* When `draggable`, this constrains the drag to this direction.
* If `true`, this ViewManager 'floats' over its parent `manager`
*
* @type {String}
* @default horizontal
* @type {Boolean}
* @default false
* @public
*/
orientation: 'horizontal',

/**
* During a drag, contains a reference to the becoming-active view
*
* @private
*/
dragView: null,
floating: false,

/**
* If created within another ViewManager, `manager` will maintain a reference to that
Expand All @@ -352,6 +296,23 @@ var ViewMgr = kind(
*/
manager: null,

/**
* @private
*/
managerChanged: function (was, is) {
if (was) this.off('*', was.managerEvent);
if (is) this.on('*', is.managerEvent);
},

/**
* When `draggable`, this constrains the drag to this direction.
*
* @type {String}
* @default horizontal
* @public
*/
orientation: 'horizontal',

/**
* The number of views managed by this ViewManager. This member is observable but should be
* considered read-only.
Expand All @@ -363,14 +324,58 @@ var ViewMgr = kind(
*/
viewCount: 0,

// PRIVATE PROPERTIES

/**
* Active view
*
* @type {Control}
* @private
*/
managerChanged: function (was, is) {
if (was) this.off('*', was.managerEvent);
if (is) this.on('*', is.managerEvent);
active: null,

/**
* @private
*/
activeChanged: function (was, is) {
if (was) this.emitViewEvent('deactivate', was);
},

/**
* Indicates the logical direction of a view activation. May be used by ViewLayouts to inform the
* direction of their animation
*
* @type {Number}
* @default 0
* @private
*/
direction: 0,

/**
* `true` when this ViewManager has been dismissed
*
* @type {Boolean}
* @default false
* @private
*/
dismissed: false,

/**
* `true` when a drag gesture is in process
*
* @type {Boolean}
* @default false
* @private
*/
dragging: false,

/**
* During a drag, contains a reference to the becoming-active view
*
* @private
*/
dragView: null,

/**
* @private
*/
Expand Down Expand Up @@ -724,7 +729,7 @@ var ViewMgr = kind(
this.direction = -1;
this.set('active', null);
this.set('dismissed', true);
this.emit('dismiss');
this.emit('dismiss', {dragging: false});
this.stack = [];
}
},
Expand Down Expand Up @@ -951,6 +956,7 @@ var ViewMgr = kind(
this.dragView = this.next();
} else if (this.floating) {
this.dragView = this.back();
if (!this.dragView) this.emit('dismiss', {dragging: true});
} else {
this.dragView = this.previous();
}
Expand Down

0 comments on commit 0f635aa

Please sign in to comment.