@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,176 @@
|
|
|
1
|
+
# Alloy Widgets
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
|
|
5
|
+
- [Alloy Widgets](#alloy-widgets)
|
|
6
|
+
- [Table of Contents](#table-of-contents)
|
|
7
|
+
- [Introduction](#introduction)
|
|
8
|
+
- [Using Widgets](#using-widgets)
|
|
9
|
+
- [Creating Widgets](#creating-widgets)
|
|
10
|
+
- [Assets and Libs](#assets-and-libs)
|
|
11
|
+
- [Configuration](#configuration)
|
|
12
|
+
- [Controllers](#controllers)
|
|
13
|
+
- [Models](#models)
|
|
14
|
+
- [Styles](#styles)
|
|
15
|
+
- [Themes](#themes)
|
|
16
|
+
- [Views](#views)
|
|
17
|
+
- [Widgets](#widgets)
|
|
18
|
+
|
|
19
|
+
## Introduction
|
|
20
|
+
|
|
21
|
+
Widgets are self-contained components that can be easily dropped into Alloy-powered Titanium projects. They were conceived as a way to reuse code in multiple applications or to be used multiple times in the same application. Widgets have their own views, controllers, styles and assets and are laid out the same as the `app` directory in the Alloy project.
|
|
22
|
+
|
|
23
|
+
## Using Widgets
|
|
24
|
+
|
|
25
|
+
See [Importing Widgets](./VIEWS_XML.md#importing-widgets) for more information on using widgets in your project.
|
|
26
|
+
|
|
27
|
+
## Creating Widgets
|
|
28
|
+
|
|
29
|
+
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. Additionally, 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.
|
|
30
|
+
|
|
31
|
+
## Assets and Libs
|
|
32
|
+
|
|
33
|
+
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.
|
|
34
|
+
|
|
35
|
+
For example, if you have a library located at `app/widgets/foo/lib/helper.js`, to require it:
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
require(WPATH('helper'))
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
If you have an image located at `app/widgets/foo/assets/images/foo.png`, to reference it:
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
WPATH('images/foo.png')
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Configuration
|
|
48
|
+
|
|
49
|
+
Widgets have their own configuration file called `widget.json` located in the widget's root directory.
|
|
50
|
+
|
|
51
|
+
Example **widget.json**:
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"id": "com.example.widget",
|
|
56
|
+
"name": "My Widget",
|
|
57
|
+
"description": "A sample widget",
|
|
58
|
+
"author": "Your Name",
|
|
59
|
+
"version": "1.0",
|
|
60
|
+
"platform": [
|
|
61
|
+
"android",
|
|
62
|
+
"ios"
|
|
63
|
+
],
|
|
64
|
+
"min_alloy": "1.0"
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Controllers
|
|
69
|
+
|
|
70
|
+
The main controller is called `widget.js` instead of `index.js`.
|
|
71
|
+
|
|
72
|
+
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.
|
|
73
|
+
|
|
74
|
+
**app/widgets/foo/controllers/widget.js**
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
const button = Widget.createController('button').getView();
|
|
78
|
+
$.widget.add(button);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
All methods in the widget controller are private unless you prefix the method with `$`, which makes it accessible to the Alloy project and other widgets.
|
|
82
|
+
|
|
83
|
+
**app/widgets/foo/controllers/widget.js**
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
$.init = args => {
|
|
87
|
+
$.button.title = args.title || 'Yes';
|
|
88
|
+
$.button.color = args.color || 'black';
|
|
89
|
+
const message = args.message || 'Hello World';
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Then, in the Alloy project:
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
$.foo.init({title:'Yes', color:'gray', message:'I pity the foo.'});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Models
|
|
100
|
+
|
|
101
|
+
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.
|
|
102
|
+
|
|
103
|
+
You can also use the `Model` and `Collection` tags in widget views.
|
|
104
|
+
|
|
105
|
+
## Styles
|
|
106
|
+
|
|
107
|
+
The main TSS file is called `widget.tss` instead of `index.tss`.
|
|
108
|
+
|
|
109
|
+
## Themes
|
|
110
|
+
|
|
111
|
+
Widget themes work the same as project themes except for the placement of the files. Inside your theme folder (`app/themes/<THEME_NAME>`), create `widgets/<WIDGET_NAME>` folders, where `<THEME_NAME>` is the name of the theme and `<WIDGET_NAME>` is the name of the widget.
|
|
112
|
+
|
|
113
|
+
Create two folders, `assets` and `styles`, to place your custom images and styles for your widget, respectively.
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
app
|
|
117
|
+
├── themes
|
|
118
|
+
│ └── mytheme
|
|
119
|
+
│ └── widgets
|
|
120
|
+
│ └── mywidget
|
|
121
|
+
│ ├── assets
|
|
122
|
+
│ │ ├── ios
|
|
123
|
+
│ │ │ └── star_half.png
|
|
124
|
+
│ │ ├── star.png
|
|
125
|
+
│ │ └── star_off.png
|
|
126
|
+
│ └── styles
|
|
127
|
+
│ ├── ios
|
|
128
|
+
│ │ └── star.tss
|
|
129
|
+
│ └── star.tss
|
|
130
|
+
└── widgets
|
|
131
|
+
└── mywidget
|
|
132
|
+
├── assets
|
|
133
|
+
│ ├── star.png
|
|
134
|
+
│ ├── star_half.png
|
|
135
|
+
│ └── star_off.png
|
|
136
|
+
├── controllers
|
|
137
|
+
│ ├── star.js
|
|
138
|
+
│ └── widget.js
|
|
139
|
+
├── styles
|
|
140
|
+
│ ├── star.tss
|
|
141
|
+
│ └── widget.tss
|
|
142
|
+
├── views
|
|
143
|
+
│ ├── star.xml
|
|
144
|
+
│ └── widget.xml
|
|
145
|
+
└── widget.json
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
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.
|
|
149
|
+
|
|
150
|
+
## Views
|
|
151
|
+
|
|
152
|
+
The main view is called `widget.xml` instead of `index.xml`.
|
|
153
|
+
|
|
154
|
+
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`:
|
|
155
|
+
|
|
156
|
+
```javascript
|
|
157
|
+
Ti.API.info("button state: " + $.foo.button.enabled);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
For widgets that have multiple view-controllers, to include a widget's view-controller in another widget's view, use the `Widget` tag and assign the `name` attribute with the name of the view-controller minus the file extension. Since Alloy 1.5.0, if you omit the `src` attribute, Alloy assumes you are referencing the current widget.
|
|
161
|
+
|
|
162
|
+
**app/widgets/foo/views/widget.xml**
|
|
163
|
+
|
|
164
|
+
```xml
|
|
165
|
+
<Alloy>
|
|
166
|
+
<View>
|
|
167
|
+
<Widget src="foo" name="button"/>
|
|
168
|
+
</View>
|
|
169
|
+
</Alloy>
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Widgets
|
|
173
|
+
|
|
174
|
+
Widgets can also contain other widgets. Follow the same directions from [Importing Widgets](./VIEWS_XML.md#importing-widgets) except the widget's configuration file is called `widget.json` instead of `config.json`.
|
|
175
|
+
|
|
176
|
+
To create a widget inside a widget controller, use the `Widget.createWidget(widget_name, [controller_name], [params])` method.
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: alloy-howtos
|
|
3
|
+
description: "Titanium Alloy CLI and configuration guide. Use when creating, reviewing, analyzing, or examining Alloy projects, running alloy commands (new, generate, compile), configuring alloy.jmk or config.json, debugging compilation errors, creating conditional views, using Backbone.Events for communication, or writing custom XML tags."
|
|
4
|
+
argument-hint: "[task]"
|
|
5
|
+
allowed-tools: Read, Grep, Glob, Edit, Write, Bash(alloy *), Bash(node *)
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Titanium Alloy How-tos
|
|
9
|
+
|
|
10
|
+
Comprehensive guide for the Alloy MVC Framework in Titanium SDK.
|
|
11
|
+
|
|
12
|
+
## Project Detection
|
|
13
|
+
|
|
14
|
+
:::info AUTO-DETECTS ALLOY PROJECTS
|
|
15
|
+
This skill automatically detects Alloy projects when invoked and provides CLI and configuration guidance.
|
|
16
|
+
|
|
17
|
+
**Detection occurs automatically** - no manual command needed.
|
|
18
|
+
|
|
19
|
+
**Alloy project indicators:**
|
|
20
|
+
- `app/` folder with Alloy structure
|
|
21
|
+
- `alloy.jmk` or `config.json` files
|
|
22
|
+
|
|
23
|
+
**Behavior based on detection:**
|
|
24
|
+
- **Alloy detected** → Provides Alloy CLI command guidance, configuration file help, Alloy-specific troubleshooting
|
|
25
|
+
- **Not detected** → Indicates this skill is for Alloy projects only, suggests Alloy guides if user wants to migrate
|
|
26
|
+
:::
|
|
27
|
+
|
|
28
|
+
## Table of Contents
|
|
29
|
+
|
|
30
|
+
- [Titanium Alloy How-tos](#titanium-alloy-how-tos)
|
|
31
|
+
- [Project Detection](#project-detection)
|
|
32
|
+
- [Table of Contents](#table-of-contents)
|
|
33
|
+
- [Quick Reference](#quick-reference)
|
|
34
|
+
- [Critical Best Practices](#critical-best-practices)
|
|
35
|
+
- [Naming Conventions](#naming-conventions)
|
|
36
|
+
- [Global Events - Use Backbone.Events](#global-events---use-backboneevents)
|
|
37
|
+
- [Global Variables in Non-Controller Files](#global-variables-in-non-controller-files)
|
|
38
|
+
- [Conditional Views](#conditional-views)
|
|
39
|
+
- [Common Error Solutions](#common-error-solutions)
|
|
40
|
+
- [CLI Quick Reference](#cli-quick-reference)
|
|
41
|
+
- [Configuration Files Priority](#configuration-files-priority)
|
|
42
|
+
- [Custom XML Tags](#custom-xml-tags)
|
|
43
|
+
- [Resources](#resources)
|
|
44
|
+
- [references/](#references)
|
|
45
|
+
- [Related Skills](#related-skills)
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Quick Reference
|
|
50
|
+
|
|
51
|
+
| Topic | Reference |
|
|
52
|
+
| -------------------------------------------- | ----------------------------------------------------------------------- |
|
|
53
|
+
| Best Practices & Naming Conventions | [best_practices.md](references/best_practices.md) |
|
|
54
|
+
| CLI Commands (new, generate, compile) | [cli_reference.md](references/cli_reference.md) |
|
|
55
|
+
| Configuration Files (alloy.jmk, config.json) | [config_files.md](references/config_files.md) |
|
|
56
|
+
| Custom XML Tags & Reusable Components | [custom_tags.md](references/custom_tags.md) |
|
|
57
|
+
| Debugging & Common Errors | [debugging_troubleshooting.md](references/debugging_troubleshooting.md) |
|
|
58
|
+
| Code Samples & Conditionals | [samples.md](references/samples.md) |
|
|
59
|
+
|
|
60
|
+
## Critical Best Practices
|
|
61
|
+
|
|
62
|
+
### Naming Conventions
|
|
63
|
+
- **Never use double underscore prefixes** (`__foo`) - reserved for Alloy
|
|
64
|
+
- **Never use JavaScript reserved words as IDs**
|
|
65
|
+
|
|
66
|
+
### Global Events - Use Backbone.Events
|
|
67
|
+
**AVOID** `Ti.App.fireEvent` / `Ti.App.addEventListener` - causes memory leaks and poor performance.
|
|
68
|
+
|
|
69
|
+
**USE** Backbone.Events pattern:
|
|
70
|
+
```javascript
|
|
71
|
+
// In alloy.js
|
|
72
|
+
Alloy.Events = _.clone(Backbone.Events);
|
|
73
|
+
|
|
74
|
+
// Listener
|
|
75
|
+
Alloy.Events.on('updateMainUI', refreshData);
|
|
76
|
+
// Clean up on close
|
|
77
|
+
$.controller.addEventListener('close', () => {
|
|
78
|
+
Alloy.Events.off('updateMainUI');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Trigger
|
|
82
|
+
Alloy.Events.trigger('updateMainUI');
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Global Variables in Non-Controller Files
|
|
86
|
+
Always require Alloy modules:
|
|
87
|
+
```javascript
|
|
88
|
+
const Alloy = require('alloy');
|
|
89
|
+
const Backbone = require('alloy/backbone');
|
|
90
|
+
const _ = require('alloy/underscore')._;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Conditional Views
|
|
94
|
+
|
|
95
|
+
Use IF attributes in XML for conditional rendering (evaluated before render):
|
|
96
|
+
|
|
97
|
+
```xml
|
|
98
|
+
<Alloy>
|
|
99
|
+
<Window>
|
|
100
|
+
<View if="Alloy.Globals.isLoggedIn()" id="notLoggedIn">
|
|
101
|
+
<Label text="Not logged in" />
|
|
102
|
+
</View>
|
|
103
|
+
<View if="!Alloy.Globals.isLoggedIn()" id="loggedIn">
|
|
104
|
+
<Label text="Logged in" />
|
|
105
|
+
</View>
|
|
106
|
+
</Window>
|
|
107
|
+
</Alloy>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Conditional TSS styles:
|
|
111
|
+
```tss
|
|
112
|
+
"#info[if=Alloy.Globals.isIos7Plus]": {
|
|
113
|
+
font: { textStyle: Ti.UI.TEXT_STYLE_FOOTNOTE }
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Data-binding conditionals:
|
|
118
|
+
```xml
|
|
119
|
+
<TableViewRow if="$model.shouldShowCommentRow()">
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Common Error Solutions
|
|
123
|
+
|
|
124
|
+
| Error | Solution |
|
|
125
|
+
| --------------------------------------- | ------------------------------------------------------- |
|
|
126
|
+
| `No app.js found` | Run `alloy compile --config platform=<platform>` |
|
|
127
|
+
| Android assets not showing | Use absolute paths (prepend `/`) |
|
|
128
|
+
| `Alloy is not defined` (non-controller) | Add `const Alloy = require('alloy');` |
|
|
129
|
+
| iOS `invalid method passed to UIModule` | Creating Android-only object - use `platform` attribute |
|
|
130
|
+
|
|
131
|
+
## CLI Quick Reference
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
# New project
|
|
135
|
+
alloy new [path] [template]
|
|
136
|
+
|
|
137
|
+
# Generate components
|
|
138
|
+
alloy generate controller <name>
|
|
139
|
+
alloy generate model <name> <adapter> <schema>
|
|
140
|
+
alloy generate style --all
|
|
141
|
+
|
|
142
|
+
# Compile
|
|
143
|
+
alloy compile [--config platform=android,deploytype=test]
|
|
144
|
+
|
|
145
|
+
# Extract i18n strings
|
|
146
|
+
alloy extract-i18n en --apply
|
|
147
|
+
|
|
148
|
+
# Copy/move/remove controllers
|
|
149
|
+
alloy copy <old> <new>
|
|
150
|
+
alloy move <old> <new>
|
|
151
|
+
alloy remove <name>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Configuration Files Priority
|
|
155
|
+
|
|
156
|
+
**config.json precedence:** `os:ios` > `env:production` > `global`
|
|
157
|
+
|
|
158
|
+
Access at runtime: `Alloy.CFG.yourKey`
|
|
159
|
+
|
|
160
|
+
## Custom XML Tags
|
|
161
|
+
|
|
162
|
+
Create reusable components without widgets - just drop a file in `app/lib/`:
|
|
163
|
+
|
|
164
|
+
**app/lib/checkbox.js**
|
|
165
|
+
```javascript
|
|
166
|
+
exports.createCheckBox = args => {
|
|
167
|
+
const wrapper = Ti.UI.createView({ layout: "horizontal", checked: false });
|
|
168
|
+
const box = Ti.UI.createView({ width: 15, height: 15, borderWidth: 1 });
|
|
169
|
+
// ... build component, return Ti.UI.* object
|
|
170
|
+
return wrapper;
|
|
171
|
+
};
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**view.xml**
|
|
175
|
+
```xml
|
|
176
|
+
<CheckBox module="checkbox" id="terms" caption="I agree" onChange="onCheck" />
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Key: `module` attribute points to file in `app/lib/` (without `.js`), function must be `create<TagName>`.
|
|
180
|
+
|
|
181
|
+
See [custom_tags.md](references/custom_tags.md) for complete examples.
|
|
182
|
+
|
|
183
|
+
## Resources
|
|
184
|
+
|
|
185
|
+
### references/
|
|
186
|
+
|
|
187
|
+
Complete documentation for each topic area:
|
|
188
|
+
- **best_practices.md** - Coding standards, naming conventions, global events patterns
|
|
189
|
+
- **cli_reference.md** - All CLI commands with options and model schema format
|
|
190
|
+
- **config_files.md** - alloy.jmk tasks, config.json structure, widget.json format
|
|
191
|
+
- **custom_tags.md** - Creating reusable custom XML tags without widgets
|
|
192
|
+
- **debugging_troubleshooting.md** - Common errors with solutions
|
|
193
|
+
- **samples.md** - Controller examples, conditional views, data-binding patterns
|
|
194
|
+
|
|
195
|
+
## Related Skills
|
|
196
|
+
|
|
197
|
+
For tasks beyond Alloy CLI and configuration, use these complementary skills:
|
|
198
|
+
|
|
199
|
+
| Task | Use This Skill |
|
|
200
|
+
| ---------------------------------------- | -------------- |
|
|
201
|
+
| Modern architecture, services, patterns | `alloy-expert` |
|
|
202
|
+
| Alloy MVC concepts, models, data binding | `alloy-guides` |
|
|
203
|
+
| SDK config, Hyperloop, app distribution | `ti-guides` |
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# Alloy Best Practices and Recommendations
|
|
2
|
+
|
|
3
|
+
This guide provides recommendations for writing Alloy applications. This guide supplements the existing Titanium SDK [Best Practices and Recommendations](https://titaniumsdk.com/guide/Titanium_SDK/Titanium_SDK_Guide/Best_Practices_and_Recommendations/) guide, specifically focusing on Coding Best Practices and Style and Conventions.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Alloy Best Practices and Recommendations](#alloy-best-practices-and-recommendations)
|
|
8
|
+
- [Table of Contents](#table-of-contents)
|
|
9
|
+
- [Titanium-to-Alloy Guidance](#titanium-to-alloy-guidance)
|
|
10
|
+
- [Loading Libraries in Alloy](#loading-libraries-in-alloy)
|
|
11
|
+
- [Performance Best Practices](#performance-best-practices)
|
|
12
|
+
- [Project Organization](#project-organization)
|
|
13
|
+
- [Coding Style Best Practices](#coding-style-best-practices)
|
|
14
|
+
- [Naming Conventions](#naming-conventions)
|
|
15
|
+
- [Global Variables](#global-variables)
|
|
16
|
+
- [Global Events](#global-events)
|
|
17
|
+
- [Use Callbacks for Master-Child Communication](#use-callbacks-for-master-child-communication)
|
|
18
|
+
- [Use Backbone.Events for App-Wide Communication](#use-backboneevents-for-app-wide-communication)
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Titanium-to-Alloy Guidance
|
|
23
|
+
|
|
24
|
+
### Loading Libraries in Alloy
|
|
25
|
+
|
|
26
|
+
If you have pre-existing functionality to make available globally, you can require modules in all controllers or create a single global reference:
|
|
27
|
+
|
|
28
|
+
**alloy.js**
|
|
29
|
+
```javascript
|
|
30
|
+
// Alloy.Globals.refToYourModule will be available in all controllers
|
|
31
|
+
Alloy.Globals.refToYourModule = require('yourModule');
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Performance Best Practices
|
|
35
|
+
|
|
36
|
+
The same best practices from traditional Titanium development apply to Alloy. Everything you can do in traditional Titanium development can be done in Alloy's controllers.
|
|
37
|
+
|
|
38
|
+
Use compiler directives to speed up runtime performance (see Conditional Code in Alloy Controllers).
|
|
39
|
+
|
|
40
|
+
### Project Organization
|
|
41
|
+
|
|
42
|
+
Determine if it makes sense to bend Alloy around your existing organization, or bend your existing organization around Alloy. Alloy was created to standardize Titanium coding methodologies, making projects cleaner and more maintainable.
|
|
43
|
+
|
|
44
|
+
## Coding Style Best Practices
|
|
45
|
+
|
|
46
|
+
### Naming Conventions
|
|
47
|
+
|
|
48
|
+
- **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.
|
|
49
|
+
- **Do not use JavaScript reserved words as IDs.** See [Titanium SDK Reserved Words](https://titaniumsdk.com/guide/Titanium_SDK/Titanium_SDK_Guide/Best_Practices_and_Recommendations/Reserved_Words/) for the complete list.
|
|
50
|
+
|
|
51
|
+
### Global Variables
|
|
52
|
+
|
|
53
|
+
Do not declare global variables in app.js and use them in other files. This is allowed but not recommended and will be deprecated.
|
|
54
|
+
|
|
55
|
+
Instead, declare these in your JS files:
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
const Alloy = require('alloy');
|
|
59
|
+
const Backbone = require('alloy/backbone');
|
|
60
|
+
const _ = require('alloy/underscore')._;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Safe pattern for non-controller files:
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
if (typeof Alloy === 'undefined') {
|
|
67
|
+
var Alloy = require('alloy');
|
|
68
|
+
}
|
|
69
|
+
if (typeof Backbone === 'undefined') {
|
|
70
|
+
var Backbone = require('alloy/backbone');
|
|
71
|
+
}
|
|
72
|
+
if (typeof _ === 'undefined') {
|
|
73
|
+
var _ = require('alloy/underscore')._;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const loading = Alloy.createWidget("com.titaniumsdk.loading");
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Global Events
|
|
80
|
+
|
|
81
|
+
**Avoid `Ti.App.fireEvent` and `Ti.App.addEventListener`** - This crosses the bridge between native and JavaScript lands, which can cause memory leaks and slower processes.
|
|
82
|
+
|
|
83
|
+
#### Use Callbacks for Master-Child Communication
|
|
84
|
+
|
|
85
|
+
**master.js**
|
|
86
|
+
```javascript
|
|
87
|
+
function openChild() {
|
|
88
|
+
Alloy.createController('child', {callback: refreshData});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function refreshData(value) {
|
|
92
|
+
// Refresh master data here
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**child.js**
|
|
97
|
+
```javascript
|
|
98
|
+
const args = arguments[0] || {};
|
|
99
|
+
|
|
100
|
+
function refreshParent() {
|
|
101
|
+
// Pass return value to parent
|
|
102
|
+
args.callback(true);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### Use Backbone.Events for App-Wide Communication
|
|
107
|
+
|
|
108
|
+
**alloy.js**
|
|
109
|
+
```javascript
|
|
110
|
+
Alloy.Events = _.clone(Backbone.Events);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**controller_a.js** (listener)
|
|
114
|
+
```javascript
|
|
115
|
+
Alloy.Events.on('updateMainUI', refreshData);
|
|
116
|
+
|
|
117
|
+
function refreshData(value) {
|
|
118
|
+
// Do work here
|
|
119
|
+
// Optionally disable one-time events
|
|
120
|
+
// Alloy.Events.off('updateMainUI');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Clean up when closing to avoid memory leaks
|
|
124
|
+
$.controller_a.addEventListener('close', () => {
|
|
125
|
+
Alloy.Events.off('updateMainUI');
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**controller_b.js** (trigger)
|
|
130
|
+
```javascript
|
|
131
|
+
Alloy.Events.trigger('updateMainUI');
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**Note:** Alloy controllers are Backbone event dispatchers. You can also use:
|
|
135
|
+
```javascript
|
|
136
|
+
Alloy.createController('child').on('refresh', refreshData);
|
|
137
|
+
```
|
|
138
|
+
This is a cleaner approach to cross-controller communication using Backbone's built-in event capabilities.
|