-
-
Save pec1985/fed5005b2ab33b6da445 to your computer and use it in GitHub Desktop.
Runtime error in ti:window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a mini replica of the issue that client is seeing in their application | |
// I cannot reproduce it. | |
// This is the smallest I could create a sample test case to replicate the problem | |
// this is NOT important | |
var Utils = {}; | |
(function(){ | |
Utils.CurrentActivty = null; | |
Utils.isAndroidInBackground = false; | |
})(); | |
// Most the UI will have to go through this namespace | |
var UI = {}; | |
(function(){ | |
UI.Alert = function(params, callback){ | |
params = params || {}; | |
callback = callback || function(){}; | |
var dialog = Ti.UI.createAlertDialog(params); | |
dialog.addEventListener('click', callback); | |
return dialog; | |
}; | |
UI.Image = function(a){ | |
a = a || {}; | |
return Ti.UI.createImageView(a); | |
} | |
UI.Label = function(a){ | |
a = a || {}; | |
return Ti.UI.createLabel(a); | |
} | |
UI.Button = function(a){ | |
a = a || {}; | |
a.left = 20; | |
a.right = 20; | |
a.height = Ti.UI.SIZE; | |
return Ti.UI.createButton(a); | |
}; | |
UI.Win = function(a){ | |
a = a || {}; | |
a.fullscreen = a.fullscreen || false; | |
var win = Ti.UI.createWindow(a); | |
var opened = false; | |
function openEvent(){ | |
win.removeEventListener('open', openEvent); | |
if(opened === false){ | |
opened = true; | |
if(win.isActivity){ | |
var activity = win.activity; | |
Utils.CurrentActivty = win; | |
Utils.isAndroidInBackground = false; | |
if(activity.addEventListener){ | |
activity.addEventListener('resume', function(){ | |
Utils.isAndroidInBackground = false; | |
}); | |
activity.addEventListener('pause', function(){ | |
Utils.isAndroidInBackground = true; | |
}); | |
} | |
} | |
} | |
}; | |
function closeEvent(){ | |
win.removeEventListener('close', closeEvent); | |
} | |
win.addEventListener('close', closeEvent); | |
win.addEventListener('open', openEvent); | |
return win; | |
}; | |
UI.LightWin = function(a){ | |
a = a || {}; | |
return Ti.UI.createWindow(a); | |
} | |
})(); | |
// All the windows in this app are inside of this namespace | |
var W = {}; | |
W.Settings = function(){ | |
var self = {}; | |
var win = UI.LightWin({ | |
backgroundColor:'#ccc' | |
}); | |
var btn1 = UI.Button({ | |
title:'Open a window', | |
top:100 | |
}); | |
var btn2 = UI.Button({ | |
title:'Fire Event', | |
bottom:100 | |
}); | |
win.add(btn1); | |
win.add(btn2); | |
btn1.addEventListener('click', function(){ | |
W.OtherWin().open(); | |
}); | |
btn2.addEventListener('click', function(){ | |
Ti.App.fireEvent('close_all'); | |
}); | |
self.open = function(){ | |
win.open(); | |
} | |
self.close = function(){ | |
win.close(); | |
setTimeout(function(){ | |
W.Login().open(); | |
},400); | |
} | |
win.addEventListener('close', function(){ | |
Ti.API.info('close settings window'); | |
Ti.App.removeEventListener('close_all', self.close); | |
}); | |
Ti.App.addEventListener('close_all', self.close); | |
return self; | |
} | |
// Login window, it is *lightweight* | |
W.Login = function(){ | |
var self = {}; | |
var win = UI.LightWin({ | |
backgroundColor:'white' | |
}); | |
var loginButton = UI.Button({title:'Login', top:100}); | |
win.add(loginButton); | |
loginButton.addEventListener('click', function(){ | |
self.close(); | |
var w = W.Settings(); | |
w.open(); | |
}); | |
self.win = win; | |
self.open = function(){ | |
win.open(); | |
} | |
self.close = function(){ | |
win.close(); | |
} | |
return self; | |
}; | |
W.OtherWin = function(){ | |
var self = {}; | |
var win = UI.Win({backgroundColor:'white'}); | |
var btn = UI.Button({ | |
title:'fireEvent' | |
}); | |
win.add(btn); | |
self.open = function(){ | |
win.open(); | |
} | |
self.close = function(){ | |
win.close(); | |
} | |
btn.addEventListener('click', function(){ | |
Ti.App.fireEvent('close_all'); | |
}) | |
Ti.App.addEventListener('close_all', self.close); | |
win.addEventListener('close', function(){ | |
Ti.API.info('close other win'); | |
Ti.App.removeEventListener('close_all', self.close); | |
}); | |
return self; | |
} | |
// this is main window, gloabaly available | |
var BaseWindow = UI.Win({ | |
navBarHidden:true, | |
windowSoftInputMode:Ti.UI.Android.SOFT_INPUT_ADJUST_RESIZE, | |
exitOnClose:true, | |
backgroundColor:'white' | |
}); | |
BaseWindow.orientationModes = [Ti.UI.PORTRAIT]; | |
BaseWindow.open(); | |
// just to mimic the start of the app: | |
// BaseWindow is a heavy weight window. | |
// it opens W.Login, which is a lightweight window | |
(function(){ | |
var loading = Ti.UI.createProgressBar({ | |
value: 0, | |
min: 0, | |
max: 1000, | |
left:20,right:20, | |
height: Ti.UI.SIZE, | |
color: '#888', | |
message: 'Loading' | |
}); | |
BaseWindow.add(loading); | |
setTimeout(function(){ | |
var val = 0; | |
// mimic server download stuff | |
while(val < 1000){ | |
loading.value = val; | |
val++; | |
} | |
W.Login().open(); | |
BaseWindow.remove(loading); | |
loading = null; | |
},300); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment