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