Skip to content

Commit

Permalink
added "path" like option - so it now supports both directions and two…
Browse files Browse the repository at this point in the history
… menu windows
  • Loading branch information
Marcel Pociot authored and Marcel Pociot committed Dec 30, 2011
1 parent 79237f4 commit 797b6b1
Showing 1 changed file with 64 additions and 15 deletions.
79 changes: 64 additions & 15 deletions Resources/app.js
@@ -1,19 +1,34 @@
// ALPHABYTES

// Facebook like menu window
var menu = Ti.UI.createWindow({
var leftMenu = Ti.UI.createWindow({
backgroundColor: 'red',
top: 0,
left: 0,
width: 250,
width: 150,
zIndex: 1
});
var data = [{title:"Row 1"},{title:"Row 2"},{title:"Row 3"},{title:"Row 4"}];
var tableView = Ti.UI.createTableView({ data: data });
leftMenu.add(tableView);
leftMenu.open();

// Facebook like menu window
var rightMenu = Ti.UI.createWindow({
backgroundColor: 'red',
top: 0,
right: 0,
width: 150,
zIndex: 1
});
var data = [{title:"Row 1"},{title:"Row 2"},{title:"Row 3"},{title:"Row 4"}];
var tableView = Ti.UI.createTableView({ data: data });
menu.add(tableView);
menu.open();
rightMenu.add(tableView);
rightMenu.open();

// animations
var animateLeft = Ti.UI.createAnimation({
left: 250,
left: 150,
curve: Ti.UI.iOS.ANIMATION_CURVE_EASE_OUT,
duration: 500
});
Expand All @@ -22,6 +37,13 @@ var animateRight = Ti.UI.createAnimation({
curve: Ti.UI.iOS.ANIMATION_CURVE_EASE_OUT,
duration: 500
});
var animateNegativeLeft = Ti.UI.createAnimation({
left: -150,
curve: Ti.UI.iOS.ANIMATION_CURVE_EASE_OUT,
duration: 500
});


var win = Titanium.UI.createWindow({
left: 0,
zIndex: 10
Expand All @@ -44,35 +66,52 @@ var button = Ti.UI.createButton({
height: 30,
top: 10
});
var button2 = Ti.UI.createButton({
title: 'm',
right: 10,
width: 30,
height: 30,
top: 10
});
var touchStartX = 0;
var touchStarted = false;
win1.addEventListener('touchstart',function(e){
touchStartX = parseInt(e.x,10);
});
win1.addEventListener('touchend',function(e){
touchStarted = false;
if( win.left >= 140 ){
win.animate(animateLeft);
isToggled = true;
if( win.left < 0 ){
if( win.left <= -140 ){
win.animate(animateNegativeLeft);
isToggled = true;
} else {
win.animate(animateRight);
isToggled = false;
}
} else {
win.animate(animateRight);
isToggled = false;
if( win.left >= 140 ){
win.animate(animateLeft);
isToggled = true;
} else {
win.animate(animateRight);
isToggled = false;
}
}
});
win1.addEventListener('touchmove',function(e){
var x = parseInt(e.globalPoint.x, 10);
var newLeft = x - touchStartX;
if( newLeft >= 0 ){
if( touchStarted ){
win.left = newLeft;
}
if( touchStarted ){
if( newLeft <= 150 && newLeft >= -150)
win.left = newLeft;
}
// Minimum movement is 30
if( newLeft > 30 ){
if( newLeft > 30 || newLeft < -30 ){
touchStarted = true;
}
});
nav.add(button);
nav.add(button2);
win.add(nav);
win.open();

Expand All @@ -86,4 +125,14 @@ button.addEventListener('click',function(e){
win.animate(animateRight);
isToggled = false;
}
});

button2.addEventListener('click',function(e){
if( !isToggled ){
win.animate(animateNegativeLeft);
isToggled = true;
} else {
win.animate(animateRight);
isToggled = false;
}
});

0 comments on commit 797b6b1

Please sign in to comment.