@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,109 @@
|
|
|
1
|
+
# Views without Controllers
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
|
|
5
|
+
- [Views without Controllers](#views-without-controllers)
|
|
6
|
+
- [Table of Contents](#table-of-contents)
|
|
7
|
+
- [Introduction](#introduction)
|
|
8
|
+
- [XML Markup](#xml-markup)
|
|
9
|
+
- [Controller Code](#controller-code)
|
|
10
|
+
|
|
11
|
+
## Introduction
|
|
12
|
+
|
|
13
|
+
Views can be created without controllers with an optional style sheet. These views can be used as building blocks to create a GUI. After you have defined your controller-less views, the application can either require in these views using markup or can dynamically generate these views in the controller code.
|
|
14
|
+
|
|
15
|
+
## XML Markup
|
|
16
|
+
|
|
17
|
+
In XML markup, use the `Require` tag to add controller-less views into another view. Assign the `src` attribute to the name of the view file minus the `.xml` extension and the `type` to `view`. Define the `id` attribute to access each instance of the controller-less view in the controller.
|
|
18
|
+
|
|
19
|
+
For instance, a button view could be reused repeatedly in a view-controller to construct a dialog box:
|
|
20
|
+
|
|
21
|
+
**app/views/foo.xml**
|
|
22
|
+
|
|
23
|
+
```xml
|
|
24
|
+
<Alloy>
|
|
25
|
+
<Button id='fooButton'>I am a foo button!</Button>
|
|
26
|
+
</Alloy>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
This view can be inserted into another view multiple times:
|
|
30
|
+
|
|
31
|
+
**app/views/index.xml**
|
|
32
|
+
|
|
33
|
+
```xml
|
|
34
|
+
<Alloy>
|
|
35
|
+
<Window layout="vertical">
|
|
36
|
+
<Require id="button1" src="foo" type="view"/>
|
|
37
|
+
<Require id="button2" src="foo" type="view"/>
|
|
38
|
+
<Require id="button3" src="foo" type="view"/>
|
|
39
|
+
</Window>
|
|
40
|
+
</Alloy>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Then, the controller can use `$.button1`, `$.button2` and `$.button3` to access each instance of the foo view.
|
|
44
|
+
|
|
45
|
+
## Controller Code
|
|
46
|
+
|
|
47
|
+
**Starting with Alloy 1.4.0**, you can dynamically create views in the controller code. Each component in the controller-less view needs to be assigned an `id` attribute.
|
|
48
|
+
|
|
49
|
+
**To create a view without a corresponding controller:**
|
|
50
|
+
|
|
51
|
+
1. Use the `Alloy.createController()` method to create a controller from the controller-less view.
|
|
52
|
+
2. Use the `updateViews()` method with the created controller. Pass a style dictionary with the `id` of each component as the key and attributes as values.
|
|
53
|
+
3. Use the `getView()` method to retrieve the view.
|
|
54
|
+
4. Use the `add()` method to add the view to a parent component.
|
|
55
|
+
|
|
56
|
+
::: warning ⚠️ Warning
|
|
57
|
+
Unlike other style dictionaries in Alloy, when using the `updateViews()` method, you can only apply styles using IDs. Class and view component styles do not work with this method.
|
|
58
|
+
:::
|
|
59
|
+
|
|
60
|
+
For example:
|
|
61
|
+
|
|
62
|
+
**app/views/profile.xml**
|
|
63
|
+
|
|
64
|
+
```xml
|
|
65
|
+
<Alloy>
|
|
66
|
+
<View id="container">
|
|
67
|
+
<ImageView id="picture"/>
|
|
68
|
+
<Label id="name"/>
|
|
69
|
+
</View>
|
|
70
|
+
</Alloy>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**app/controllers/index.js**
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
const profile = Alloy.createController('profile');
|
|
77
|
+
profile.updateViews({
|
|
78
|
+
"#container" : {
|
|
79
|
+
layout : "vertical"
|
|
80
|
+
},
|
|
81
|
+
"#picture" : {
|
|
82
|
+
image : "/appicon.png"
|
|
83
|
+
},
|
|
84
|
+
"#name" : {
|
|
85
|
+
text : "Mr. Man"
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
$.index.add(profile.getView());
|
|
89
|
+
|
|
90
|
+
$.index.open();
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Prior to Alloy 1.4.0**, to dynamically generate a view:
|
|
94
|
+
|
|
95
|
+
1. Create a new instance of the controller using `Alloy.createController()`.
|
|
96
|
+
2. Modify the properties directly.
|
|
97
|
+
3. Use `getView()` to retrieve the view.
|
|
98
|
+
4. Use `add()` to add it to a parent.
|
|
99
|
+
|
|
100
|
+
**app/controllers/index.js** (Alloy < 1.4.0)
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
const profile = Alloy.createController('profile');
|
|
104
|
+
profile.container.layout = 'vertical';
|
|
105
|
+
profile.picture.image = '/appicon.png';
|
|
106
|
+
profile.name.text = 'Mr. Man';
|
|
107
|
+
$.index.add(profile.getView());
|
|
108
|
+
$.index.open();
|
|
109
|
+
```
|
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
# Alloy XML Markup
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
|
|
5
|
+
- [Alloy XML Markup](#alloy-xml-markup)
|
|
6
|
+
- [Table of Contents](#table-of-contents)
|
|
7
|
+
- [Introduction](#introduction)
|
|
8
|
+
- [Collection Element](#collection-element)
|
|
9
|
+
- [Creating a Singleton](#creating-a-singleton)
|
|
10
|
+
- [Creating an Instance](#creating-an-instance)
|
|
11
|
+
- [Model Element](#model-element)
|
|
12
|
+
- [Creating a Singleton](#creating-a-singleton-1)
|
|
13
|
+
- [Creating an Instance](#creating-an-instance-1)
|
|
14
|
+
- [Module Attribute](#module-attribute)
|
|
15
|
+
- [Module Element](#module-element)
|
|
16
|
+
- [Require Element](#require-element)
|
|
17
|
+
- [Including Views](#including-views)
|
|
18
|
+
- [Importing Widgets](#importing-widgets)
|
|
19
|
+
- [Passing Arguments](#passing-arguments)
|
|
20
|
+
- [Binding Events](#binding-events)
|
|
21
|
+
- [Adding Children Views](#adding-children-views)
|
|
22
|
+
- [Namespace](#namespace)
|
|
23
|
+
- [Conditional Code](#conditional-code)
|
|
24
|
+
- [Property Mapping](#property-mapping)
|
|
25
|
+
- [Proxy Properties](#proxy-properties)
|
|
26
|
+
- [Android ActionBar](#android-actionbar)
|
|
27
|
+
- [iOS Navigation Button Shorthand](#ios-navigation-button-shorthand)
|
|
28
|
+
- [iOS SystemButton Shorthand](#ios-systembutton-shorthand)
|
|
29
|
+
- [TextField Keyboard Shorthands](#textfield-keyboard-shorthands)
|
|
30
|
+
- [Event Handling](#event-handling)
|
|
31
|
+
- [Data Binding](#data-binding)
|
|
32
|
+
- [Non-Standard Syntax](#non-standard-syntax)
|
|
33
|
+
|
|
34
|
+
## Introduction
|
|
35
|
+
|
|
36
|
+
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.
|
|
37
|
+
|
|
38
|
+
The following code is an example of a view file:
|
|
39
|
+
|
|
40
|
+
**app/views/index.xml**
|
|
41
|
+
|
|
42
|
+
```xml
|
|
43
|
+
<Alloy>
|
|
44
|
+
<Window class="container">
|
|
45
|
+
<Label id="label" onClick="doClick">Hello, World</Label>
|
|
46
|
+
</Window>
|
|
47
|
+
</Alloy>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
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.
|
|
51
|
+
|
|
52
|
+
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`.
|
|
53
|
+
|
|
54
|
+
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`.
|
|
55
|
+
|
|
56
|
+
The following table lists the attributes for the UI components:
|
|
57
|
+
|
|
58
|
+
| Attribute | Description |
|
|
59
|
+
| -------------- | -------------------------------------------------------------------------------------------------- |
|
|
60
|
+
| `id` | Identifies UI elements in the controller (prefixed with `$.`) and style sheet (prefixed with `#`). |
|
|
61
|
+
| `class` | Applies additional styles (prefixed with `.` in the TSS file). |
|
|
62
|
+
| `autoStyle` | Enables the autostyle feature for dynamic styling. |
|
|
63
|
+
| `formFactor` | Acts as a compiler directive for size-specific view components (`handheld` or `tablet`). |
|
|
64
|
+
| `if` | Use a custom query to apply additional styles to the element. |
|
|
65
|
+
| `module` | Requires in a CommonJS module. |
|
|
66
|
+
| `ns` | Overrides the default `Titanium.UI` namespace. |
|
|
67
|
+
| `platform` | Switches the namespace based on the platform. |
|
|
68
|
+
| `<properties>` | Assigns values to UI object properties. |
|
|
69
|
+
| `<events>` | Assigns callbacks to UI object events. |
|
|
70
|
+
|
|
71
|
+
The following table lists the special XML elements besides the Titanium UI components:
|
|
72
|
+
|
|
73
|
+
| Element | Description |
|
|
74
|
+
| ------------ | ----------------------------------------------------------- |
|
|
75
|
+
| `Alloy` | Root element for all view XML files. Required in all views. |
|
|
76
|
+
| `Collection` | Creates a singleton or instance of a collection. |
|
|
77
|
+
| `Model` | Creates a singleton or instance of a model. |
|
|
78
|
+
| `Module` | Imports a module view inside this view. |
|
|
79
|
+
| `Require` | Imports a widget or includes another view inside this view. |
|
|
80
|
+
| `Widget` | Imports a widget inside this view. |
|
|
81
|
+
|
|
82
|
+
`index.xml` is a special case that only accepts the following view components as direct children of the Alloy tag:
|
|
83
|
+
|
|
84
|
+
* `Ti.UI.Window` or `<Window>`
|
|
85
|
+
* `Ti.UI.TabGroup` or `<TabGroup>`
|
|
86
|
+
* `Ti.UI.NavigationWindow` or `<NavigationWindow>`
|
|
87
|
+
* `Ti.UI.iOS.SplitWindow` or `<SplitWindow>`
|
|
88
|
+
|
|
89
|
+
::: warning
|
|
90
|
+
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!" />`
|
|
91
|
+
:::
|
|
92
|
+
|
|
93
|
+
## Collection Element
|
|
94
|
+
|
|
95
|
+
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.
|
|
96
|
+
|
|
97
|
+
### Creating a Singleton
|
|
98
|
+
|
|
99
|
+
```xml
|
|
100
|
+
<Alloy>
|
|
101
|
+
<Collection src="book" />
|
|
102
|
+
<Window>
|
|
103
|
+
<TableView id="table" />
|
|
104
|
+
</Window>
|
|
105
|
+
</Alloy>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
```javascript
|
|
109
|
+
const library = Alloy.Collections.book;
|
|
110
|
+
library.fetch();
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Creating an Instance
|
|
114
|
+
|
|
115
|
+
```xml
|
|
116
|
+
<Alloy>
|
|
117
|
+
<Collection id="localLibrary" src="book" instance="true"/>
|
|
118
|
+
<Window>
|
|
119
|
+
<TableView id="table" />
|
|
120
|
+
</Window>
|
|
121
|
+
</Alloy>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
```javascript
|
|
125
|
+
const library = $.localLibrary;
|
|
126
|
+
library.fetch();
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Model Element
|
|
130
|
+
|
|
131
|
+
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.
|
|
132
|
+
|
|
133
|
+
### Creating a Singleton
|
|
134
|
+
|
|
135
|
+
```xml
|
|
136
|
+
<Alloy>
|
|
137
|
+
<Model src="book" />
|
|
138
|
+
<Window>
|
|
139
|
+
<TableView id="table" />
|
|
140
|
+
</Window>
|
|
141
|
+
</Alloy>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
const drama = Alloy.Models.book;
|
|
146
|
+
drama.set('title', 'Hamlet');
|
|
147
|
+
drama.set('author', 'William Shakespeare');
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Creating an Instance
|
|
151
|
+
|
|
152
|
+
```xml
|
|
153
|
+
<Alloy>
|
|
154
|
+
<Model id="myBook" src="book" instance="true"/>
|
|
155
|
+
<Window>
|
|
156
|
+
<TableView id="table" />
|
|
157
|
+
</Window>
|
|
158
|
+
</Alloy>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
```javascript
|
|
162
|
+
const drama = $.myBook;
|
|
163
|
+
drama.set('title', 'Hamlet');
|
|
164
|
+
drama.set('author', 'William Shakespeare');
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Module Attribute
|
|
168
|
+
|
|
169
|
+
You can require a CommonJS module in an Alloy view using the `module` attribute of an XML element.
|
|
170
|
+
|
|
171
|
+
**app/lib/foo.js**
|
|
172
|
+
|
|
173
|
+
```javascript
|
|
174
|
+
exports.createFoo = args => {
|
|
175
|
+
const viewArgs = {
|
|
176
|
+
backgroundColor: args.color || 'white',
|
|
177
|
+
width: 100,
|
|
178
|
+
height: 100
|
|
179
|
+
};
|
|
180
|
+
const view = Ti.UI.createView(viewArgs);
|
|
181
|
+
const labelArgs = {
|
|
182
|
+
color: args.textColor || 'black',
|
|
183
|
+
text: args.text || 'Foobar'
|
|
184
|
+
};
|
|
185
|
+
const label = Ti.UI.createLabel(labelArgs);
|
|
186
|
+
view.add(label);
|
|
187
|
+
return view;
|
|
188
|
+
};
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**app/views/index.xml**
|
|
192
|
+
|
|
193
|
+
```xml
|
|
194
|
+
<Alloy>
|
|
195
|
+
<Window backgroundColor="white">
|
|
196
|
+
<Foo module="foo" color="blue" textColor="orange" text="Hello, World!"/>
|
|
197
|
+
</Window>
|
|
198
|
+
</Alloy>
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Module Element
|
|
202
|
+
|
|
203
|
+
You can also include a view from a native module using the `Module` XML element.
|
|
204
|
+
|
|
205
|
+
**app/views/index.xml**
|
|
206
|
+
|
|
207
|
+
```xml
|
|
208
|
+
<Alloy>
|
|
209
|
+
<Window>
|
|
210
|
+
<Module id="paint" module="ti.paint" method="createPaintView" eraseMode="false" strokeWidth="1.0" strokeColor="red" strokeAlpha="100" />
|
|
211
|
+
<Button onClick="eraseMe" bottom="0">Erase</Button>
|
|
212
|
+
</Window>
|
|
213
|
+
</Alloy>
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
**app/controllers/index.js**
|
|
217
|
+
|
|
218
|
+
```javascript
|
|
219
|
+
function eraseMe() {
|
|
220
|
+
$.paint.clear();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
$.index.open();
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Require Element
|
|
227
|
+
|
|
228
|
+
The `Require` XML element has two uses: including external views and importing widgets into the current view.
|
|
229
|
+
|
|
230
|
+
### Including Views
|
|
231
|
+
|
|
232
|
+
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.
|
|
233
|
+
|
|
234
|
+
**app/views/index.xml**
|
|
235
|
+
|
|
236
|
+
```xml
|
|
237
|
+
<Alloy>
|
|
238
|
+
<TabGroup>
|
|
239
|
+
<Tab id="leftTab">
|
|
240
|
+
<Require type="view" src="rss" id="rssTab"/>
|
|
241
|
+
</Tab>
|
|
242
|
+
<Tab id="rightTab">
|
|
243
|
+
<Require type="view" src="about" id="aboutTab"/>
|
|
244
|
+
</Tab>
|
|
245
|
+
</TabGroup>
|
|
246
|
+
</Alloy>
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
To use UI objects from the included views:
|
|
250
|
+
|
|
251
|
+
```javascript
|
|
252
|
+
const aboutView = $.aboutTab.getView('aboutView');
|
|
253
|
+
aboutView.url = 'http://www.google.com';
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Importing Widgets
|
|
257
|
+
|
|
258
|
+
Within a view in the regular Alloy project space (`app/views`), use the `<Widget>` tag to import the widget into the application.
|
|
259
|
+
|
|
260
|
+
**To import a widget:**
|
|
261
|
+
|
|
262
|
+
1. Copy the widget to the `app/widgets` folder.
|
|
263
|
+
2. Add the `<Widget>` tag in the XML and specify its `src` attribute as the folder name of the widget.
|
|
264
|
+
3. Update the `dependencies` object in the `config.json` file.
|
|
265
|
+
|
|
266
|
+
**app/views/index.xml**
|
|
267
|
+
|
|
268
|
+
```xml
|
|
269
|
+
<Alloy>
|
|
270
|
+
<Window>
|
|
271
|
+
<Widget src="mywidget" id="foo" name="foo" />
|
|
272
|
+
</Window>
|
|
273
|
+
</Alloy>
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
**app/controllers/index.js**
|
|
277
|
+
|
|
278
|
+
```javascript
|
|
279
|
+
$.index.open();
|
|
280
|
+
$.foo.myMethod();
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Passing Arguments
|
|
284
|
+
|
|
285
|
+
You can add any custom attributes to the markup to initialize a widget or controller.
|
|
286
|
+
|
|
287
|
+
**apps/views/index.xml**
|
|
288
|
+
|
|
289
|
+
```xml
|
|
290
|
+
<Require id="foobar" src="foo" customTitle="Hello" customImage="hello.png"/>
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
This is equivalent to:
|
|
294
|
+
|
|
295
|
+
**apps/controllers/index.js**
|
|
296
|
+
|
|
297
|
+
```javascript
|
|
298
|
+
const foobar = Alloy.createController('foo', {
|
|
299
|
+
id: 'foobar',
|
|
300
|
+
customTitle: 'Hello',
|
|
301
|
+
customImage: 'images/hello.png'
|
|
302
|
+
});
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
In the required view's controller:
|
|
306
|
+
|
|
307
|
+
**apps/controllers/foo.js**
|
|
308
|
+
|
|
309
|
+
```javascript
|
|
310
|
+
const title = $.args.customTitle || 'Foobar';
|
|
311
|
+
const image = $.args.customImage || 'default.png';
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Binding Events
|
|
315
|
+
|
|
316
|
+
To bind a callback to an event in a required view using the `on` attribute:
|
|
317
|
+
|
|
318
|
+
Parent View:
|
|
319
|
+
|
|
320
|
+
```xml
|
|
321
|
+
<Require id="fooButton" src="button" onClick="doClick" />
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Button View:
|
|
325
|
+
|
|
326
|
+
```xml
|
|
327
|
+
<Alloy>
|
|
328
|
+
<Button id="button">Click Me!</Button>
|
|
329
|
+
</Alloy>
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
In the controller of the required view:
|
|
333
|
+
|
|
334
|
+
```
|
|
335
|
+
$.button.addEventListener('click', e => {
|
|
336
|
+
$.trigger('click', e);
|
|
337
|
+
});
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Adding Children Views
|
|
341
|
+
|
|
342
|
+
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`.
|
|
343
|
+
|
|
344
|
+
**app/views/info.xml**
|
|
345
|
+
|
|
346
|
+
```xml
|
|
347
|
+
<Alloy>
|
|
348
|
+
<View backgroundColor="yellow" borderWidth="0.5" borderColor="brown"/>
|
|
349
|
+
</Alloy>
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
**controllers/info.js**
|
|
353
|
+
|
|
354
|
+
```javascript
|
|
355
|
+
_.each($.args.children || [], child => {
|
|
356
|
+
$.info.add(child);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
$.info.height = Ti.UI.SIZE;
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
**app/views/index.xml**
|
|
363
|
+
|
|
364
|
+
```xml
|
|
365
|
+
<Alloy>
|
|
366
|
+
<Window class="container">
|
|
367
|
+
<Require src="info">
|
|
368
|
+
<Label>I am an info box.</Label>
|
|
369
|
+
</Require>
|
|
370
|
+
</Window>
|
|
371
|
+
</Alloy>
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
## Namespace
|
|
375
|
+
|
|
376
|
+
By default, all UI components specified in the views are prefixed with `Titanium.UI` for convenience. However, to use a component not part of the `Titanium.UI` namespace, use the `ns` attribute.
|
|
377
|
+
|
|
378
|
+
```xml
|
|
379
|
+
<BlurView ns="Ti.UI.iOS" id="blurView"/>
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
For UI objects that belong to a specific platform, use the `platform` attribute:
|
|
383
|
+
|
|
384
|
+
```xml
|
|
385
|
+
<SplitWindow platform="ios"/>
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
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:
|
|
389
|
+
|
|
390
|
+
| Element | Namespace |
|
|
391
|
+
| ---------------- | ------------- |
|
|
392
|
+
| Menu | Ti.Android |
|
|
393
|
+
| MenuItem | Ti.Android |
|
|
394
|
+
| Annotation | Ti.Map |
|
|
395
|
+
| VideoPlayer | Ti.Media |
|
|
396
|
+
| MusicPlayer | Ti.Media |
|
|
397
|
+
| SearchView | Ti.UI.Android |
|
|
398
|
+
| AdView | Ti.UI.iOS |
|
|
399
|
+
| CoverFlowView | Ti.UI.iOS |
|
|
400
|
+
| NavigationWindow | Ti.UI |
|
|
401
|
+
| TabbedBar | Ti.UI.iOS |
|
|
402
|
+
| DocumentViewer | Ti.UI.iOS |
|
|
403
|
+
| Popover | Ti.UI.iPad |
|
|
404
|
+
| SplitWindow | Ti.UI.iOS |
|
|
405
|
+
| StatusBar | Ti.UI.iOS |
|
|
406
|
+
|
|
407
|
+
## Conditional Code
|
|
408
|
+
|
|
409
|
+
Add the `platform`, `formFactor` and `if` attributes to apply XML elements based on conditionals.
|
|
410
|
+
|
|
411
|
+
* `platform`: Assign it a platform, such as, `android` or `ios`. Comma separate values to OR them. Prepend with `!` to negate.
|
|
412
|
+
* `formFactor`: Assign it a device size–either `handheld` or `tablet`.
|
|
413
|
+
* `if`: Assign it to a conditional statement in the `Alloy.Globals` namespace or `$.args` namespace.
|
|
414
|
+
|
|
415
|
+
```xml
|
|
416
|
+
<Alloy>
|
|
417
|
+
<Window>
|
|
418
|
+
<Module id="mapview" module="ti.map" method="createView">
|
|
419
|
+
<Annotation title="Cupertino" platform='ios' formFactor='tablet' latitude='37.3231' longitude='-122.0311'/>
|
|
420
|
+
<Annotation title="Redwood City" platform='ios' formFactor='handheld' latitude='37.4853' longitude='-122.2353'/>
|
|
421
|
+
<Annotation title="Mountain View" platform='android' latitude='37.3861' longitude='-122.0828'/>
|
|
422
|
+
<Annotation title="Palo Alto" platform='android,ios,mobileweb' latitude='37.4419' longitude='-122.1419'/>
|
|
423
|
+
<Annotation title="San Francisco" platform='mobileweb' latitude='37.7750' longitude='-122.4183'/>
|
|
424
|
+
</Module>
|
|
425
|
+
</Window>
|
|
426
|
+
</Alloy>
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
## Property Mapping
|
|
430
|
+
|
|
431
|
+
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.
|
|
432
|
+
|
|
433
|
+
```xml
|
|
434
|
+
<Label borderWidth="1" borderColor="red" color="red" width="Ti.UI.FILL">Hello, World!</Label>
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
### Proxy Properties
|
|
438
|
+
|
|
439
|
+
For properties that are assigned Titanium proxies, such as Views or Buttons, these properties can be declared. Create a child tag under the Titanium UI object tag, using the name of the property with the first character capitalized. Then, declare your Titanium proxy inline with the child property tag.
|
|
440
|
+
|
|
441
|
+
```xml
|
|
442
|
+
<Alloy>
|
|
443
|
+
<Window>
|
|
444
|
+
<RightNavButton>
|
|
445
|
+
<Button title="Back" onClick="closeWindow" />
|
|
446
|
+
</RightNavButton>
|
|
447
|
+
</Window>
|
|
448
|
+
</Alloy>
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
Currently, the following Titanium proxies and properties implemented using this syntax are:
|
|
452
|
+
|
|
453
|
+
| Titanium Proxy Object / Alloy tag | Proxy Property | Child Alloy Tag | Since |
|
|
454
|
+
| --------------------------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------- | --------------------------------------- |
|
|
455
|
+
| Ti.Android.MenuItem / `<MenuItem>` | actionView | `<ActionView>` | Alloy 1.6.0 |
|
|
456
|
+
| Ti.UI.iPad.Popover / `<PopOver>` | contentView | `<ContentView>` | Alloy 1.4.0 |
|
|
457
|
+
| Ti.UI.Label / `<Label>` | attributedString | `<AttributedString>` | Alloy 1.7.6 |
|
|
458
|
+
| Ti.UI.ListSection / `<ListSection>` | footerView, headerView | `<FooterView>`, `<HeaderView>` | Alloy 1.3.0 |
|
|
459
|
+
| Ti.UI.ListView / `<ListView>` | footerView, headerView, pullView, searchView | `<FooterView>`, `<HeaderView>`, `<PullView>`, `<SearchBar>` or `<SearchView platform="android">` | Alloy 1.3.0 |
|
|
460
|
+
| Ti.UI.OptionDialog / `<OptionDialog>` | androidView | `<AndroidView>` or `<View>` | Alloy 1.5.0 |
|
|
461
|
+
| Ti.UI.TableView / `<TableView>` | footerView, headerPullView, headerView, search | `<FooterView>`, `<HeaderPullView>`, `<HeaderView>`, `<Search>` | Alloy 1.1.0 |
|
|
462
|
+
| Ti.UI.TableViewSection / `<TableViewSection>` | headerView | `<HeaderView>` | - |
|
|
463
|
+
| Ti.UI.TextArea / `<TextArea>` | attributedString, keyboardToolbar | `<AttributedString>`, `<KeyboardToolbar>` | Alloy 1.7.6, 1.5.0 |
|
|
464
|
+
| 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 |
|
|
465
|
+
| Ti.UI.Window / `<Window>` | leftNavButton, rightNavButton, titleControl, toolbar | `<LeftNavButton>`, `<RightNavButton>`, `<TitleControl>`, `<WindowToolbar>` | Alloy 1.6.0 |
|
|
466
|
+
|
|
467
|
+
### Android ActionBar
|
|
468
|
+
|
|
469
|
+
You can set ActionBar properties in the `ActionBar` element.
|
|
470
|
+
|
|
471
|
+
**app/views/index.xml**
|
|
472
|
+
|
|
473
|
+
```xml
|
|
474
|
+
<Alloy>
|
|
475
|
+
<Window title="My App">
|
|
476
|
+
<ActionBar id="actionbar" platform="android" title="Home Screen" onHomeIconItemSelected="showInfo" />
|
|
477
|
+
<Menu>
|
|
478
|
+
<MenuItem id="editItem" title="Edit" onClick="editInfo" />
|
|
479
|
+
<MenuItem id="viewItem" title="View" onClick="viewInfo" />
|
|
480
|
+
</Menu>
|
|
481
|
+
<Label id="label">Use the ActionBar to Perform an Action.</Label>
|
|
482
|
+
</Window>
|
|
483
|
+
</Alloy>
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
### iOS Navigation Button Shorthand
|
|
487
|
+
|
|
488
|
+
When specifying either the `LeftNavButton` or `RightNavButton` element, you can define the `Button` attributes directly.
|
|
489
|
+
|
|
490
|
+
**app/views/index.xml**
|
|
491
|
+
|
|
492
|
+
```xml
|
|
493
|
+
<Alloy>
|
|
494
|
+
<NavigationWindow>
|
|
495
|
+
<Window>
|
|
496
|
+
<LeftNavButton title="Back" onClick="goBack" />
|
|
497
|
+
<Label>I am iOS!</Label>
|
|
498
|
+
</Window>
|
|
499
|
+
</NavigationWindow>
|
|
500
|
+
</Alloy>
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
### iOS SystemButton Shorthand
|
|
504
|
+
|
|
505
|
+
When specifying the `systemButton` attribute, you do not need to use the `Ti.UI.iOS.SystemButton` namespace.
|
|
506
|
+
|
|
507
|
+
```xml
|
|
508
|
+
<Button systemButton="CAMERA"/>
|
|
509
|
+
<!-- Instead of -->
|
|
510
|
+
<Button systemButton="Titanium.UI.iOS.SystemButton.CAMERA"/>
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
### TextField Keyboard Shorthands
|
|
514
|
+
|
|
515
|
+
When specifying the `keyboardType` or `returnKeyType` for a TextField:
|
|
516
|
+
|
|
517
|
+
```xml
|
|
518
|
+
<TextField id="txt" keyboardType="DECIMAL_PAD" returnKeyType="DONE"/>
|
|
519
|
+
|
|
520
|
+
"#txt": {
|
|
521
|
+
keyboardType: "DECIMAL_PAD",
|
|
522
|
+
returnKeyType: "DONE"
|
|
523
|
+
}
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
## Event Handling
|
|
527
|
+
|
|
528
|
+
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.
|
|
529
|
+
|
|
530
|
+
```xml
|
|
531
|
+
<Alloy>
|
|
532
|
+
<Window>
|
|
533
|
+
<Button id="confirmButton" onClick="confirmCB">OK</Button>
|
|
534
|
+
</Window>
|
|
535
|
+
</Alloy>
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
## Data Binding
|
|
539
|
+
|
|
540
|
+
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.
|
|
541
|
+
|
|
542
|
+
## Non-Standard Syntax
|
|
543
|
+
|
|
544
|
+
Some Titanium view elements use special syntax. Refer to the **Alloy XML Markup** examples in the Titanium API Guides site for the following view objects:
|
|
545
|
+
|
|
546
|
+
* [AlertDialog](https://titaniumsdk.com/api/titanium/ui/alertdialog.html)
|
|
547
|
+
* [ButtonBar](https://titaniumsdk.com/api/titanium/ui/buttonbar.html)
|
|
548
|
+
* [CoverFlowView](https://titaniumsdk.com/api/titanium/ui/ios/coverflowview.html)
|
|
549
|
+
* [DashboardView](https://titaniumsdk.com/api/titanium/ui/dashboardview.html)
|
|
550
|
+
* [ListView](https://titaniumsdk.com/api/titanium/ui/listview.html)
|
|
551
|
+
* [Map](https://titaniumsdk.com/api/modules/map.html)
|
|
552
|
+
* [Menu](https://titaniumsdk.com/api/titanium/android/menu.html)
|
|
553
|
+
* [OptionBar](https://titaniumsdk.com/api/titanium/ui/optionbar.html)
|
|
554
|
+
* [OptionDialog](https://titaniumsdk.com/api/titanium/ui/optiondialog.html)
|
|
555
|
+
* [Picker](https://titaniumsdk.com/api/titanium/ui/picker.html)
|
|
556
|
+
* [SplitWindow](https://titaniumsdk.com/api/titanium/ui/ios/splitwindow.html)
|
|
557
|
+
* [TabbedBar](https://titaniumsdk.com/api/titanium/ui/ios/tabbedbar.html)
|
|
558
|
+
* [Toolbar](https://titaniumsdk.com/api/titanium/ui/toolbar.html)
|