Skip to content

Instantly share code, notes, and snippets.

@kosso
Created September 16, 2013 18:40
Show Gist options
  • Save kosso/6584687 to your computer and use it in GitHub Desktop.
Save kosso/6584687 to your computer and use it in GitHub Desktop.
test for NappDrawer containing a scrollView and a swipeable view.
var NappDrawerModule = require('dk.napp.drawer');
function createAPIExampleWindow(){
var win = Ti.UI.createWindow({
barColor:"#996633",
fullscreen:false,
translucent:false,
statusBarStyle:Ti.UI.iPhone.StatusBar.LIGHT_CONTENT,
navTintColor:'white'
});
var data = [
{title: "Nothin"},
{title: "Toggle stretch drawer"},
{title: "Close"}
];
var tableView = Ti.UI.createTableView({
top:20,
data:data
});
tableView.addEventListener("click", function(e){
Ti.API.info("isLeftWindowOpen: " + drawer.isLeftWindowOpen());
switch(e.index){
case 0:
//drawer.setShowShadow(!drawer.showShadow);
break;
case 1:
drawer.setShouldStretchDrawer(!drawer.shouldStretchDrawer);
break;
case 2:
drawer.toggleLeftWindow();
break;
}
setTimeout(function(){
Ti.API.info("isLeftWindowOpen: " + drawer.isLeftWindowOpen());
}, 500);
});
win.add(tableView);
return win;
}
function createCenterNavWindow(){
var leftBtn = Ti.UI.createButton({title:" < "});
leftBtn.addEventListener("click", function(){
drawer.toggleLeftWindow();
});
var rightBtn = Ti.UI.createButton({title:"Right"});
rightBtn.addEventListener("click", function(){
drawer.toggleRightWindow();
});
var win = Ti.UI.createWindow({
backgroundColor:'#eee',
title:"Drawer Controller",
barColor:"#336699",
statusBarStyle:Ti.UI.iPhone.StatusBar.LIGHT_CONTENT,
fullscreen:false,
translucent:false,
navTintColor:'white',
leftNavButton: leftBtn//,
//rightNavButton: rightBtn
});
/*
var bounceBtn = Ti.UI.createButton({
top:20,
width:300,
title:"Bounce Right Window"
});
bounceBtn.addEventListener("click", function(){
drawer.bounceRightWindow();
});
win.add(bounceBtn);
*/
var scroller = Ti.UI.createScrollView({
top:0,
left:0,
width:320,
backgroundColor:'#eee',
bottom:0,
showVerticalScrollIndicator:true,
contentHeight:Ti.UI.SIZE,
layout:'vertical'
});
win.add(scroller);
var closeGestureMode = 1;
var closeGestureModeBtn = Ti.UI.createButton({
title:"closeGestureMode: ALL",
width:300,
top:50
});
closeGestureModeBtn.addEventListener("click", function(e){
if(closeGestureMode == 2){
closeGestureMode = 0;
} else {
closeGestureMode++;
}
switch(closeGestureMode){
case 0:
drawer.setCloseDrawerGestureMode(NappDrawerModule.CLOSE_MODE_TAP_CENTERWINDOW);
closeGestureModeBtn.setTitle("closeGesture: Tap Center");
break;
case 1:
drawer.setCloseDrawerGestureMode(NappDrawerModule.CLOSE_MODE_ALL);
closeGestureModeBtn.setTitle("closeGesture: ALL");
break;
case 2:
drawer.setCloseDrawerGestureMode(NappDrawerModule.CLOSE_MODE_PANNING_NAVBAR);
closeGestureModeBtn.setTitle("closeGesture: NAVBAR");
break;
}
});
scroller.add(closeGestureModeBtn);
var animationMode = 0;
var animationModeBtn = Ti.UI.createButton({
title:"animation: NONE",
width:300,
top:50
});
animationModeBtn.addEventListener("click", function(e){
if(animationMode == 5){
animationMode = 0;
} else {
animationMode++;
}
switch(animationMode){
case 0:
drawer.setAnimationMode(NappDrawerModule.ANIMATION_NONE);
animationModeBtn.setTitle("animation: None");
break;
case 1:
drawer.setAnimationMode(NappDrawerModule.ANIMATION_PARALLAX_FACTOR_3);
animationModeBtn.setTitle("animation: Parallax factor 3");
break;
case 2:
drawer.setAnimationMode(NappDrawerModule.ANIMATION_PARALLAX_FACTOR_7);
animationModeBtn.setTitle("animation: Parallax factor 7");
break;
case 3:
drawer.setAnimationMode(NappDrawerModule.ANIMATION_FADE);
animationModeBtn.setTitle("animation: Fade");
break;
case 4:
drawer.setAnimationMode(NappDrawerModule.ANIMATION_SLIDE);
animationModeBtn.setTitle("animation: Slide");
break;
case 5:
drawer.setAnimationMode(NappDrawerModule.ANIMATION_SLIDE_SCALE);
animationModeBtn.setTitle("animation: Slide & Scale");
break;
}
});
scroller.add(animationModeBtn);
var slider = Ti.UI.createSlider({
top: 50,
min: 50,
max: 280,
width: 280,
value: 200
});
var label = Ti.UI.createLabel({
text: "Left Drawer Width: " + slider.value,
top: 50
});
slider.addEventListener('touchend', function(e) {
var value = Math.round(e.value);
label.setText("Left Drawer Width: " + value);
drawer.setLeftDrawerWidth(value);
});
scroller.add(label);
scroller.add(slider);
var test_swiper = Ti.UI.createView({
top:50,
height:100,
left:20,
right:20,
bubbleParent:false,
backgroundColor:'blue'
});
var label = Ti.UI.createLabel({color:'white',text:'swipe me'});
test_swiper.add(label);
test_swiper.addEventListener('swipe', function(e){
alert('swipe: '+e.direction+'!');
});
test_swiper.addEventListener('click', function(e){
alert('click');
});
scroller.add(test_swiper);
// make some scrolliness
scroller.add(Ti.UI.createView({top:50, height:200, left:20, right:20, backgroundColor:'black'}));
scroller.add(Ti.UI.createView({top:50, height:200, left:20, right:20, backgroundColor:'black'}));
scroller.add(Ti.UI.createView({top:50, height:200, left:20, right:20, backgroundColor:'black'}));
scroller.add(Ti.UI.createView({top:50, height:200, left:20, right:20, backgroundColor:'black'}));
var navWin = Ti.UI.iOS.createNavigationWindow({
window:win
});
// NAV controller
//var navController = Ti.UI.iPhone.createNavigationGroup({
// window : win
//});
return navWin;
}
var drawer = NappDrawerModule.createDrawer({
leftWindow: createAPIExampleWindow(),
centerWindow: createCenterNavWindow(),
//rightWindow: Ti.UI.createWindow({backgroundColor:"blue"}),
closeDrawerGestureMode: NappDrawerModule.CLOSE_MODE_ALL,
openDrawerGestureMode: NappDrawerModule.OPEN_MODE_ALL,
leftDrawerWidth: 200,
//rightDrawerWidth: 220
});
drawer.open();
Ti.API.info("isAnyWindowOpen: " + drawer.isAnyWindowOpen());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment