@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,160 +1,82 @@
|
|
|
1
|
-
# Alloy
|
|
1
|
+
# Alloy widgets
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A widget packages views, styles, controllers, assets and a manifest for reuse between apps. Use `<Require>` to reuse part of one app; use a widget for a component shared across apps.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Create and declare
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
See [Importing Widgets](./VIEWS_XML.md#importing-widgets) for more information on using widgets in your project.
|
|
10
|
-
|
|
11
|
-
## Creating Widgets
|
|
12
|
-
|
|
13
|
-
Widgets should be built in their own directory in the Alloy project's `app/widgets/` directory. Widgets have their own views, controllers, models, styles and assets and are laid out the same as the `app` directory in the Alloy project. Also, since widgets are self-contained, they should not reference any code or assets not within its path, except for internationalization and localization files, which are located in the `i18n` folder.
|
|
14
|
-
|
|
15
|
-
## Assets and Libs
|
|
16
|
-
|
|
17
|
-
For any files in the `assets` or `libs` folder, use the `WPATH()` macro to automatically map the path relative from the widget's root folder.
|
|
18
|
-
|
|
19
|
-
For example, if you have a library located at `app/widgets/foo/lib/helper.js`, to require it:
|
|
20
|
-
|
|
21
|
-
```javascript
|
|
22
|
-
require(WPATH('helper'))
|
|
7
|
+
```bash
|
|
8
|
+
alloy generate widget com.example.rating
|
|
23
9
|
```
|
|
24
10
|
|
|
25
|
-
|
|
11
|
+
The default controller is named `widget`, with these files under `app/widgets/com.example.rating/`:
|
|
26
12
|
|
|
27
|
-
```
|
|
28
|
-
|
|
13
|
+
```text
|
|
14
|
+
controllers/widget.js
|
|
15
|
+
views/widget.xml
|
|
16
|
+
styles/widget.tss
|
|
17
|
+
assets/
|
|
18
|
+
widget.json
|
|
29
19
|
```
|
|
30
20
|
|
|
31
|
-
## Configuration
|
|
32
|
-
|
|
33
|
-
Widgets have their own configuration file called `widget.json` located in the widget's root directory.
|
|
34
|
-
|
|
35
|
-
Example **widget.json**:
|
|
36
|
-
|
|
37
21
|
```json
|
|
38
22
|
{
|
|
39
|
-
"id": "com.example.
|
|
40
|
-
"name": "
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"version": "1.0",
|
|
44
|
-
"platform": [
|
|
45
|
-
"android",
|
|
46
|
-
"ios"
|
|
47
|
-
],
|
|
48
|
-
"min_alloy": "1.0"
|
|
23
|
+
"id": "com.example.rating",
|
|
24
|
+
"name": "rating",
|
|
25
|
+
"version": "1.0.0",
|
|
26
|
+
"platforms": "android,ios"
|
|
49
27
|
}
|
|
50
28
|
```
|
|
51
29
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
The main controller is called `widget.js` instead of `index.js`.
|
|
55
|
-
|
|
56
|
-
To use another view-controller besides `widget.js`/`widget.xml`, use the `Widget.createController(controller_name, [params])` method to create a new instance and the `getView()` method to access the Titanium proxy object.
|
|
30
|
+
The reverse-DNS ID must be unique across the app's widgets. Declare it in `app/config.json`, including when copying its directory from another project:
|
|
57
31
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"com.example.rating": "1.0.0"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
63
38
|
```
|
|
64
39
|
|
|
65
|
-
|
|
40
|
+
The generator creates a dependency; inspect it for the actual generated version. A declaration does not fetch files. Copy the widget directory or populate `app/widgets` with a build step, including one from an npm package. The current guide provides no registry workflow.
|
|
66
41
|
|
|
67
|
-
|
|
42
|
+
## Use and communicate
|
|
68
43
|
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
44
|
+
```xml
|
|
45
|
+
<Alloy>
|
|
46
|
+
<Window>
|
|
47
|
+
<Widget src="com.example.rating" id="rating" score="4" />
|
|
48
|
+
</Window>
|
|
49
|
+
</Alloy>
|
|
75
50
|
```
|
|
76
51
|
|
|
77
|
-
|
|
52
|
+
The widget reads `$.args.score`. Or construct it from JavaScript:
|
|
78
53
|
|
|
79
54
|
```javascript
|
|
80
|
-
|
|
55
|
+
const rating = Alloy.createWidget('com.example.rating', { score: 4 });
|
|
56
|
+
$.index.add(rating.getView());
|
|
81
57
|
```
|
|
82
58
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
Use models the same way as with a regular Alloy project except to create a model or collection inside a widget controller, use the `Widget.createModel(model_name, [params])` and `Widget.createCollection(model_name, [params])` methods, respectively.
|
|
86
|
-
|
|
87
|
-
You can also use the `Model` and `Collection` tags in widget views.
|
|
88
|
-
|
|
89
|
-
## Styles
|
|
90
|
-
|
|
91
|
-
The main TSS file is called `widget.tss` instead of `index.tss`.
|
|
59
|
+
The containing view must provide the `$.index` Window. Expose methods with `exports`, and send events with `$.trigger()`:
|
|
92
60
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
```
|
|
100
|
-
app
|
|
101
|
-
├── themes
|
|
102
|
-
│ └── mytheme
|
|
103
|
-
│ └── widgets
|
|
104
|
-
│ └── mywidget
|
|
105
|
-
│ ├── assets
|
|
106
|
-
│ │ ├── ios
|
|
107
|
-
│ │ │ └── star_half.png
|
|
108
|
-
│ │ ├── star.png
|
|
109
|
-
│ │ └── star_off.png
|
|
110
|
-
│ └── styles
|
|
111
|
-
│ ├── ios
|
|
112
|
-
│ │ └── star.tss
|
|
113
|
-
│ └── star.tss
|
|
114
|
-
└── widgets
|
|
115
|
-
└── mywidget
|
|
116
|
-
├── assets
|
|
117
|
-
│ ├── star.png
|
|
118
|
-
│ ├── star_half.png
|
|
119
|
-
│ └── star_off.png
|
|
120
|
-
├── controllers
|
|
121
|
-
│ ├── star.js
|
|
122
|
-
│ └── widget.js
|
|
123
|
-
├── styles
|
|
124
|
-
│ ├── star.tss
|
|
125
|
-
│ └── widget.tss
|
|
126
|
-
├── views
|
|
127
|
-
│ ├── star.xml
|
|
128
|
-
│ └── widget.xml
|
|
129
|
-
└── widget.json
|
|
61
|
+
```javascript
|
|
62
|
+
// Widget controller; its view provides a Label with id="stars".
|
|
63
|
+
exports.setScore = (score) => {
|
|
64
|
+
$.stars.text = '*'.repeat(score);
|
|
65
|
+
};
|
|
130
66
|
```
|
|
131
67
|
|
|
132
|
-
To use a theme, in the project's `config.json` file, add the `theme` key with the name of the theme folder as the value.
|
|
133
|
-
|
|
134
|
-
## Views
|
|
135
|
-
|
|
136
|
-
The main view is called `widget.xml` instead of `index.xml`.
|
|
137
|
-
|
|
138
|
-
Specifying the `id` attribute in the XML markup components will make it easier to access and override Titanium object properties. For example, if you have a Button object in a widget view with id `button` and in the Alloy project the widget id is `foo`:
|
|
139
|
-
|
|
140
68
|
```javascript
|
|
141
|
-
|
|
69
|
+
// App controller, after constructing rating.
|
|
70
|
+
rating.setScore(4);
|
|
71
|
+
rating.on('changed', (event) => {
|
|
72
|
+
Ti.API.info(event.score);
|
|
73
|
+
});
|
|
142
74
|
```
|
|
143
75
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
**app/widgets/foo/views/widget.xml**
|
|
147
|
-
|
|
148
|
-
```xml
|
|
149
|
-
<Alloy>
|
|
150
|
-
<View>
|
|
151
|
-
<Widget src="foo" name="button"/>
|
|
152
|
-
</View>
|
|
153
|
-
</Alloy>
|
|
154
|
-
```
|
|
76
|
+
The widget emits `$.trigger('changed', { score: 3 })` when its state changes, after listeners have been attached. Events emitted during construction can precede the caller's subscription. Clean up subscriptions with their owning controller.
|
|
155
77
|
|
|
156
|
-
##
|
|
78
|
+
## Isolation and styling
|
|
157
79
|
|
|
158
|
-
|
|
80
|
+
Keep widget styles and assets with the component and pass values such as `tint` in arguments rather than coupling it to one app's `Alloy.Globals`. The published guide describes stylesheet isolation, but released Alloy 3.0.1 includes matching app `app.tss` rules in widget styles: do not rely on a widget being shielded from global selectors. Use explicit widget styles and deliberate configuration to control its appearance. Keep assets in the widget's own directory; verify exact asset resolution for the target Alloy version when integrating an asset-heavy widget.
|
|
159
81
|
|
|
160
|
-
|
|
82
|
+
Source: [widgets](https://titaniumsdk.com/docs/alloy/widgets.md).
|
|
@@ -1,179 +1,24 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: alloy-howtos
|
|
3
|
-
description: Use when
|
|
3
|
+
description: Use when working on current Titanium Alloy app creation and conversion, config.json runtime settings, environment/platform overrides, compiler constants, widget dependencies, Backbone selection, alloy.jmk hooks, LiveView and build/runtime debugging. Applies to Alloy projects with app/views, app/controllers and app/config.json.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# Alloy workflows and configuration
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Load the relevant reference before changing an Alloy project's configuration or workflow.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
| Task | Reference |
|
|
11
|
+
| --- | --- |
|
|
12
|
+
| Current conventions, ownership and cleanup | [Practical conventions](references/best_practices.md) |
|
|
13
|
+
| App creation, conversion and supported guide workflows | [CLI workflow](references/cli_reference.md) |
|
|
14
|
+
| config.json, constants, dependencies, themes and hooks | [Configuration](references/config_files.md) |
|
|
15
|
+
| Build errors, logs, breakpoints, LiveView and profiling | [Debugging](references/debugging_troubleshooting.md) |
|
|
16
|
+
| A complete screen and links to persistent-list/widget examples | [Examples](references/samples.md) |
|
|
11
17
|
|
|
12
|
-
|
|
18
|
+
Run `ti info` before diagnosing a toolchain failure as an Alloy defect. Keep secrets out of config files and release logs. Configuration is compiled into the application; environment changes require a build. LiveView handles JavaScript changes, while native configuration/modules require rebuilding.
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
The currently published configuration page has release-sensitive details. Read the configuration reference's verified caveats before relying on conflicting environment/platform values or selecting a build hook. Confirm the installed Alloy release with `alloy --version`.
|
|
15
21
|
|
|
16
|
-
-
|
|
17
|
-
- Running or scripting the Alloy CLI (`alloy new`, `alloy generate`, `alloy compile`, ...)
|
|
18
|
-
- Configuring `alloy.jmk` build hooks or `config.json` environment / platform precedence
|
|
19
|
-
- Writing conditional views with `if=` in XML or TSS
|
|
20
|
-
- Building reusable custom XML tags in `app/lib/`
|
|
21
|
-
- Wiring cross-controller communication via `Backbone.Events`
|
|
22
|
-
- Diagnosing Alloy compilation errors or platform-specific runtime issues
|
|
22
|
+
Use `alloy-guides` for XML, controllers, TSS, models, migrations and widgets; `ti-guides` for SDK setup, modules and distribution; `ti-api` for exact API/platform contracts; and `ti-ui` for native layout/list behavior.
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
- Alloy MVC concepts, controllers, models, or data binding (use `alloy-guides`)
|
|
27
|
-
- Titanium SDK fundamentals, `tiapp.xml`, Hyperloop, or app distribution (use `ti-guides`)
|
|
28
|
-
- Native module dependency updates (use `ti-module-update`)
|
|
29
|
-
|
|
30
|
-
## Quick reference
|
|
31
|
-
|
|
32
|
-
| Topic | Reference |
|
|
33
|
-
|---|---|
|
|
34
|
-
| Coding standards, naming, global events patterns | [best_practices.md](references/best_practices.md) |
|
|
35
|
-
| All CLI commands with options and model schema format | [cli_reference.md](references/cli_reference.md) |
|
|
36
|
-
| `alloy.jmk` tasks, `config.json` structure, `widget.json` format | [config_files.md](references/config_files.md) |
|
|
37
|
-
| Creating reusable custom XML tags without widgets | [custom_tags.md](references/custom_tags.md) |
|
|
38
|
-
| Common errors with solutions | [debugging_troubleshooting.md](references/debugging_troubleshooting.md) |
|
|
39
|
-
| Controller examples, conditional views, data-binding patterns | [samples.md](references/samples.md) |
|
|
40
|
-
|
|
41
|
-
## Key practices
|
|
42
|
-
|
|
43
|
-
### Naming conventions
|
|
44
|
-
|
|
45
|
-
- **Never use double underscore prefixes** (`__foo`) — reserved for Alloy
|
|
46
|
-
- **Never use JavaScript reserved words as IDs**
|
|
47
|
-
|
|
48
|
-
### Global events — use Backbone.Events
|
|
49
|
-
|
|
50
|
-
Avoid `Ti.App.fireEvent` / `Ti.App.addEventListener`. They cross the native-JS bridge and can cause memory leaks and slower execution.
|
|
51
|
-
|
|
52
|
-
Use the Backbone.Events pattern:
|
|
53
|
-
|
|
54
|
-
```javascript
|
|
55
|
-
// In alloy.js
|
|
56
|
-
Alloy.Events = _.clone(Backbone.Events);
|
|
57
|
-
|
|
58
|
-
// Listener
|
|
59
|
-
Alloy.Events.on('updateMainUI', refreshData);
|
|
60
|
-
|
|
61
|
-
// Clean up on close
|
|
62
|
-
$.controller.addEventListener('close', () => {
|
|
63
|
-
Alloy.Events.off('updateMainUI');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// Trigger
|
|
67
|
-
Alloy.Events.trigger('updateMainUI');
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Global variables in non-controller files
|
|
71
|
-
|
|
72
|
-
Always require Alloy modules:
|
|
73
|
-
|
|
74
|
-
```javascript
|
|
75
|
-
const Alloy = require('alloy');
|
|
76
|
-
const Backbone = require('alloy/backbone');
|
|
77
|
-
const _ = require('alloy/underscore')._;
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
## Conditional views
|
|
81
|
-
|
|
82
|
-
Use `if` attributes in XML for conditional rendering (evaluated before render):
|
|
83
|
-
|
|
84
|
-
```xml
|
|
85
|
-
<Alloy>
|
|
86
|
-
<Window>
|
|
87
|
-
<View if="Alloy.Globals.isLoggedIn()" id="loggedIn">
|
|
88
|
-
<Label text="Logged in" />
|
|
89
|
-
</View>
|
|
90
|
-
<View if="!Alloy.Globals.isLoggedIn()" id="notLoggedIn">
|
|
91
|
-
<Label text="Not logged in" />
|
|
92
|
-
</View>
|
|
93
|
-
</Window>
|
|
94
|
-
</Alloy>
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
Conditional TSS styles:
|
|
98
|
-
|
|
99
|
-
```tss
|
|
100
|
-
"#info[if=Alloy.Globals.isIos7Plus]": {
|
|
101
|
-
font: { textStyle: Ti.UI.TEXT_STYLE_FOOTNOTE }
|
|
102
|
-
}
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
Data-binding conditionals:
|
|
106
|
-
|
|
107
|
-
```xml
|
|
108
|
-
<TableViewRow if="$model.shouldShowCommentRow()">
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## Common error solutions
|
|
112
|
-
|
|
113
|
-
| Error | Solution |
|
|
114
|
-
|---|---|
|
|
115
|
-
| `No app.js found` | Run `alloy compile --config platform=<platform>` |
|
|
116
|
-
| Android assets not showing | Use absolute paths (prepend `/`) |
|
|
117
|
-
| `Alloy is not defined` (non-controller) | Add `const Alloy = require('alloy');` |
|
|
118
|
-
| iOS `invalid method passed to UIModule` | Creating Android-only object — use `platform` attribute |
|
|
119
|
-
|
|
120
|
-
## CLI quick reference
|
|
121
|
-
|
|
122
|
-
```bash
|
|
123
|
-
# New project
|
|
124
|
-
alloy new [path] [template]
|
|
125
|
-
|
|
126
|
-
# Generate components
|
|
127
|
-
alloy generate controller <name>
|
|
128
|
-
alloy generate model <name> <adapter> <schema>
|
|
129
|
-
alloy generate style --all
|
|
130
|
-
|
|
131
|
-
# Compile
|
|
132
|
-
alloy compile [--config platform=android,deploytype=test]
|
|
133
|
-
|
|
134
|
-
# Extract i18n strings
|
|
135
|
-
alloy extract-i18n en --apply
|
|
136
|
-
|
|
137
|
-
# Copy / move / remove controllers
|
|
138
|
-
alloy copy <old> <new>
|
|
139
|
-
alloy move <old> <new>
|
|
140
|
-
alloy remove <name>
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
## Configuration files priority
|
|
144
|
-
|
|
145
|
-
`config.json` precedence: `os:<platform>` > `env:<environment>` > `global`
|
|
146
|
-
|
|
147
|
-
Access at runtime: `Alloy.CFG.<key>`
|
|
148
|
-
|
|
149
|
-
## Custom XML tags
|
|
150
|
-
|
|
151
|
-
Reusable components without the overhead of widgets. Drop a file in `app/lib/`:
|
|
152
|
-
|
|
153
|
-
**`app/lib/checkbox.js`**
|
|
154
|
-
```javascript
|
|
155
|
-
exports.createCheckBox = args => {
|
|
156
|
-
const wrapper = Ti.UI.createView({ layout: 'horizontal', checked: false });
|
|
157
|
-
const box = Ti.UI.createView({ width: 15, height: 15, borderWidth: 1 });
|
|
158
|
-
// ... build component, return Ti.UI.* object
|
|
159
|
-
return wrapper;
|
|
160
|
-
};
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
**`view.xml`**
|
|
164
|
-
```xml
|
|
165
|
-
<CheckBox module="checkbox" id="terms" caption="I agree" onChange="onCheck" />
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
The `module` attribute points to the file in `app/lib/` (without `.js`). The function must be `create<TagName>`.
|
|
169
|
-
|
|
170
|
-
See [custom_tags.md](references/custom_tags.md) for the complete worked example.
|
|
171
|
-
|
|
172
|
-
## Related skills
|
|
173
|
-
|
|
174
|
-
| Task | Use this skill |
|
|
175
|
-
|---|---|
|
|
176
|
-
| Alloy MVC concepts, controllers, models, data binding | `alloy-guides` |
|
|
177
|
-
| Titanium SDK config, Hyperloop, app distribution | `ti-guides` |
|
|
178
|
-
| Titanium API lookup (Ti.UI, Ti.Network, modules) | `ti-api` |
|
|
179
|
-
| Native module dependency updates | `ti-module-update` |
|
|
24
|
+
Sources: [current Alloy guides](https://titaniumsdk.com/docs/alloy.md), [first app](https://titaniumsdk.com/docs/build/first-app.md), [debugging](https://titaniumsdk.com/docs/build/debugging.md).
|
|
@@ -1,121 +1,17 @@
|
|
|
1
|
-
# Alloy
|
|
1
|
+
# Practical Alloy conventions
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Keep structure in XML, shared appearance in `app/styles/app.tss`, screen-specific styles in the corresponding TSS file and behavior in the controller. The controller can still use the Titanium API directly.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Read `$.args` at the top of a controller so its inputs are visible in one place. Share plain code through CommonJS modules in `app/lib`, and initialize shared configuration in `app/alloy.js` before the first controller.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
A controller is not a native Window. Construct it, then call `getView().open()`, or expose a method that opens its own Window. Do not combine both opening approaches.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Clean up external listeners, timers and service subscriptions when the controller is disposed. Separately call `$.destroy()` to remove generated data bindings. See [controllers](../../alloy-guides/references/CONTROLLERS.md#cleaning-up) for callback ownership and the required lifecycle.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
```javascript
|
|
13
|
-
// Alloy.Globals.refToYourModule will be available in all controllers
|
|
14
|
-
Alloy.Globals.refToYourModule = require('yourModule');
|
|
15
|
-
```
|
|
11
|
+
Use widgets for reuse between projects and `<Require>` for composition within one app. Pass widget arguments and report changes through exported methods/events; coupling a reusable widget to the app's global state defeats that isolation.
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
Use models for data that persists, is shared between screens or outlives a screen. A plain array and `Ti.Network` are adequate for data fetched once and rendered. Keep data transforms inexpensive because they run per row when data changes.
|
|
18
14
|
|
|
19
|
-
|
|
15
|
+
Do not edit or commit generated `Resources/` or `build/`. Keep signing credentials out of the repository. Do not put secrets in `config.json` or production logs; both reach the app package/device.
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
### Project Organization
|
|
24
|
-
|
|
25
|
-
Decide whether to adapt Alloy to your existing structure, or to adopt Alloy's structure. Alloy standardizes common Titanium patterns and makes projects easier to maintain.
|
|
26
|
-
|
|
27
|
-
## Coding Style Best Practices
|
|
28
|
-
|
|
29
|
-
### Naming Conventions
|
|
30
|
-
|
|
31
|
-
- **Do not use double underscore prefixes** on variables, properties, or function names (e.g., `__foo`). They are reserved for Alloy and may cause conflicts and unexpected behavior.
|
|
32
|
-
- **Do not use JavaScript reserved words as IDs.** See [Titanium SDK Reserved Words](https://titaniumsdk.com/docs/buildReserved_Words/) for the complete list.
|
|
33
|
-
|
|
34
|
-
### Global Variables
|
|
35
|
-
|
|
36
|
-
Avoid declaring globals in app.js and using them in other files. It still works, but it is not recommended and may be deprecated.
|
|
37
|
-
|
|
38
|
-
Instead, declare these in your JS files:
|
|
39
|
-
|
|
40
|
-
```javascript
|
|
41
|
-
const Alloy = require('alloy');
|
|
42
|
-
const Backbone = require('alloy/backbone');
|
|
43
|
-
const _ = require('alloy/underscore')._;
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Safe pattern for non-controller files:
|
|
47
|
-
|
|
48
|
-
```javascript
|
|
49
|
-
if (typeof Alloy === 'undefined') {
|
|
50
|
-
var Alloy = require('alloy');
|
|
51
|
-
}
|
|
52
|
-
if (typeof Backbone === 'undefined') {
|
|
53
|
-
var Backbone = require('alloy/backbone');
|
|
54
|
-
}
|
|
55
|
-
if (typeof _ === 'undefined') {
|
|
56
|
-
var _ = require('alloy/underscore')._;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const loading = Alloy.createWidget("com.titaniumsdk.loading");
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### Global Events
|
|
63
|
-
|
|
64
|
-
**Avoid `Ti.App.fireEvent` and `Ti.App.addEventListener`.** It crosses the native-JS bridge and can cause memory leaks and slower execution.
|
|
65
|
-
|
|
66
|
-
#### Use Callbacks for Master-Child Communication
|
|
67
|
-
|
|
68
|
-
**master.js**
|
|
69
|
-
```javascript
|
|
70
|
-
function openChild() {
|
|
71
|
-
Alloy.createController('child', {callback: refreshData});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function refreshData(value) {
|
|
75
|
-
// Refresh master data here
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
**child.js**
|
|
80
|
-
```javascript
|
|
81
|
-
const args = arguments[0] || {};
|
|
82
|
-
|
|
83
|
-
function refreshParent() {
|
|
84
|
-
// Pass return value to parent
|
|
85
|
-
args.callback(true);
|
|
86
|
-
}
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
#### Use Backbone.Events for App-Wide Communication
|
|
90
|
-
|
|
91
|
-
**alloy.js**
|
|
92
|
-
```javascript
|
|
93
|
-
Alloy.Events = _.clone(Backbone.Events);
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
**controller_a.js** (listener)
|
|
97
|
-
```javascript
|
|
98
|
-
Alloy.Events.on('updateMainUI', refreshData);
|
|
99
|
-
|
|
100
|
-
function refreshData(value) {
|
|
101
|
-
// Do work here
|
|
102
|
-
// Optionally disable one-time events
|
|
103
|
-
// Alloy.Events.off('updateMainUI');
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Clean up when closing to avoid memory leaks
|
|
107
|
-
$.controller_a.addEventListener('close', () => {
|
|
108
|
-
Alloy.Events.off('updateMainUI');
|
|
109
|
-
});
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
**controller_b.js** (trigger)
|
|
113
|
-
```javascript
|
|
114
|
-
Alloy.Events.trigger('updateMainUI');
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
**Note:** Alloy controllers are Backbone event dispatchers. You can also use:
|
|
118
|
-
```javascript
|
|
119
|
-
Alloy.createController('child').on('refresh', refreshData);
|
|
120
|
-
```
|
|
121
|
-
This is a simpler way to do cross-controller communication with Backbone events.
|
|
17
|
+
Sources: [Alloy](https://titaniumsdk.com/docs/alloy.md), [controllers](https://titaniumsdk.com/docs/alloy/controllers.md), [models](https://titaniumsdk.com/docs/alloy/models.md), [widgets](https://titaniumsdk.com/docs/alloy/widgets.md), [project structure](https://titaniumsdk.com/docs/build/project-structure.md).
|