Skip to content

Instantly share code, notes, and snippets.

@rblalock
Last active November 18, 2017 19:16
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rblalock/5001234 to your computer and use it in GitHub Desktop.
Save rblalock/5001234 to your computer and use it in GitHub Desktop.
TableViewRow swipe sample
/**
* Handle Item Swipe
* @param {Object} _event
*/
$.handleItemSwipe = function(_event) {
var row = _event.source;
var id = row.id;
var controls = Alloy.createController("rowControls");
row.add(controls.wrapper);
};
var rows = [];
_data.forEach(function(_item) {
var row = Ti.UI.createTableViewRow({
height: 85,
backgroundColor: "#fff",
id: _item.id,
text: _item.title,
selectionStyle: Ti.UI.iPhone.TableViewCellSelectionStyle.NONE
});
var touchWrapper = Ti.UI.createView({
width: "100%",
height: "100%"
});
var wrapper = Ti.UI.createView({
layout: "vertical",
id: _item.id,
text: _item.title,
touchEnabled: false
});
var title = Ti.UI.createLabel({
text: _item.title,
color: "#222",
left: 10,
top: 10,
font: { fontWeight: "bold", fontSize: 16 },
touchEnabled: false
});
var managedTitle = Ti.UI.createLabel({
text: "This app is managed by " + _item.subtitle,
color: "#444",
left: 10,
top: 3,
font: { fontSize: 12 },
touchEnabled: false
});
var border = Ti.UI.createView({
backgroundColor: "#d4e6f5",
height: 1,
bottom: 0,
touchEnabled: false
});
wrapper.add(title);
wrapper.add(managedTitle);
row.add(wrapper);
row.add(border);
row.add(touchWrapper);
rows.push( row );
});
$.list.setData( rows );
// Custom swipe detection for table rows (since technically the "swipe"
// event doesn't apply to individual rows but rather the table. This way we
// don't have to assign a swipe event for each row. One event to manage
// them all is more performant.
var TOUCH_X = 0;
$.list.addEventListener("touchstart", function(e) {
TOUCH_X = e.x;
});
$.list.addEventListener("touchend", function(e) {
if(e.x > (TOUCH_X + 44)) {
$.handleItemSwipe(e);
} else if(e.x < (TOUCH_X - 44)) {
$.handleItemSwipe(e);
}
TOUCH_X = e.x;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment