@maccesar/titools 5.2.5 → 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 +58 -97
- package/agents/ti-pro.md +4 -2
- package/commands/ti-audit.md +7 -5
- package/docs/examples.md +24 -13
- 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-synthengine/SKILL.md +62 -111
- package/skills/ti-synthengine/assets/example/README.md +50 -59
- package/skills/ti-synthengine/assets/example/app.js +67 -65
- package/skills/ti-synthengine/assets/example/lib/sequenceOwner.js +39 -40
- package/skills/ti-synthengine/assets/example/lib/soundPreset.js +34 -0
- package/skills/ti-synthengine/assets/index.d.ts +122 -2
- package/skills/ti-synthengine/references/advanced-examples.md +4 -4
- package/skills/ti-synthengine/references/api.md +40 -18
- package/skills/ti-synthengine/references/audio-engine.md +15 -57
- package/skills/ti-synthengine/references/examples.md +63 -6
- package/skills/ti-synthengine/references/guide.md +61 -57
- package/skills/ti-synthengine/references/instruments-and-effects.md +15 -15
- package/skills/ti-synthengine/references/native-variation.md +53 -14
- package/skills/ti-synthengine/references/recipes-interaction.md +25 -20
- package/skills/ti-synthengine/references/recipes.md +19 -16
- package/skills/ti-synthengine/references/recommendations.md +12 -12
- package/skills/ti-synthengine/references/sound-api.md +197 -0
- package/skills/ti-synthengine/references/sound-design.md +7 -7
- package/skills/ti-synthengine/references/source-notes.md +62 -172
- package/skills/ti-synthengine/references/troubleshooting.md +17 -19
- package/skills/ti-synthengine/references/upgrade-2.0.0.md +40 -0
- 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-synthengine/references/android-sim80-correction-evidence.zip +0 -0
- package/skills/ti-synthengine/references/android-sim80-correction.json +0 -162
- package/skills/ti-synthengine/references/audio-pipeline-validation.md +0 -19
- package/skills/ti-synthengine/references/bypass-physical-recheck-evidence.zip +0 -0
- package/skills/ti-synthengine/references/frontier-android-evidence.zip +0 -0
- package/skills/ti-synthengine/references/frontier-ipad-evidence.zip +0 -0
- package/skills/ti-synthengine/references/frontier-physical-validation.json +0 -1918
- package/skills/ti-synthengine/references/native-tone-repetition-validation.md +0 -59
- package/skills/ti-synthengine/references/native-variation-proposal.md +0 -182
- package/skills/ti-synthengine/references/native-variation-validation.md +0 -63
- package/skills/ti-synthengine/references/performance-review-evidence.zip +0 -0
- package/skills/ti-synthengine/references/performance-review.json +0 -1146
- package/skills/ti-synthengine/references/physical-validation.json +0 -1457
- package/skills/ti-synthengine/references/source-snapshot.json +0 -542
- package/skills/ti-synthengine/references/stats-performance.json +0 -2992
- package/skills/ti-synthengine/references/stats-performance.md +0 -82
- package/skills/ti-synthengine/references/studio-validation.json +0 -6202
- package/skills/ti-synthengine/references/unified-bypass-performance.json +0 -22425
- package/skills/ti-synthengine/references/unified-validation.json +0 -314
- 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,599 +1,83 @@
|
|
|
1
|
-
# Alloy XML
|
|
1
|
+
# Alloy XML views
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
## Contents
|
|
3
|
+
Wrap every view in `<Alloy>`, which is a compiler element rather than a native View. Element names normally select `Ti.UI.create*`: `<Label>` creates a Label, `<ListView>` creates a ListView, and nesting adds children to their container.
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
- [Collection Element](#collection-element)
|
|
8
|
-
- [Model Element](#model-element)
|
|
9
|
-
- [Module Attribute](#module-attribute)
|
|
10
|
-
- [Module Element](#module-element)
|
|
11
|
-
- [Require Element](#require-element)
|
|
12
|
-
- [Namespace](#namespace)
|
|
13
|
-
- [Conditional Code](#conditional-code)
|
|
14
|
-
- [Property Mapping](#property-mapping)
|
|
15
|
-
- [Event Handling](#event-handling)
|
|
16
|
-
- [Data Binding](#data-binding)
|
|
17
|
-
- [Non-Standard Syntax](#non-standard-syntax)
|
|
18
|
-
|
|
19
|
-
<!-- TOC-END -->
|
|
20
|
-
|
|
21
|
-
## Introduction
|
|
22
|
-
|
|
23
|
-
In Alloy, the XML markup abstracts the Titanium SDK UI components, so you do not need to code the creation and setup of these components using JavaScript and the Titanium SDK API. All view files must be placed in the `app/views` folder of your project with the `.xml` file extension.
|
|
24
|
-
|
|
25
|
-
The following code is an example of a view file:
|
|
26
|
-
|
|
27
|
-
**app/views/index.xml**
|
|
5
|
+
## A complete screen
|
|
28
6
|
|
|
29
7
|
```xml
|
|
8
|
+
<!-- app/views/index.xml -->
|
|
30
9
|
<Alloy>
|
|
31
10
|
<Window class="container">
|
|
32
|
-
<Label id="
|
|
33
|
-
|
|
34
|
-
</Alloy>
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
The `Alloy` tag is the root element for the XML markup and is required in all views. The Window element defines an instance of the `Ti.UI.Window` object and within that window instance is the `Label` element which defines an instance of a `Ti.UI.Label` object. Almost all of the Alloy XML tags are the class names of the Titanium UI components without the preceding namespace.
|
|
38
|
-
|
|
39
|
-
Within a controller, a UI component can be referenced if its ID attribute is defined. For instance, the Label component in the above example has its ID defined as `label` and can be referenced in the controller using `$.label`.
|
|
40
|
-
|
|
41
|
-
If the top-level UI component does not have an ID defined, it can be referenced using the name of the view-controller prefixed with a dollar sign and period (`$.`). For instance, the Window element in the above example can be referenced in the controller using `$.index`.
|
|
42
|
-
|
|
43
|
-
The following table lists the attributes for the UI components:
|
|
44
|
-
|
|
45
|
-
| Attribute | Description |
|
|
46
|
-
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
47
|
-
| `id` | Identifies UI elements in the controller (prefixed with `$.`) and style sheet (prefixed with `#`). IDs should be unique per view but are not global, so multiple views can have components with the same ID. |
|
|
48
|
-
| `class` | Applies additional styles (prefixed with `.` in the TSS file). Overwrites the element style but not the id style. |
|
|
49
|
-
| `autoStyle` | Enables the autostyle feature for dynamic styling. |
|
|
50
|
-
| `formFactor` | Acts as a compiler directive for size-specific view components (`handheld` or `tablet`). |
|
|
51
|
-
| `if` | Use a custom query to apply additional styles to the element. |
|
|
52
|
-
| `module` | Requires in a CommonJS module. |
|
|
53
|
-
| `ns` | Overrides the default `Titanium.UI` namespace. |
|
|
54
|
-
| `platform` | Switches the namespace based on the platform. |
|
|
55
|
-
| `<properties>` | Assigns values to UI object properties. |
|
|
56
|
-
| `<events>` | Assigns callbacks to UI object events. |
|
|
57
|
-
|
|
58
|
-
The following table lists the special XML elements besides the Titanium UI components:
|
|
59
|
-
|
|
60
|
-
| Element | Description |
|
|
61
|
-
| ------------ | ----------------------------------------------------------- |
|
|
62
|
-
| `Alloy` | Root element for all view XML files. Required in all views. |
|
|
63
|
-
| `Collection` | Creates a singleton or instance of a collection. |
|
|
64
|
-
| `Model` | Creates a singleton or instance of a model. |
|
|
65
|
-
| `Module` | Imports a module view inside this view. |
|
|
66
|
-
| `Require` | Imports a widget or includes another view inside this view. |
|
|
67
|
-
| `Widget` | Imports a widget inside this view. |
|
|
68
|
-
|
|
69
|
-
`index.xml` is a special case that only accepts the following view components as direct children of the Alloy tag:
|
|
70
|
-
|
|
71
|
-
* `Ti.UI.Window` or `<Window>`
|
|
72
|
-
* `Ti.UI.TabGroup` or `<TabGroup>`
|
|
73
|
-
* `Ti.UI.NavigationWindow` or `<NavigationWindow>`
|
|
74
|
-
* `Ti.UI.iOS.SplitWindow` or `<SplitWindow>`
|
|
75
|
-
|
|
76
|
-
Other views do not have any format restrictions.
|
|
77
|
-
|
|
78
|
-
> **⚠️ WARNING**
|
|
79
|
-
> With the release of CLI 7.1.0, you can use platform as a prefix in the XML. For example: `<Label ios:text="Hello iOS!" android:text="Hello Android!" />`
|
|
80
|
-
|
|
81
|
-
## Collection Element
|
|
82
|
-
|
|
83
|
-
The `Collection` XML element creates a singleton or instance of a collection. The `Collection` tag needs to be a child of the `Alloy` parent tag.
|
|
84
|
-
|
|
85
|
-
### Creating a Singleton
|
|
86
|
-
|
|
87
|
-
```xml
|
|
88
|
-
<Alloy>
|
|
89
|
-
<Collection src="book" />
|
|
90
|
-
<Window>
|
|
91
|
-
<TableView id="table" />
|
|
92
|
-
</Window>
|
|
93
|
-
</Alloy>
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
```javascript
|
|
97
|
-
const library = Alloy.Collections.book;
|
|
98
|
-
library.fetch();
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### Creating an Instance
|
|
102
|
-
|
|
103
|
-
```xml
|
|
104
|
-
<Alloy>
|
|
105
|
-
<Collection id="localLibrary" src="book" instance="true"/>
|
|
106
|
-
<Window>
|
|
107
|
-
<TableView id="table" />
|
|
108
|
-
</Window>
|
|
109
|
-
</Alloy>
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
```javascript
|
|
113
|
-
const library = $.localLibrary;
|
|
114
|
-
library.fetch();
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
## Model Element
|
|
118
|
-
|
|
119
|
-
The `Model` XML element creates a singleton or instance of a model. The `Model` tag needs to be a child of the `Alloy` parent tag.
|
|
120
|
-
|
|
121
|
-
### Creating a Singleton
|
|
122
|
-
|
|
123
|
-
```xml
|
|
124
|
-
<Alloy>
|
|
125
|
-
<Model src="book" />
|
|
126
|
-
<Window>
|
|
127
|
-
<TableView id="table" />
|
|
128
|
-
</Window>
|
|
129
|
-
</Alloy>
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
```javascript
|
|
133
|
-
const drama = Alloy.Models.book;
|
|
134
|
-
drama.set('title', 'Hamlet');
|
|
135
|
-
drama.set('author', 'William Shakespeare');
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### Creating an Instance
|
|
139
|
-
|
|
140
|
-
```xml
|
|
141
|
-
<Alloy>
|
|
142
|
-
<Model id="myBook" src="book" instance="true"/>
|
|
143
|
-
<Window>
|
|
144
|
-
<TableView id="table" />
|
|
145
|
-
</Window>
|
|
146
|
-
</Alloy>
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
```javascript
|
|
150
|
-
const drama = $.myBook;
|
|
151
|
-
drama.set('title', 'Hamlet');
|
|
152
|
-
drama.set('author', 'William Shakespeare');
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
## Module Attribute
|
|
156
|
-
|
|
157
|
-
You can require a CommonJS module in an Alloy view using the `module` attribute of an XML element.
|
|
158
|
-
|
|
159
|
-
**app/lib/foo.js**
|
|
160
|
-
|
|
161
|
-
```javascript
|
|
162
|
-
exports.createFoo = args => {
|
|
163
|
-
const viewArgs = {
|
|
164
|
-
backgroundColor: args.color || 'white',
|
|
165
|
-
width: 100,
|
|
166
|
-
height: 100
|
|
167
|
-
};
|
|
168
|
-
const view = Ti.UI.createView(viewArgs);
|
|
169
|
-
const labelArgs = {
|
|
170
|
-
color: args.textColor || 'black',
|
|
171
|
-
text: args.text || 'Foobar'
|
|
172
|
-
};
|
|
173
|
-
const label = Ti.UI.createLabel(labelArgs);
|
|
174
|
-
view.add(label);
|
|
175
|
-
return view;
|
|
176
|
-
};
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
**app/views/index.xml**
|
|
180
|
-
|
|
181
|
-
```xml
|
|
182
|
-
<Alloy>
|
|
183
|
-
<Window backgroundColor="white">
|
|
184
|
-
<Foo module="foo" color="blue" textColor="orange" text="Hello, World!"/>
|
|
11
|
+
<Label id="greeting">Hello</Label>
|
|
12
|
+
<Button id="go" onClick="doGo">Continue</Button>
|
|
185
13
|
</Window>
|
|
186
14
|
</Alloy>
|
|
187
15
|
```
|
|
188
16
|
|
|
189
|
-
## Module Element
|
|
190
|
-
|
|
191
|
-
You can also include a view from a native module using the `Module` XML element. The `method` attribute specifies which creation method to call. If omitted, defaults to `createView`.
|
|
192
|
-
|
|
193
|
-
**app/views/index.xml**
|
|
194
|
-
|
|
195
|
-
```xml
|
|
196
|
-
<Alloy>
|
|
197
|
-
<Window>
|
|
198
|
-
<Module id="paint" module="ti.paint" method="createPaintView" eraseMode="false" strokeWidth="1.0" strokeColor="red" strokeAlpha="100" />
|
|
199
|
-
<Button onClick="eraseMe" bottom="0">Erase</Button>
|
|
200
|
-
</Window>
|
|
201
|
-
</Alloy>
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
**app/controllers/index.js**
|
|
205
|
-
|
|
206
17
|
```javascript
|
|
207
|
-
|
|
208
|
-
|
|
18
|
+
// app/controllers/index.js
|
|
19
|
+
function doGo() {
|
|
20
|
+
$.greeting.text = 'Going';
|
|
209
21
|
}
|
|
210
|
-
|
|
211
|
-
$.index.open();
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
## Require Element
|
|
215
|
-
|
|
216
|
-
The `Require` XML element has two uses: including external views and importing widgets into the current view.
|
|
217
|
-
|
|
218
|
-
### Including Views
|
|
219
|
-
|
|
220
|
-
Views may be included in other views using the `Require` element. Specify the `type` attribute as `view` and the `src` attribute should be the view file minus the `.xml` extension. If you omit the `type` attribute, Alloy assumes it is implicitly set to `view`.
|
|
221
|
-
|
|
222
|
-
**app/views/index.xml**
|
|
223
|
-
|
|
224
|
-
```xml
|
|
225
|
-
<Alloy>
|
|
226
|
-
<TabGroup>
|
|
227
|
-
<Tab id="leftTab">
|
|
228
|
-
<Require type="view" src="rss" id="rssTab"/>
|
|
229
|
-
</Tab>
|
|
230
|
-
<Tab id="rightTab">
|
|
231
|
-
<Require type="view" src="about" id="aboutTab"/>
|
|
232
|
-
</Tab>
|
|
233
|
-
</TabGroup>
|
|
234
|
-
</Alloy>
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
To use UI objects from the included views:
|
|
238
|
-
|
|
239
|
-
```javascript
|
|
240
|
-
const aboutView = $.aboutTab.getView('aboutView');
|
|
241
|
-
aboutView.url = 'http://www.google.com';
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
### Importing Widgets
|
|
245
|
-
|
|
246
|
-
Within a view in the regular Alloy project space (`app/views`), use the `<Widget>` tag to import the widget into the application. For Alloy 1.4.x and prior, you need to assign the `src` attribute to the widget's name (the `id` in `widget.json`).
|
|
247
|
-
|
|
248
|
-
**To import a widget:**
|
|
249
|
-
|
|
250
|
-
1. Copy the widget to the `app/widgets` folder. The widget must be contained within its own folder.
|
|
251
|
-
2. Add the `<Widget>` tag in the XML and specify its `src` attribute as the folder name of the widget.
|
|
252
|
-
3. Update the `dependencies` object in the `config.json` file by adding a key/value pair with the name of the widget as the key and the version number as the value.
|
|
253
|
-
|
|
254
|
-
You can optionally add the `id` and `name` attributes to the `Widget` element:
|
|
255
|
-
- The `id` attribute allows you to reference the widget in the controller code.
|
|
256
|
-
- The `name` attribute allows you to import a specific view-controller in the widget rather than the default one (`widget.xml`/`widget.js`). Specify the name of the view-controller minus the extension.
|
|
257
|
-
|
|
258
|
-
For example, to import the `mywidget` widget, copy it to `app/widgets`:
|
|
259
|
-
|
|
260
|
-
```
|
|
261
|
-
app
|
|
262
|
-
├── config.json
|
|
263
|
-
├── controllers
|
|
264
|
-
│ └── index.js
|
|
265
|
-
├── views
|
|
266
|
-
│ └── index.xml
|
|
267
|
-
└── widgets
|
|
268
|
-
└── mywidget
|
|
269
|
-
├── controllers
|
|
270
|
-
│ ├── foo.js
|
|
271
|
-
│ └── widget.js
|
|
272
|
-
├── views
|
|
273
|
-
│ ├── foo.xml
|
|
274
|
-
│ └── widget.xml
|
|
275
|
-
└── widget.json
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
**app/views/index.xml**
|
|
279
|
-
|
|
280
|
-
```xml
|
|
281
|
-
<Alloy>
|
|
282
|
-
<Window>
|
|
283
|
-
<Widget src="mywidget" id="foo" name="foo" />
|
|
284
|
-
</Window>
|
|
285
|
-
</Alloy>
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
**app/controllers/index.js**
|
|
289
|
-
|
|
290
|
-
```javascript
|
|
291
22
|
$.index.open();
|
|
292
|
-
$.foo.myMethod();
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
Update the `dependencies` object in `config.json`:
|
|
296
|
-
|
|
297
|
-
```
|
|
298
|
-
...
|
|
299
|
-
"dependencies": {
|
|
300
|
-
"mywidget":"1.0"
|
|
301
|
-
}
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
### Passing Arguments
|
|
305
|
-
|
|
306
|
-
You can add any custom attributes to the markup to initialize a widget or controller.
|
|
307
|
-
|
|
308
|
-
**apps/views/index.xml**
|
|
309
|
-
|
|
310
|
-
```xml
|
|
311
|
-
<Require id="foobar" src="foo" customTitle="Hello" customImage="hello.png"/>
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
This is equivalent to:
|
|
315
|
-
|
|
316
|
-
**apps/controllers/index.js**
|
|
317
|
-
|
|
318
|
-
```javascript
|
|
319
|
-
const foobar = Alloy.createController('foo', {
|
|
320
|
-
id: 'foobar',
|
|
321
|
-
customTitle: 'Hello',
|
|
322
|
-
customImage: 'images/hello.png'
|
|
323
|
-
});
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
In the required view's controller:
|
|
327
|
-
|
|
328
|
-
**apps/controllers/foo.js**
|
|
329
|
-
|
|
330
|
-
```javascript
|
|
331
|
-
const title = $.args.customTitle || 'Foobar';
|
|
332
|
-
const image = $.args.customImage || 'default.png';
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
### Binding Events
|
|
336
|
-
|
|
337
|
-
To bind a callback to an event in a required view using the `on` attribute:
|
|
338
|
-
|
|
339
|
-
Parent View:
|
|
340
|
-
|
|
341
|
-
```xml
|
|
342
|
-
<Require id="fooButton" src="button" onClick="doClick" />
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
Button View:
|
|
346
|
-
|
|
347
|
-
```xml
|
|
348
|
-
<Alloy>
|
|
349
|
-
<Button id="button">Click Me!</Button>
|
|
350
|
-
</Alloy>
|
|
351
|
-
```
|
|
352
|
-
|
|
353
|
-
In the controller of the required view:
|
|
354
|
-
|
|
355
|
-
```
|
|
356
|
-
$.button.addEventListener('click', e => {
|
|
357
|
-
$.trigger('click', e);
|
|
358
|
-
});
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
### Adding Children Views
|
|
362
|
-
|
|
363
|
-
If your Require element is a parent view, you can add children elements to it. These children elements are passed to the parent controller as an array called `$.args.children`.
|
|
364
|
-
|
|
365
|
-
**app/views/info.xml**
|
|
366
|
-
|
|
367
|
-
```xml
|
|
368
|
-
<Alloy>
|
|
369
|
-
<View backgroundColor="yellow" borderWidth="0.5" borderColor="brown"/>
|
|
370
|
-
</Alloy>
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
**controllers/info.js**
|
|
374
|
-
|
|
375
|
-
```javascript
|
|
376
|
-
_.each($.args.children || [], child => {
|
|
377
|
-
$.info.add(child);
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
$.info.height = Ti.UI.SIZE;
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
**app/views/index.xml**
|
|
384
|
-
|
|
385
|
-
```xml
|
|
386
|
-
<Alloy>
|
|
387
|
-
<Window class="container">
|
|
388
|
-
<Require src="info">
|
|
389
|
-
<Label>I am an info box.</Label>
|
|
390
|
-
</Require>
|
|
391
|
-
</Window>
|
|
392
|
-
</Alloy>
|
|
393
23
|
```
|
|
394
24
|
|
|
395
|
-
|
|
25
|
+
`id="greeting"` exposes `$.greeting` and selects `#greeting` in TSS. `class="row highlighted"` applies two TSS classes. An element without an ID is created and added, but has no public handle. The root defaults to the filename (`$.index`) only if it has no explicit ID.
|
|
396
26
|
|
|
397
|
-
|
|
27
|
+
Text content sets the element's text property: Label `text`, Button `title`. Attribute values become numbers or booleans when recognized, so `top="20"` is numeric and `visible="false"` is false. Put structured dictionaries in TSS or JavaScript.
|
|
398
28
|
|
|
399
|
-
|
|
400
|
-
<BlurView ns="Ti.UI.iOS" id="blurView"/>
|
|
401
|
-
```
|
|
29
|
+
## Namespaces and native modules
|
|
402
30
|
|
|
403
|
-
For
|
|
31
|
+
For an object outside `Ti.UI`, specify its namespace:
|
|
404
32
|
|
|
405
33
|
```xml
|
|
406
|
-
<
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
Also, use the alias `Ti` for `Titanium` when specifying namespaces.
|
|
410
|
-
|
|
411
|
-
Many of the Titanium view proxies not part of the `Titanium.UI` namespace do not require that the `ns` attribute be explicitly set. The following elements are implicitly mapped to a namespace:
|
|
412
|
-
|
|
413
|
-
| Element | Namespace |
|
|
414
|
-
| ---------------- | ------------- |
|
|
415
|
-
| Menu | Ti.Android |
|
|
416
|
-
| MenuItem | Ti.Android |
|
|
417
|
-
| Annotation | Ti.Map |
|
|
418
|
-
| VideoPlayer | Ti.Media |
|
|
419
|
-
| MusicPlayer | Ti.Media |
|
|
420
|
-
| SearchView | Ti.UI.Android |
|
|
421
|
-
| AdView | Ti.UI.iOS |
|
|
422
|
-
| CoverFlowView | Ti.UI.iOS |
|
|
423
|
-
| NavigationWindow | Ti.UI |
|
|
424
|
-
| TabbedBar | Ti.UI.iOS |
|
|
425
|
-
| DocumentViewer | Ti.UI.iOS |
|
|
426
|
-
| Popover | Ti.UI.iPad |
|
|
427
|
-
| SplitWindow | Ti.UI.iOS |
|
|
428
|
-
| StatusBar | Ti.UI.iOS |
|
|
429
|
-
|
|
430
|
-
## Conditional Code
|
|
431
|
-
|
|
432
|
-
Add the `platform`, `formFactor` and `if` attributes to apply XML elements based on conditionals.
|
|
433
|
-
|
|
434
|
-
* `platform`: Assign it a platform, such as, `android` or `ios`. Comma separate values to OR them. Prepend with `!` to negate.
|
|
435
|
-
* `formFactor`: Assign it a device size–either `handheld` or `tablet`.
|
|
436
|
-
* `if`: Assign it to a conditional statement in the `Alloy.Globals` namespace or `$.args` namespace.
|
|
437
|
-
|
|
438
|
-
```xml
|
|
439
|
-
<Alloy>
|
|
440
|
-
<Window>
|
|
441
|
-
<Module id="mapview" module="ti.map" method="createView">
|
|
442
|
-
<Annotation title="Cupertino" platform='ios' formFactor='tablet' latitude='37.3231' longitude='-122.0311'/>
|
|
443
|
-
<Annotation title="Redwood City" platform='ios' formFactor='handheld' latitude='37.4853' longitude='-122.2353'/>
|
|
444
|
-
<Annotation title="Mountain View" platform='android' latitude='37.3861' longitude='-122.0828'/>
|
|
445
|
-
<Annotation title="Palo Alto" platform='android,ios,mobileweb' latitude='37.4419' longitude='-122.1419'/>
|
|
446
|
-
<Annotation title="San Francisco" platform='mobileweb' latitude='37.7750' longitude='-122.4183'/>
|
|
447
|
-
</Module>
|
|
448
|
-
</Window>
|
|
449
|
-
</Alloy>
|
|
34
|
+
<Module id="player" ns="Ti.Media" method="createVideoPlayer" />
|
|
450
35
|
```
|
|
451
36
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
Each Titanium UI object property is defined as an attribute in the XML and TSS file if it accepts a string, boolean, number or Titanium SDK constant. Setting properties in the XML overrides the settings in the TSS file. Node text can also be used to define the `Label` text and `Button` title properties.
|
|
37
|
+
For a native module, install its compatible binary and declare it in `tiapp.xml` before using it; see `ti-guides` for module setup. Alloy requires the named module:
|
|
455
38
|
|
|
456
39
|
```xml
|
|
457
|
-
<
|
|
40
|
+
<Module id="map" module="ti.map" method="createView" />
|
|
458
41
|
```
|
|
459
42
|
|
|
460
|
-
|
|
43
|
+
## Conditional elements
|
|
461
44
|
|
|
462
|
-
|
|
45
|
+
`platform="android"` or `platform="ios"` excludes other-platform elements from the compiled build. Lists such as `platform="ios,android"` are OR conditions; `platform="!ios"` negates the selection.
|
|
463
46
|
|
|
464
47
|
```xml
|
|
465
48
|
<Alloy>
|
|
466
49
|
<Window>
|
|
467
|
-
<
|
|
468
|
-
|
|
469
|
-
</
|
|
50
|
+
<Button platform="android" title="Android only" />
|
|
51
|
+
<Button platform="ios" title="iOS only" />
|
|
52
|
+
<Label formFactor="tablet">Wide layout</Label>
|
|
470
53
|
</Window>
|
|
471
54
|
</Alloy>
|
|
472
55
|
```
|
|
473
56
|
|
|
474
|
-
|
|
57
|
+
`formFactor` accepts `tablet` or `handheld`. Unlike the platform branch, released Alloy evaluates this using `Alloy.isTablet` at runtime; a universal app can contain both device layouts.
|
|
475
58
|
|
|
476
|
-
|
|
477
|
-
| --------------------------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------- | --------------------------------------- |
|
|
478
|
-
| Ti.Android.MenuItem / `<MenuItem>` | actionView | `<ActionView>` | Alloy 1.6.0 |
|
|
479
|
-
| Ti.UI.iPad.Popover / `<PopOver>` | contentView | `<ContentView>` | Alloy 1.4.0 |
|
|
480
|
-
| Ti.UI.Label / `<Label>` | attributedString | `<AttributedString>` | Alloy 1.7.6 |
|
|
481
|
-
| Ti.UI.ListSection / `<ListSection>` | footerView, headerView | `<FooterView>`, `<HeaderView>` | Alloy 1.3.0 |
|
|
482
|
-
| Ti.UI.ListView / `<ListView>` | footerView, headerView, pullView, searchView | `<FooterView>`, `<HeaderView>`, `<PullView>`, `<SearchBar>` or `<SearchView platform="android">` | Alloy 1.3.0 |
|
|
483
|
-
| Ti.UI.OptionDialog / `<OptionDialog>` | androidView | `<AndroidView>` or `<View>` | Alloy 1.5.0 |
|
|
484
|
-
| Ti.UI.TableView / `<TableView>` | footerView, headerPullView, headerView, search | `<FooterView>`, `<HeaderPullView>`, `<HeaderView>`, `<Search>` | Alloy 1.1.0 |
|
|
485
|
-
| Ti.UI.TableViewSection / `<TableViewSection>` | headerView | `<HeaderView>` | - |
|
|
486
|
-
| Ti.UI.TextArea / `<TextArea>` | attributedString, keyboardToolbar | `<AttributedString>`, `<KeyboardToolbar>` | Alloy 1.7.6, 1.5.0 |
|
|
487
|
-
| Ti.UI.TextField / `<TextField>` | attributedHintText, attributedString, keyboardToolbar, leftButton, rightButton | `<AttributeHintText>`, `<AttributedString>`, `<KeyboardToolbar>`, `<LeftButton>`, `<RightButton>` | Alloy 1.7.6, 1.7.6, 1.3.0, 1.3.0, 1.3.0 |
|
|
488
|
-
| Ti.UI.Window / `<Window>` | leftNavButton, rightNavButton, titleControl, toolbar | `<LeftNavButton>`, `<RightNavButton>`, `<TitleControl>`, `<WindowToolbar>` | Alloy 1.6.0 |
|
|
489
|
-
|
|
490
|
-
### Android ActionBar
|
|
491
|
-
|
|
492
|
-
You can set ActionBar properties in the `ActionBar` element.
|
|
493
|
-
|
|
494
|
-
**app/views/index.xml**
|
|
495
|
-
|
|
496
|
-
```xml
|
|
497
|
-
<Alloy>
|
|
498
|
-
<Window title="My App">
|
|
499
|
-
<ActionBar id="actionbar" platform="android" title="Home Screen" onHomeIconItemSelected="showInfo" />
|
|
500
|
-
<Menu>
|
|
501
|
-
<MenuItem id="editItem" title="Edit" onClick="editInfo" />
|
|
502
|
-
<MenuItem id="viewItem" title="View" onClick="viewInfo" />
|
|
503
|
-
</Menu>
|
|
504
|
-
<Label id="label">Use the ActionBar to Perform an Action.</Label>
|
|
505
|
-
</Window>
|
|
506
|
-
</Alloy>
|
|
507
|
-
```
|
|
508
|
-
|
|
509
|
-
**app/styles/index.tss**
|
|
510
|
-
|
|
511
|
-
```javascript
|
|
512
|
-
"#editItem": {
|
|
513
|
-
showAsAction: Ti.Android.SHOW_AS_ACTION_ALWAYS
|
|
514
|
-
},
|
|
515
|
-
"#actionbar": {
|
|
516
|
-
displayHomeAsUp: true,
|
|
517
|
-
icon: "/images/actionicon.png"
|
|
518
|
-
}
|
|
519
|
-
```
|
|
520
|
-
|
|
521
|
-
### iOS Navigation Button Shorthand
|
|
522
|
-
|
|
523
|
-
When specifying either the `LeftNavButton` or `RightNavButton` element, you can define the `Button` attributes directly. This also works with iPad `Popover` objects. Note that you cannot use node text to define the button title with this shorthand.
|
|
524
|
-
|
|
525
|
-
**app/views/index.xml**
|
|
526
|
-
|
|
527
|
-
```xml
|
|
528
|
-
<Alloy>
|
|
529
|
-
<NavigationWindow>
|
|
530
|
-
<Window>
|
|
531
|
-
<LeftNavButton title="Back" onClick="goBack" />
|
|
532
|
-
<Label>I am iOS!</Label>
|
|
533
|
-
</Window>
|
|
534
|
-
</NavigationWindow>
|
|
535
|
-
</Alloy>
|
|
536
|
-
```
|
|
537
|
-
|
|
538
|
-
### iOS SystemButton Shorthand
|
|
539
|
-
|
|
540
|
-
When specifying the `systemButton` attribute, you do not need to use the `Ti.UI.iOS.SystemButton` namespace.
|
|
541
|
-
|
|
542
|
-
```xml
|
|
543
|
-
<Button systemButton="CAMERA"/>
|
|
544
|
-
<!-- Instead of -->
|
|
545
|
-
<Button systemButton="Titanium.UI.iOS.SystemButton.CAMERA"/>
|
|
546
|
-
```
|
|
547
|
-
|
|
548
|
-
### TextField Keyboard Shorthands
|
|
549
|
-
|
|
550
|
-
When specifying the `keyboardType` or `returnKeyType` for a TextField, you can use shorthand constants without the full namespace:
|
|
551
|
-
|
|
552
|
-
```xml
|
|
553
|
-
<TextField id="txt" keyboardType="DECIMAL_PAD" returnKeyType="DONE"/>
|
|
554
|
-
<!-- Instead of -->
|
|
555
|
-
<TextField id="txt" keyboardType="Titanium.UI.KEYBOARD_DECIMAL_PAD" returnKeyType="Titanium.UI.RETURNKEY_DONE"/>
|
|
556
|
-
```
|
|
557
|
-
|
|
558
|
-
This also works in TSS:
|
|
559
|
-
|
|
560
|
-
```javascript
|
|
561
|
-
"#txt": {
|
|
562
|
-
keyboardType: "DECIMAL_PAD",
|
|
563
|
-
returnKeyType: "DONE"
|
|
564
|
-
}
|
|
565
|
-
```
|
|
566
|
-
|
|
567
|
-
## Event Handling
|
|
568
|
-
|
|
569
|
-
In Alloy, events may be added in the views using a special attribute. Capitalize the first character of the event name and prefix it with `on`, so the `Ti.UI.Button` object events `click`, `dblclick` and `swipe` events will become the attributes: `onClick`, `onDblclick`, and `onSwipe`, respectively.
|
|
59
|
+
## Composing screens
|
|
570
60
|
|
|
571
61
|
```xml
|
|
572
62
|
<Alloy>
|
|
573
63
|
<Window>
|
|
574
|
-
<
|
|
64
|
+
<Require src="header" id="header" />
|
|
65
|
+
<Label>Body</Label>
|
|
575
66
|
</Window>
|
|
576
67
|
</Alloy>
|
|
577
68
|
```
|
|
578
69
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
If you have a collection of model data that needs to be automatically updated to a view as it changes, you need to use data binding techniques. See [Alloy Data Binding](./MODELS.md#alloy-data-binding) for more details.
|
|
70
|
+
Provide the `header` view/controller in the app. `$.header` is its controller, so exported methods are reachable there. Its top-level native view is `$.header.getView()`. Arguments are read from `$.args` in that controller.
|
|
582
71
|
|
|
583
|
-
|
|
72
|
+
| Compiler element | Purpose |
|
|
73
|
+
| --- | --- |
|
|
74
|
+
| `Alloy` | Required root |
|
|
75
|
+
| `Require` | Embed another app controller |
|
|
76
|
+
| `Widget` | Embed a reusable widget |
|
|
77
|
+
| `Module` | Create an object from another namespace or native module |
|
|
78
|
+
| `Collection` | Declare a collection for data binding |
|
|
79
|
+
| `Model` | Declare a model for data binding |
|
|
584
80
|
|
|
585
|
-
|
|
81
|
+
Continue with [styles](./VIEWS_STYLES.md), [models](./MODELS.md) and [widgets](./WIDGETS.md).
|
|
586
82
|
|
|
587
|
-
|
|
588
|
-
* [ButtonBar](https://titaniumsdk.com/docs/sdk/Titanium.UI.ButtonBar)
|
|
589
|
-
* [CoverFlowView](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.CoverFlowView)
|
|
590
|
-
* [DashboardView](https://titaniumsdk.com/docs/sdk/Titanium.UI.DashboardView)
|
|
591
|
-
* [ListView](https://titaniumsdk.com/docs/sdk/Titanium.UI.ListView)
|
|
592
|
-
* [Map](https://titaniumsdk.com/modules/ti.map)
|
|
593
|
-
* [Menu](https://titaniumsdk.com/docs/sdk/Titanium.Android.Menu)
|
|
594
|
-
* [OptionBar](https://titaniumsdk.com/docs/sdk/Titanium.UI.OptionBar)
|
|
595
|
-
* [OptionDialog](https://titaniumsdk.com/docs/sdk/Titanium.UI.OptionDialog)
|
|
596
|
-
* [Picker](https://titaniumsdk.com/docs/sdk/Titanium.UI.Picker)
|
|
597
|
-
* [SplitWindow](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.SplitWindow)
|
|
598
|
-
* [TabbedBar](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.TabbedBar)
|
|
599
|
-
* [Toolbar](https://titaniumsdk.com/docs/sdk/Titanium.UI.Toolbar)
|
|
83
|
+
Source: [views](https://titaniumsdk.com/docs/alloy/views.md). The form-factor caveat corrects that page's compile-time wording against released Alloy 3.0.1.
|