@maccesar/titools 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS-TEMPLATE.md +173 -0
- package/README.md +867 -0
- package/agents/ti-researcher.md +108 -0
- package/bin/titools.js +53 -0
- package/lib/commands/agents.js +126 -0
- package/lib/commands/install.js +188 -0
- package/lib/commands/uninstall.js +215 -0
- package/lib/commands/update.js +159 -0
- package/lib/config.js +119 -0
- package/lib/downloader.js +153 -0
- package/lib/installer.js +253 -0
- package/lib/platform.js +108 -0
- package/lib/symlink.js +142 -0
- package/lib/utils.js +270 -0
- package/package.json +67 -0
- package/skills/alloy-expert/SKILL.md +247 -0
- package/skills/alloy-expert/assets/ControllerAutoCleanup.js +182 -0
- package/skills/alloy-expert/references/alloy-structure.md +381 -0
- package/skills/alloy-expert/references/anti-patterns.md +133 -0
- package/skills/alloy-expert/references/code-conventions.md +469 -0
- package/skills/alloy-expert/references/contracts.md +280 -0
- package/skills/alloy-expert/references/controller-patterns.md +520 -0
- package/skills/alloy-expert/references/error-handling.md +484 -0
- package/skills/alloy-expert/references/examples.md +735 -0
- package/skills/alloy-expert/references/migration-patterns.md +298 -0
- package/skills/alloy-expert/references/patterns.md +448 -0
- package/skills/alloy-expert/references/performance-patterns.md +855 -0
- package/skills/alloy-expert/references/security-patterns.md +847 -0
- package/skills/alloy-expert/references/state-management.md +779 -0
- package/skills/alloy-expert/references/testing.md +872 -0
- package/skills/alloy-guides/SKILL.md +214 -0
- package/skills/alloy-guides/references/CLI_TASKS.md +243 -0
- package/skills/alloy-guides/references/CONCEPTS.md +191 -0
- package/skills/alloy-guides/references/CONTROLLERS.md +298 -0
- package/skills/alloy-guides/references/MODELS.md +1028 -0
- package/skills/alloy-guides/references/PURGETSS.md +56 -0
- package/skills/alloy-guides/references/VIEWS_DYNAMIC.md +242 -0
- package/skills/alloy-guides/references/VIEWS_STYLES.md +388 -0
- package/skills/alloy-guides/references/VIEWS_WITHOUT_CONTROLLERS.md +109 -0
- package/skills/alloy-guides/references/VIEWS_XML.md +558 -0
- package/skills/alloy-guides/references/WIDGETS.md +176 -0
- package/skills/alloy-howtos/SKILL.md +203 -0
- package/skills/alloy-howtos/references/best_practices.md +138 -0
- package/skills/alloy-howtos/references/cli_reference.md +253 -0
- package/skills/alloy-howtos/references/config_files.md +87 -0
- package/skills/alloy-howtos/references/custom_tags.md +147 -0
- package/skills/alloy-howtos/references/debugging_troubleshooting.md +101 -0
- package/skills/alloy-howtos/references/samples.md +167 -0
- package/skills/purgetss/SKILL.md +442 -0
- package/skills/purgetss/assets/purgetss.config.cjs +17 -0
- package/skills/purgetss/references/EXAMPLES.md +247 -0
- package/skills/purgetss/references/animation-system.md +1294 -0
- package/skills/purgetss/references/apply-directive.md +375 -0
- package/skills/purgetss/references/arbitrary-values.md +612 -0
- package/skills/purgetss/references/class-index.md +1350 -0
- package/skills/purgetss/references/cli-commands.md +948 -0
- package/skills/purgetss/references/configurable-properties.md +654 -0
- package/skills/purgetss/references/custom-rules.md +161 -0
- package/skills/purgetss/references/customization-deep-dive.md +722 -0
- package/skills/purgetss/references/dynamic-component-creation.md +489 -0
- package/skills/purgetss/references/grid-layout.md +455 -0
- package/skills/purgetss/references/icon-fonts.md +609 -0
- package/skills/purgetss/references/installation-setup.md +366 -0
- package/skills/purgetss/references/opacity-modifier.md +291 -0
- package/skills/purgetss/references/platform-modifiers.md +479 -0
- package/skills/purgetss/references/smart-mappings.md +42 -0
- package/skills/purgetss/references/titanium-resets.md +359 -0
- package/skills/purgetss/references/ui-ux-design.md +1526 -0
- package/skills/ti-guides/SKILL.md +94 -0
- package/skills/ti-guides/references/advanced-data-and-images.md +19 -0
- package/skills/ti-guides/references/alloy-cli-advanced.md +84 -0
- package/skills/ti-guides/references/alloy-data-mastery.md +29 -0
- package/skills/ti-guides/references/alloy-widgets-and-themes.md +19 -0
- package/skills/ti-guides/references/android-manifest.md +97 -0
- package/skills/ti-guides/references/app-distribution.md +258 -0
- package/skills/ti-guides/references/application-frameworks.md +377 -0
- package/skills/ti-guides/references/cli-reference.md +402 -0
- package/skills/ti-guides/references/coding-best-practices.md +102 -0
- package/skills/ti-guides/references/commonjs-advanced.md +134 -0
- package/skills/ti-guides/references/hello-world.md +100 -0
- package/skills/ti-guides/references/hyperloop-native-access.md +62 -0
- package/skills/ti-guides/references/javascript-primer.md +411 -0
- package/skills/ti-guides/references/reserved-words.md +36 -0
- package/skills/ti-guides/references/resources.md +183 -0
- package/skills/ti-guides/references/style-and-conventions.md +48 -0
- package/skills/ti-guides/references/tiapp-config.md +609 -0
- package/skills/ti-howtos/SKILL.md +174 -0
- package/skills/ti-howtos/references/android-platform-deep-dives.md +658 -0
- package/skills/ti-howtos/references/automation-fastlane-appium.md +95 -0
- package/skills/ti-howtos/references/buffer-codec-streams.md +140 -0
- package/skills/ti-howtos/references/cross-platform-development.md +348 -0
- package/skills/ti-howtos/references/debugging-profiling.md +543 -0
- package/skills/ti-howtos/references/extending-titanium.md +723 -0
- package/skills/ti-howtos/references/google-maps-v2.md +169 -0
- package/skills/ti-howtos/references/ios-map-kit.md +143 -0
- package/skills/ti-howtos/references/ios-platform-deep-dives.md +783 -0
- package/skills/ti-howtos/references/local-data-sources.md +301 -0
- package/skills/ti-howtos/references/location-and-maps.md +252 -0
- package/skills/ti-howtos/references/media-apis.md +210 -0
- package/skills/ti-howtos/references/notification-services.md +599 -0
- package/skills/ti-howtos/references/remote-data-sources.md +349 -0
- package/skills/ti-howtos/references/tutorials.md +502 -0
- package/skills/ti-howtos/references/using-modules.md +237 -0
- package/skills/ti-howtos/references/web-content-integration.md +307 -0
- package/skills/ti-howtos/references/webpack-build-pipeline.md +78 -0
- package/skills/ti-ui/SKILL.md +179 -0
- package/skills/ti-ui/references/accessibility-deep-dive.md +242 -0
- package/skills/ti-ui/references/animation-and-matrices.md +599 -0
- package/skills/ti-ui/references/application-structures.md +655 -0
- package/skills/ti-ui/references/custom-fonts-styling.md +579 -0
- package/skills/ti-ui/references/event-handling.md +393 -0
- package/skills/ti-ui/references/gestures.md +473 -0
- package/skills/ti-ui/references/icons-and-splash-screens.md +409 -0
- package/skills/ti-ui/references/layouts-and-positioning.md +462 -0
- package/skills/ti-ui/references/listviews-and-performance.md +619 -0
- package/skills/ti-ui/references/orientation.md +362 -0
- package/skills/ti-ui/references/platform-ui-android.md +635 -0
- package/skills/ti-ui/references/platform-ui-ios.md +469 -0
- package/skills/ti-ui/references/scrolling-views.md +252 -0
- package/skills/ti-ui/references/tableviews.md +568 -0
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
# Application Structures and Core Building Blocks
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
|
|
5
|
+
- [Application Structures and Core Building Blocks](#application-structures-and-core-building-blocks)
|
|
6
|
+
- [Table of Contents](#table-of-contents)
|
|
7
|
+
- [1. Overview](#1-overview)
|
|
8
|
+
- [2. Windows](#2-windows)
|
|
9
|
+
- [Window Concepts](#window-concepts)
|
|
10
|
+
- [Creating Windows](#creating-windows)
|
|
11
|
+
- [Window Events](#window-events)
|
|
12
|
+
- [Window Lifecycle](#window-lifecycle)
|
|
13
|
+
- [3. Views](#3-views)
|
|
14
|
+
- [View Concepts](#view-concepts)
|
|
15
|
+
- [Creating Views](#creating-views)
|
|
16
|
+
- [Common View Types](#common-view-types)
|
|
17
|
+
- [Adding Views to Windows](#adding-views-to-windows)
|
|
18
|
+
- [Removing Views](#removing-views)
|
|
19
|
+
- [4. TabGroups](#4-tabgroups)
|
|
20
|
+
- [Tab-Based Apps](#tab-based-apps)
|
|
21
|
+
- [Tab Properties](#tab-properties)
|
|
22
|
+
- [Window Titles vs Tab Titles](#window-titles-vs-tab-titles)
|
|
23
|
+
- [Tab Events](#tab-events)
|
|
24
|
+
- [Tab Recommendations](#tab-recommendations)
|
|
25
|
+
- [Tab-Based Applications](#tab-based-applications)
|
|
26
|
+
- [Navigation Bar Customization](#navigation-bar-customization)
|
|
27
|
+
- [7. Modal Windows](#7-modal-windows)
|
|
28
|
+
- [iOS Modal Windows](#ios-modal-windows)
|
|
29
|
+
- [8. Heavyweight vs Lightweight Windows](#8-heavyweight-vs-lightweight-windows)
|
|
30
|
+
- [Heavyweight Windows (Android)](#heavyweight-windows-android)
|
|
31
|
+
- [Lightweight Windows](#lightweight-windows)
|
|
32
|
+
- [9. Window Hierarchy and Stacking](#9-window-hierarchy-and-stacking)
|
|
33
|
+
- [Understanding the Stack](#understanding-the-stack)
|
|
34
|
+
- [Accessing the Stack](#accessing-the-stack)
|
|
35
|
+
- [10. Platform-Specific Navigation](#10-platform-specific-navigation)
|
|
36
|
+
- [Android Navigation Patterns](#android-navigation-patterns)
|
|
37
|
+
- [iOS Navigation Patterns](#ios-navigation-patterns)
|
|
38
|
+
- [11. Execution Contexts](#11-execution-contexts)
|
|
39
|
+
- [Lightweight Contexts](#lightweight-contexts)
|
|
40
|
+
- [12. Common Patterns](#12-common-patterns)
|
|
41
|
+
- [Drill-Down Navigation](#drill-down-navigation)
|
|
42
|
+
- [Modal Forms](#modal-forms)
|
|
43
|
+
- [Tab with Navigation](#tab-with-navigation)
|
|
44
|
+
- [13. Best Practices](#13-best-practices)
|
|
45
|
+
- [14. Platform Differences Summary](#14-platform-differences-summary)
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 1. Overview
|
|
50
|
+
|
|
51
|
+
Titanium apps are built from three core components:
|
|
52
|
+
- **Windows** - Top-level containers (like web pages)
|
|
53
|
+
- **Views** - Generic content containers (like HTML divs)
|
|
54
|
+
- **TabGroups** - Tab-based navigation containers
|
|
55
|
+
|
|
56
|
+
## 2. Windows
|
|
57
|
+
|
|
58
|
+
### Window Concepts
|
|
59
|
+
|
|
60
|
+
In web development terms:
|
|
61
|
+
- **Window** ≈ **Web page** (top-level container)
|
|
62
|
+
- **View** ≈ **div** (generic content container)
|
|
63
|
+
- Windows can run in their own execution context
|
|
64
|
+
- Windows are top-level containers that hold views
|
|
65
|
+
|
|
66
|
+
### Creating Windows
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
const win = Ti.UI.createWindow({
|
|
70
|
+
title: 'My Window',
|
|
71
|
+
backgroundColor: '#fff',
|
|
72
|
+
fullscreen: false,
|
|
73
|
+
modal: false,
|
|
74
|
+
barColor: '#000'
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
win.open();
|
|
78
|
+
```
|
|
79
|
+
...
|
|
80
|
+
### Window Events
|
|
81
|
+
|
|
82
|
+
```javascript
|
|
83
|
+
win.addEventListener('open', (e) => {
|
|
84
|
+
Ti.API.info('Window opened');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
win.addEventListener('close', (e) => {
|
|
88
|
+
Ti.API.info('Window closed');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
win.addEventListener('focus', (e) => {
|
|
92
|
+
Ti.API.info('Window focused');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
win.addEventListener('blur', (e) => {
|
|
96
|
+
Ti.API.info('Window blurred');
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Window Lifecycle
|
|
101
|
+
|
|
102
|
+
Windows exist in a stack. Opening a window pushes it onto the stack; closing pops it from the stack.
|
|
103
|
+
|
|
104
|
+
```javascript
|
|
105
|
+
const win1 = Ti.UI.createWindow({ title: 'Window 1' });
|
|
106
|
+
const win2 = Ti.UI.createWindow({ title: 'Window 2' });
|
|
107
|
+
|
|
108
|
+
win1.open();
|
|
109
|
+
win2.open(); // Pushed on top of win1
|
|
110
|
+
|
|
111
|
+
// Pressing back (Android) or calling close() returns to win1
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## 3. Views
|
|
115
|
+
|
|
116
|
+
### View Concepts
|
|
117
|
+
|
|
118
|
+
Views are style-able generic containers that:
|
|
119
|
+
- Hold other components (buttons, labels, etc.)
|
|
120
|
+
- Must be contained within a window
|
|
121
|
+
- Are analogous to HTML divs
|
|
122
|
+
|
|
123
|
+
### Creating Views
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
const view = Ti.UI.createView({
|
|
127
|
+
width: 300,
|
|
128
|
+
height: 400,
|
|
129
|
+
backgroundColor: 'blue',
|
|
130
|
+
top: 10,
|
|
131
|
+
left: 10
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
win.add(view);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Common View Types
|
|
138
|
+
|
|
139
|
+
```javascript
|
|
140
|
+
// Basic view
|
|
141
|
+
const view = Ti.UI.createView();
|
|
142
|
+
|
|
143
|
+
// Container with specific purpose
|
|
144
|
+
const containerView = Ti.UI.createView({
|
|
145
|
+
layout: 'vertical',
|
|
146
|
+
height: Ti.UI.SIZE
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// ImageView
|
|
150
|
+
const imageView = Ti.UI.createImageView({
|
|
151
|
+
image: 'photo.png',
|
|
152
|
+
width: 100,
|
|
153
|
+
height: 100
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// WebView
|
|
157
|
+
const webView = Ti.UI.createWebView({
|
|
158
|
+
url: 'https://example.com',
|
|
159
|
+
width: Ti.UI.FILL,
|
|
160
|
+
height: Ti.UI.FILL
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Adding Views to Windows
|
|
165
|
+
|
|
166
|
+
```javascript
|
|
167
|
+
// Add single view
|
|
168
|
+
win.add(view);
|
|
169
|
+
|
|
170
|
+
// Add multiple
|
|
171
|
+
win.add(view1);
|
|
172
|
+
win.add(view2);
|
|
173
|
+
|
|
174
|
+
// Nested views
|
|
175
|
+
container.add(childView);
|
|
176
|
+
win.add(container);
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Removing Views
|
|
180
|
+
|
|
181
|
+
```javascript
|
|
182
|
+
// Remove specific view
|
|
183
|
+
win.remove(view);
|
|
184
|
+
|
|
185
|
+
// Remove all children
|
|
186
|
+
win.removeAllChildren();
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## 4. TabGroups
|
|
190
|
+
|
|
191
|
+
### Tab-Based Apps
|
|
192
|
+
|
|
193
|
+
TabGroups contain multiple tabs, each containing a window. This is the most common mobile app pattern.
|
|
194
|
+
|
|
195
|
+
```javascript
|
|
196
|
+
// Create tab group
|
|
197
|
+
const tabGroup = Ti.UI.createTabGroup();
|
|
198
|
+
|
|
199
|
+
// Create windows
|
|
200
|
+
const win1 = Ti.UI.createWindow({
|
|
201
|
+
title: 'Tab 1',
|
|
202
|
+
backgroundColor: '#fff'
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const win2 = Ti.UI.createWindow({
|
|
206
|
+
title: 'Tab 2',
|
|
207
|
+
backgroundColor: '#fff'
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// Create tabs
|
|
211
|
+
const tab1 = Ti.UI.createTab({
|
|
212
|
+
icon: 'tab1icon.png',
|
|
213
|
+
title: 'Tab 1',
|
|
214
|
+
window: win1
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const tab2 = Ti.UI.createTab({
|
|
218
|
+
icon: 'tab2icon.png',
|
|
219
|
+
title: 'Tab 2',
|
|
220
|
+
window: win2
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// Add tabs to group
|
|
224
|
+
tabGroup.addTab(tab1);
|
|
225
|
+
tabGroup.addTab(tab2);
|
|
226
|
+
|
|
227
|
+
// Open tab group
|
|
228
|
+
tabGroup.open();
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Tab Properties
|
|
232
|
+
|
|
233
|
+
| Property | Description |
|
|
234
|
+
| ------------ | ---------------------- |
|
|
235
|
+
| `icon` | Tab icon (PNG path) |
|
|
236
|
+
| `title` | Tab text |
|
|
237
|
+
| `window` | Root window for tab |
|
|
238
|
+
| `badge` | Badge number |
|
|
239
|
+
| `activeIcon` | Icon when active (iOS) |
|
|
240
|
+
|
|
241
|
+
### Window Titles vs Tab Titles
|
|
242
|
+
|
|
243
|
+
```javascript
|
|
244
|
+
const tab = Ti.UI.createTab({
|
|
245
|
+
title: 'Tab Title', // Shown on tab handle
|
|
246
|
+
window: Ti.UI.createWindow({
|
|
247
|
+
title: 'Window Title' // Shown in nav bar
|
|
248
|
+
})
|
|
249
|
+
});
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Tab Events
|
|
253
|
+
|
|
254
|
+
```javascript
|
|
255
|
+
tabGroup.addEventListener('focus', (e) => {
|
|
256
|
+
Ti.API.info(`Tab focused: ${e.index}`);
|
|
257
|
+
// e.tab: the tab object
|
|
258
|
+
// e.index: tab index
|
|
259
|
+
});
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Tab Recommendations
|
|
263
|
+
|
|
264
|
+
**Limit tabs to 4 or less**:
|
|
265
|
+
- iOS: Fixed minimum width, shows "More" for overflow
|
|
266
|
+
- Android: Tabs shrink to fit (can become unusable)
|
|
267
|
+
- Both platforms: All tabs visible = better UX
|
|
268
|
+
|
|
269
|
+
**Tab expectations**:
|
|
270
|
+
- Tabs are peers (siblings), not hierarchical
|
|
271
|
+
- Each tab focuses on limited, related functionality
|
|
272
|
+
- Tabs are related within overall app purpose
|
|
273
|
+
|
|
274
|
+
### Tab-Based Applications
|
|
275
|
+
|
|
276
|
+
**Characteristics**:
|
|
277
|
+
- 2-4 tabs at bottom
|
|
278
|
+
- Each tab contains a window
|
|
279
|
+
- Easy navigation between features
|
|
280
|
+
- Most common mobile pattern
|
|
281
|
+
|
|
282
|
+
**Example apps**:
|
|
283
|
+
- Social networks (feed, profile, messages)
|
|
284
|
+
- News apps (headlines, sports, business)
|
|
285
|
+
- Utilities with distinct features
|
|
286
|
+
|
|
287
|
+
```javascript
|
|
288
|
+
// Classic tab-based app
|
|
289
|
+
const tabGroup = Ti.UI.createTabGroup();
|
|
290
|
+
|
|
291
|
+
tabGroup.addTab(Ti.UI.createTab({
|
|
292
|
+
title: 'Home',
|
|
293
|
+
icon: 'home.png',
|
|
294
|
+
window: createHomeWindow()
|
|
295
|
+
}));
|
|
296
|
+
|
|
297
|
+
tabGroup.addTab(Ti.UI.createTab({
|
|
298
|
+
title: 'Search',
|
|
299
|
+
icon: 'search.png',
|
|
300
|
+
window: createSearchWindow()
|
|
301
|
+
}));
|
|
302
|
+
|
|
303
|
+
tabGroup.addTab(Ti.UI.createTab({
|
|
304
|
+
title: 'Profile',
|
|
305
|
+
icon: 'profile.png',
|
|
306
|
+
window: createProfileWindow()
|
|
307
|
+
}));
|
|
308
|
+
|
|
309
|
+
tabGroup.open();
|
|
310
|
+
```
|
|
311
|
+
...
|
|
312
|
+
// Window-based app with NavigationWindow (iOS)
|
|
313
|
+
const navWindow = Ti.UI.createNavigationWindow({
|
|
314
|
+
window: Ti.UI.createWindow({
|
|
315
|
+
backgroundColor: '#fff',
|
|
316
|
+
title: 'Home'
|
|
317
|
+
})
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
navWindow.open();
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
## 6. NavigationWindow (iOS)
|
|
324
|
+
|
|
325
|
+
NavigationWindow provides iOS-style navigation with push/pop transitions.
|
|
326
|
+
|
|
327
|
+
```javascript
|
|
328
|
+
const navWindow = Ti.UI.createNavigationWindow({
|
|
329
|
+
window: Ti.UI.createWindow({
|
|
330
|
+
title: 'Root',
|
|
331
|
+
backgroundColor: '#fff'
|
|
332
|
+
})
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// Open detail window
|
|
336
|
+
const detailWin = Ti.UI.createWindow({
|
|
337
|
+
title: 'Detail',
|
|
338
|
+
backgroundColor: 'gray'
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
navWindow.openWindow(detailWin, { animated: true });
|
|
342
|
+
|
|
343
|
+
// Close to go back
|
|
344
|
+
detailWin.close();
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### Navigation Bar Customization
|
|
348
|
+
|
|
349
|
+
```javascript
|
|
350
|
+
const win = Ti.UI.createWindow({
|
|
351
|
+
title: 'My Window',
|
|
352
|
+
barColor: '#000', // Nav bar color
|
|
353
|
+
translucent: false // Opaque nav bar
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
// Left nav button
|
|
357
|
+
win.leftNavButton = Ti.UI.createButton({
|
|
358
|
+
title: 'Back'
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
win.leftNavButton.addEventListener('click', () => {
|
|
362
|
+
navWindow.closeWindow(win);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
// Right nav button
|
|
366
|
+
win.rightNavButton = Ti.UI.createButton({
|
|
367
|
+
title: 'Action'
|
|
368
|
+
});
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
## 7. Modal Windows
|
|
372
|
+
|
|
373
|
+
### iOS Modal Windows
|
|
374
|
+
|
|
375
|
+
```javascript
|
|
376
|
+
const modalWin = Ti.UI.createWindow({
|
|
377
|
+
title: 'Modal',
|
|
378
|
+
backgroundColor: '#fff'
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
// Modal windows fill screen, covering tab bar
|
|
382
|
+
modalWin.open({ modal: true });
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
**Modal behavior**:
|
|
386
|
+
- Fills entire screen
|
|
387
|
+
- Covers tab bar (if in tab)
|
|
388
|
+
- Must be explicitly closed
|
|
389
|
+
- No automatic back button
|
|
390
|
+
|
|
391
|
+
## 8. Heavyweight vs Lightweight Windows
|
|
392
|
+
|
|
393
|
+
### Heavyweight Windows (Android)
|
|
394
|
+
|
|
395
|
+
Android windows are "heavyweight" - they each run in their own activity/context.
|
|
396
|
+
|
|
397
|
+
```javascript
|
|
398
|
+
// Explicit heavyweight (Android)
|
|
399
|
+
const win = Ti.UI.createWindow({
|
|
400
|
+
fullscreen: false,
|
|
401
|
+
navBarHidden: false,
|
|
402
|
+
modal: false // Still heavyweight on Android
|
|
403
|
+
});
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
**Heavyweight characteristics**:
|
|
407
|
+
- Each window = separate Android Activity
|
|
408
|
+
- Own back button handling
|
|
409
|
+
- Own lifecycle
|
|
410
|
+
- More memory intensive
|
|
411
|
+
|
|
412
|
+
### Lightweight Windows
|
|
413
|
+
|
|
414
|
+
```javascript
|
|
415
|
+
// Lightweight (same context)
|
|
416
|
+
const win = Ti.UI.createWindow({
|
|
417
|
+
navBarHidden: true, // Creates lightweight on Android
|
|
418
|
+
modal: true // Can create lightweight on iOS
|
|
419
|
+
});
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
**Lightweight characteristics**:
|
|
423
|
+
- Share context with opening window
|
|
424
|
+
- No back button (typically)
|
|
425
|
+
- Less memory usage
|
|
426
|
+
- Faster creation
|
|
427
|
+
|
|
428
|
+
## 9. Window Hierarchy and Stacking
|
|
429
|
+
|
|
430
|
+
### Understanding the Stack
|
|
431
|
+
|
|
432
|
+
```javascript
|
|
433
|
+
const win1 = Ti.UI.createWindow({ title: '1' });
|
|
434
|
+
const win2 = Ti.UI.createWindow({ title: '2' });
|
|
435
|
+
const win3 = Ti.UI.createWindow({ title: '3' });
|
|
436
|
+
|
|
437
|
+
win1.open();
|
|
438
|
+
// Stack: [win1]
|
|
439
|
+
|
|
440
|
+
win2.open();
|
|
441
|
+
// Stack: [win1, win2]
|
|
442
|
+
|
|
443
|
+
win3.open();
|
|
444
|
+
// Stack: [win1, win2, win3]
|
|
445
|
+
|
|
446
|
+
win3.close();
|
|
447
|
+
// Stack: [win1, win2]
|
|
448
|
+
|
|
449
|
+
win2.close();
|
|
450
|
+
// Stack: [win1]
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
### Accessing the Stack
|
|
454
|
+
|
|
455
|
+
```javascript
|
|
456
|
+
// Get current window (some contexts)
|
|
457
|
+
const currentWin = Ti.UI.currentWindow;
|
|
458
|
+
|
|
459
|
+
// On Android, get current activity
|
|
460
|
+
const activity = Ti.Android.currentActivity;
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
## 10. Platform-Specific Navigation
|
|
464
|
+
|
|
465
|
+
### Android Navigation Patterns
|
|
466
|
+
|
|
467
|
+
**Back Button**:
|
|
468
|
+
```javascript
|
|
469
|
+
win.addEventListener('androidback', (e) => {
|
|
470
|
+
// Override default behavior
|
|
471
|
+
const dialog = Ti.UI.createAlertDialog({
|
|
472
|
+
title: 'Exit?',
|
|
473
|
+
message: 'Go back?',
|
|
474
|
+
buttonNames: ['Yes', 'No']
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
dialog.addEventListener('click', (evt) => {
|
|
478
|
+
if (evt.index === 0) {
|
|
479
|
+
win.close();
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
dialog.show();
|
|
484
|
+
});
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
**Menu Button**:
|
|
488
|
+
```javascript
|
|
489
|
+
const activity = Ti.Android.currentActivity;
|
|
490
|
+
|
|
491
|
+
activity.onCreateOptionsMenu = (e) => {
|
|
492
|
+
const menu = e.menu;
|
|
493
|
+
|
|
494
|
+
menu.add({
|
|
495
|
+
title: 'Refresh',
|
|
496
|
+
itemId: 1,
|
|
497
|
+
showAsAction: Ti.Android.SHOW_AS_ACTION_IF_ROOM
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
menu.add({
|
|
501
|
+
title: 'Settings',
|
|
502
|
+
itemId: 2
|
|
503
|
+
});
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
activity.onOptionsItemSelected = (e) => {
|
|
507
|
+
switch(e.itemId) {
|
|
508
|
+
case 1:
|
|
509
|
+
refreshData();
|
|
510
|
+
return true;
|
|
511
|
+
case 2:
|
|
512
|
+
openSettings();
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
return false;
|
|
516
|
+
};
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### iOS Navigation Patterns
|
|
520
|
+
|
|
521
|
+
**NavigationWindow** (most common):
|
|
522
|
+
```javascript
|
|
523
|
+
const navWindow = Ti.UI.createNavigationWindow({
|
|
524
|
+
window: rootWindow
|
|
525
|
+
});
|
|
526
|
+
navWindow.open();
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
**Tab Bar Controller**:
|
|
530
|
+
```javascript
|
|
531
|
+
const tabGroup = Ti.UI.createTabGroup();
|
|
532
|
+
tabGroup.open();
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
**SplitWindow** (iPad):
|
|
536
|
+
```javascript
|
|
537
|
+
const splitWin = Ti.UI.iOS.createSplitWindow({
|
|
538
|
+
masterView: masterWindow,
|
|
539
|
+
detailView: detailWindow
|
|
540
|
+
});
|
|
541
|
+
splitWin.open();
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
## 11. Execution Contexts
|
|
545
|
+
|
|
546
|
+
### Lightweight Contexts
|
|
547
|
+
|
|
548
|
+
Windows share contexts by default:
|
|
549
|
+
|
|
550
|
+
```javascript
|
|
551
|
+
const win1 = Ti.UI.createWindow();
|
|
552
|
+
const win2 = Ti.UI.createWindow();
|
|
553
|
+
|
|
554
|
+
// These share the same JavaScript context
|
|
555
|
+
const sharedVariable = 123; // Accessible in both
|
|
556
|
+
```
|
|
557
|
+
...
|
|
558
|
+
## 12. Common Patterns
|
|
559
|
+
|
|
560
|
+
### Drill-Down Navigation
|
|
561
|
+
|
|
562
|
+
```javascript
|
|
563
|
+
// Root level
|
|
564
|
+
const table = Ti.UI.createTableView({
|
|
565
|
+
data: [
|
|
566
|
+
{ title: 'Category 1', hasChild: true },
|
|
567
|
+
{ title: 'Category 2', hasChild: true }
|
|
568
|
+
]
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
table.addEventListener('click', (e) => {
|
|
572
|
+
if (e.row.hasChild) {
|
|
573
|
+
const detailTable = createDetailTable(e.row.title);
|
|
574
|
+
|
|
575
|
+
// iOS: Use NavigationWindow
|
|
576
|
+
if (Ti.Platform.osname === 'iphone') {
|
|
577
|
+
navWindow.openWindow(detailTable.window);
|
|
578
|
+
} else {
|
|
579
|
+
// Android: Open new window
|
|
580
|
+
detailTable.window.open();
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
### Modal Forms
|
|
587
|
+
|
|
588
|
+
```javascript
|
|
589
|
+
function showModalForm() {
|
|
590
|
+
const formWin = Ti.UI.createWindow({
|
|
591
|
+
title: 'Add Item',
|
|
592
|
+
backgroundColor: '#fff',
|
|
593
|
+
modal: true
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
const nameField = Ti.UI.createTextField({
|
|
597
|
+
hintText: 'Name',
|
|
598
|
+
top: 20,
|
|
599
|
+
height: 40
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
const saveButton = Ti.UI.createButton({
|
|
603
|
+
title: 'Save',
|
|
604
|
+
top: 70
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
saveButton.addEventListener('click', () => {
|
|
608
|
+
saveData(nameField.value);
|
|
609
|
+
formWin.close();
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
formWin.add(nameField);
|
|
613
|
+
formWin.add(saveButton);
|
|
614
|
+
formWin.open();
|
|
615
|
+
}
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
### Tab with Navigation
|
|
619
|
+
|
|
620
|
+
```javascript
|
|
621
|
+
const navWindow = Ti.UI.createNavigationWindow({
|
|
622
|
+
window: Ti.UI.createWindow({
|
|
623
|
+
title: 'Home',
|
|
624
|
+
backgroundColor: '#fff'
|
|
625
|
+
})
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
const tab = Ti.UI.createTab({
|
|
629
|
+
title: 'Home',
|
|
630
|
+
icon: 'home.png',
|
|
631
|
+
window: navWindow // Use navWindow, not win directly
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
tabGroup.addTab(tab);
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
## 13. Best Practices
|
|
638
|
+
|
|
639
|
+
1. **Prefer TabGroups for multi-feature apps** - Most common pattern
|
|
640
|
+
2. **Use NavigationWindow for iOS hierarchy** - Standard iOS pattern
|
|
641
|
+
3. **Limit to 4 tabs** - All tabs visible = better UX
|
|
642
|
+
4. **Handle androidback appropriately** - Confirm before destructive actions
|
|
643
|
+
5. **Use modal windows for focused tasks** - Forms, confirmations
|
|
644
|
+
6. **Consider execution contexts** - Heavyweight windows don't share variables
|
|
645
|
+
7. **Test on both platforms** - Navigation patterns differ significantly
|
|
646
|
+
|
|
647
|
+
## 14. Platform Differences Summary
|
|
648
|
+
|
|
649
|
+
| Feature | iOS | Android |
|
|
650
|
+
| ------------- | ---------------------------- | -------------------------------------- |
|
|
651
|
+
| Modal windows | Fill screen, cover tab bar | No effect (windows always full screen) |
|
|
652
|
+
| Navigation | NavigationWindow | Back button + Menu button |
|
|
653
|
+
| Tabs | Fixed width, "More" overflow | Shrink to fit |
|
|
654
|
+
| Window stack | Manual management | Back button navigation |
|
|
655
|
+
| Heavyweight | Requires fullscreen | Default behavior |
|