Permalink
Browse files

drastic change to move TabGroup

  • Loading branch information...
1 parent 05da4d2 commit 091e5a1df3d3bc0809764b28ac52ac2498209a39 @ofl committed Apr 26, 2012
View
@@ -1,5 +1,5 @@
(function() {
var win;
- win = new (require('ui/Window'))();
+ win = new (require('ui/TabGroup'))();
win.open();
})();
View
@@ -1,58 +0,0 @@
-var $$, Detail, dir, mix, mod, trace;
-dir = 'ui';
-mod = "" + dir + "/Detail";
-$$ = (require("" + dir + "/style")).style;
-trace = function(mes) {
- return Ti.API.info("" + mod + ":" + mes);
-};
-mix = (require('helpers/util')).mix;
-Detail = (function() {
- function Detail(tab) {
- var refresh, tableView, view, _bubble;
- trace("start constructor");
- view = Ti.UI.createView({
- left: 30,
- width: 290,
- height: 460,
- isShow: false
- });
- tableView = Ti.UI.createTableView(mix($$.tableView, {
- backgroundColor: '#ffc'
- }));
- view.add(tableView);
- refresh = function() {
- var data, item, row, rows, _i, _len;
- data = [
- {
- title: 'gagaga'
- }, {
- title: 'gogogog'
- }
- ];
- rows = [];
- for (_i = 0, _len = data.length; _i < _len; _i++) {
- item = data[_i];
- row = Ti.UI.createTableViewRow({
- title: item.title,
- indentionLevel: 3
- });
- rows.push(row);
- }
- tableView.setData(rows);
- };
- _bubble = function(type, options, propagation, source) {
- view.fireEvent('bubble', {
- btype: type,
- boptions: options || {},
- bpropagation: propagation || true,
- bsource: source || mod
- });
- };
- view.refresh = refresh;
- trace("end constructor");
- return view;
- }
- return Detail;
-})();
-trace("end load");
-module.exports = Detail;
@@ -1,58 +0,0 @@
-var $$, Window, dir, mix, mod, trace;
-dir = 'ui';
-mod = "" + dir + "/FloatWindow";
-$$ = (require("" + dir + "/style")).style;
-trace = function(mes) {
- return Ti.API.info("" + mod + ":" + mes);
-};
-mix = (require('helpers/util')).mix;
-Window = (function() {
- function Window() {
- var leftBtn, refresh, rightBtn, window, _bubble, _catchBubble;
- trace("start constructor");
- window = Ti.UI.createWindow(mix($$.window, {
- left: 0,
- width: 320,
- height: 460,
- backgroundColor: '#990000'
- }));
- leftBtn = Ti.UI.createButton(mix($$.menuBtn, {
- left: 10,
- title: 'Left'
- }));
- window.add(leftBtn);
- rightBtn = Ti.UI.createButton(mix($$.menuBtn, {
- right: 10,
- title: 'Right'
- }));
- window.add(rightBtn);
- refresh = function(color) {
- if (color === 'red') {
- window.backgroundColor = '#990000';
- } else {
- window.backgroundColor = '#000099';
- }
- };
- _bubble = function(type, options, propagation, source) {
- window.fireEvent('bubble', {
- btype: type,
- boptions: options || {},
- bpropagation: propagation || true,
- bsource: source || mod
- });
- };
- _catchBubble = function(e) {};
- leftBtn.addEventListener('click', function() {
- _bubble('showMenu');
- });
- rightBtn.addEventListener('click', function() {
- _bubble('showDetail');
- });
- window.refresh = refresh;
- trace("end constructor");
- return window;
- }
- return Window;
-})();
-trace("end load");
-module.exports = Window;
View
@@ -0,0 +1,146 @@
+var $$, TabGroup, dir, mix, mod, trace;
+dir = 'ui';
+mod = "" + dir + "/TabGroup";
+$$ = (require("" + dir + "/style")).style;
+trace = function(mes) {
+ return Ti.API.info("" + mod + ":" + mes);
+};
+mix = (require('helpers/util')).mix;
+TabGroup = (function() {
+ function TabGroup() {
+ var currentTabIndex, i_, isOpendMenu, isOpened, menuWindow, nextTabIndex, offset, tab, tabGroup, tabs, touchStartX, touchStarted, win, windowDir, _catchBubble, _i, _len, _len2, _switchTab, _toggleMenu, _touchHandler;
+ trace("start constructor");
+ windowDir = ['red', 'blue'];
+ tabs = [];
+ currentTabIndex = 0;
+ nextTabIndex = 0;
+ offset = 260;
+ isOpened = false;
+ touchStartX = 0;
+ touchStarted = false;
+ isOpendMenu = false;
+ menuWindow = new (require("" + dir + "/menu/Window"))();
+ menuWindow.open();
+ for (i_ = 0, _len = windowDir.length; i_ < _len; i_++) {
+ win = windowDir[i_];
+ tabs.push(Ti.UI.createTab($$.tab));
+ tabs[i_].window = new (require("" + dir + "/" + win + "/Window"))(tabs[i_]);
+ tabs[i_].maskView = Ti.UI.createView({
+ width: Ti.UI.FILL,
+ height: Ti.UI.FILL,
+ zIndex: 100,
+ visible: false
+ });
+ tabs[i_].window.add(tabs[i_].maskView);
+ if (i_ === 0) {
+ tabs[0].window.refresh();
+ }
+ }
+ tabGroup = Ti.UI.createTabGroup(mix($$.tabGroup, {
+ tabs: tabs,
+ zIndex: 10
+ }));
+ _catchBubble = function(e) {
+ if (e.btype === 'didSelectView') {
+ nextTabIndex = e.boptions.index;
+ if (nextTabIndex === currentTabIndex) {
+ _toggleMenu('left', true);
+ } else {
+ _switchTab(nextTabIndex);
+ }
+ tabs[currentTabIndex].maskView.visible = false;
+ } else if (e.btype === 'showMenu') {
+ _toggleMenu('left', isOpendMenu);
+ tabs[currentTabIndex].maskView.visible = true;
+ }
+ };
+ _toggleMenu = function(direction, isOpened) {
+ var left;
+ if (direction === 'left') {
+ left = !isOpened && offset || 0;
+ } else {
+ left = !isOpened && -offset || 0;
+ }
+ tabGroup.animate(mix($$.animation, {
+ left: left
+ }), function() {
+ isOpendMenu = !isOpened;
+ });
+ };
+ _switchTab = function(nextTabIndex) {
+ var animation;
+ animation = {
+ left: 320,
+ curve: Ti.UI.iOS.ANIMATION_CURVE_EASE_OUT,
+ duration: 300
+ };
+ tabGroup.animate(animation, function() {
+ tabs[nextTabIndex].window.refresh();
+ tabGroup.setActiveTab(nextTabIndex);
+ tabGroup.animate(mix($$.animation, {
+ left: 0
+ }), function() {
+ currentTabIndex = nextTabIndex;
+ isOpendMenu = false;
+ });
+ });
+ };
+ _touchHandler = function(e) {
+ var newLeft, x;
+ switch (e.type) {
+ case 'touchstart':
+ touchStartX = parseInt(e.x, 10);
+ break;
+ case 'touchmove':
+ if (typeof e.globalPoint !== 'undefined') {
+ x = parseInt(e.globalPoint.x, 10);
+ newLeft = x - touchStartX;
+ if (touchStarted) {
+ if (newLeft <= offset) {
+ tabGroup.left = newLeft;
+ }
+ }
+ if (newLeft > 30) {
+ touchStarted = true;
+ }
+ }
+ break;
+ case 'touchend':
+ touchStarted = false;
+ if (tabGroup.left >= 140) {
+ tabGroup.animate(mix($$.animation, {
+ left: offset
+ }), function() {
+ tabs[currentTabIndex].maskView.visible = true;
+ return isOpendMenu = true;
+ });
+ } else {
+ tabGroup.animate(mix($$.animation, {
+ left: 0
+ }), function() {
+ isOpendMenu = false;
+ return tabs[currentTabIndex].maskView.visible = false;
+ });
+ }
+ }
+ };
+ menuWindow.addEventListener('bubble', _catchBubble);
+ for (_i = 0, _len2 = tabs.length; _i < _len2; _i++) {
+ tab = tabs[_i];
+ win = tab.window;
+ win.addEventListener('bubble', _catchBubble);
+ win.addEventListener('touchstart', _touchHandler);
+ win.addEventListener('touchmove', _touchHandler);
+ win.addEventListener('touchend', _touchHandler);
+ }
+ tabGroup.addEventListener('open', function() {
+ menuWindow.refresh();
+ menuWindow.visible = true;
+ });
+ trace("end constructor");
+ return tabGroup;
+ }
+ return TabGroup;
+})();
+trace("end load");
+module.exports = TabGroup;
Oops, something went wrong.

0 comments on commit 091e5a1

Please sign in to comment.