@maccesar/titools 5.2.5 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/CONTRIBUTING.md +1 -1
  2. package/README.md +58 -97
  3. package/agents/ti-pro.md +4 -2
  4. package/commands/ti-audit.md +7 -5
  5. package/docs/examples.md +24 -13
  6. package/docs/knowledge-index.md +2 -1
  7. package/lib/config.js +1 -0
  8. package/package.json +1 -1
  9. package/skills/alloy-guides/SKILL.md +18 -179
  10. package/skills/alloy-guides/references/CLI_TASKS.md +17 -216
  11. package/skills/alloy-guides/references/CONCEPTS.md +27 -162
  12. package/skills/alloy-guides/references/CONTROLLERS.md +38 -236
  13. package/skills/alloy-guides/references/MODELS.md +47 -723
  14. package/skills/alloy-guides/references/MODELS_ADVANCED.md +21 -482
  15. package/skills/alloy-guides/references/VIEWS_DYNAMIC.md +12 -222
  16. package/skills/alloy-guides/references/VIEWS_STYLES.md +39 -358
  17. package/skills/alloy-guides/references/VIEWS_XML.md +36 -552
  18. package/skills/alloy-guides/references/WIDGETS.md +49 -127
  19. package/skills/alloy-howtos/SKILL.md +14 -169
  20. package/skills/alloy-howtos/references/best_practices.md +9 -113
  21. package/skills/alloy-howtos/references/cli_reference.md +18 -223
  22. package/skills/alloy-howtos/references/config_files.md +50 -133
  23. package/skills/alloy-howtos/references/debugging_troubleshooting.md +19 -63
  24. package/skills/alloy-howtos/references/samples.md +21 -138
  25. package/skills/ti-api/SKILL.md +10 -2
  26. package/skills/ti-api/references/api-android.md +36 -2
  27. package/skills/ti-api/references/api-app-platform.md +39 -3
  28. package/skills/ti-api/references/api-core.md +50 -18
  29. package/skills/ti-api/references/api-data-network.md +49 -35
  30. package/skills/ti-api/references/api-media.md +45 -27
  31. package/skills/ti-api/references/api-services.md +39 -9
  32. package/skills/ti-api/references/api-ui-android.md +33 -13
  33. package/skills/ti-api/references/api-ui-extras.md +41 -15
  34. package/skills/ti-api/references/api-ui-ios-animator.md +42 -26
  35. package/skills/ti-api/references/api-ui-ios.md +74 -2
  36. package/skills/ti-api/references/api-ui-lists.md +32 -16
  37. package/skills/ti-api/references/api-ui-text-input.md +34 -17
  38. package/skills/ti-api/references/api-ui-views.md +27 -1
  39. package/skills/ti-api/references/api-ui-windows-navigation.md +32 -18
  40. package/skills/ti-api/references/api-xml-global.md +66 -16
  41. package/skills/ti-create-release/SKILL.md +98 -0
  42. package/skills/ti-create-release/references/module-discovery.md +69 -0
  43. package/skills/ti-expert/references/adaptive-layouts.md +1 -1
  44. package/skills/ti-guides/SKILL.md +37 -76
  45. package/skills/ti-guides/references/advanced-data-and-images.md +122 -126
  46. package/skills/ti-guides/references/android-manifest.md +24 -83
  47. package/skills/ti-guides/references/app-distribution.md +31 -377
  48. package/skills/ti-guides/references/application-frameworks.md +127 -335
  49. package/skills/ti-guides/references/cli-reference.md +184 -633
  50. package/skills/ti-guides/references/commonjs-advanced.md +81 -231
  51. package/skills/ti-guides/references/compatibility-matrix.md +36 -75
  52. package/skills/ti-guides/references/hello-world.md +95 -70
  53. package/skills/ti-guides/references/hyperloop-native-access.md +52 -448
  54. package/skills/ti-guides/references/resources.md +174 -142
  55. package/skills/ti-guides/references/sdk-release-notes.md +28 -71
  56. package/skills/ti-guides/references/tiapp-config.md +222 -598
  57. package/skills/ti-howtos/SKILL.md +23 -123
  58. package/skills/ti-howtos/references/cross-platform-development.md +119 -324
  59. package/skills/ti-howtos/references/debugging-profiling.md +77 -445
  60. package/skills/ti-howtos/references/extending-titanium.md +199 -673
  61. package/skills/ti-howtos/references/local-data-sources.md +87 -300
  62. package/skills/ti-howtos/references/location-and-maps.md +86 -213
  63. package/skills/ti-howtos/references/media-apis.md +103 -223
  64. package/skills/ti-howtos/references/notification-services.md +86 -506
  65. package/skills/ti-howtos/references/remote-data-sources.md +97 -316
  66. package/skills/ti-howtos/references/using-modules.md +77 -133
  67. package/skills/ti-synthengine/SKILL.md +62 -111
  68. package/skills/ti-synthengine/assets/example/README.md +50 -59
  69. package/skills/ti-synthengine/assets/example/app.js +67 -65
  70. package/skills/ti-synthengine/assets/example/lib/sequenceOwner.js +39 -40
  71. package/skills/ti-synthengine/assets/example/lib/soundPreset.js +34 -0
  72. package/skills/ti-synthengine/assets/index.d.ts +122 -2
  73. package/skills/ti-synthengine/references/advanced-examples.md +4 -4
  74. package/skills/ti-synthengine/references/api.md +40 -18
  75. package/skills/ti-synthengine/references/audio-engine.md +15 -57
  76. package/skills/ti-synthengine/references/examples.md +63 -6
  77. package/skills/ti-synthengine/references/guide.md +61 -57
  78. package/skills/ti-synthengine/references/instruments-and-effects.md +15 -15
  79. package/skills/ti-synthengine/references/native-variation.md +53 -14
  80. package/skills/ti-synthengine/references/recipes-interaction.md +25 -20
  81. package/skills/ti-synthengine/references/recipes.md +19 -16
  82. package/skills/ti-synthengine/references/recommendations.md +12 -12
  83. package/skills/ti-synthengine/references/sound-api.md +197 -0
  84. package/skills/ti-synthengine/references/sound-design.md +7 -7
  85. package/skills/ti-synthengine/references/source-notes.md +62 -172
  86. package/skills/ti-synthengine/references/troubleshooting.md +17 -19
  87. package/skills/ti-synthengine/references/upgrade-2.0.0.md +40 -0
  88. package/skills/ti-ui/SKILL.md +28 -143
  89. package/skills/ti-ui/references/icons-and-splash-screens.md +74 -403
  90. package/skills/ti-ui/references/layouts-and-positioning.md +175 -402
  91. package/skills/ti-ui/references/listviews-and-performance.md +100 -703
  92. package/skills/ti-ui/references/platform-conventions.md +180 -0
  93. package/skills/ti-ui/references/user-interface.md +43 -0
  94. package/skills/alloy-guides/references/VIEWS_WITHOUT_CONTROLLERS.md +0 -102
  95. package/skills/alloy-howtos/references/custom_tags.md +0 -148
  96. package/skills/ti-guides/references/coding-best-practices.md +0 -149
  97. package/skills/ti-guides/references/javascript-primer.md +0 -414
  98. package/skills/ti-guides/references/reserved-words.md +0 -36
  99. package/skills/ti-guides/references/style-and-conventions.md +0 -103
  100. package/skills/ti-howtos/references/android-platform-deep-dives.md +0 -624
  101. package/skills/ti-howtos/references/automation-fastlane-appium.md +0 -96
  102. package/skills/ti-howtos/references/buffer-codec-streams.md +0 -162
  103. package/skills/ti-howtos/references/google-maps-v2.md +0 -172
  104. package/skills/ti-howtos/references/ios-map-kit.md +0 -149
  105. package/skills/ti-howtos/references/ios-platform-deep-dives.md +0 -611
  106. package/skills/ti-howtos/references/tutorials.md +0 -565
  107. package/skills/ti-howtos/references/web-content-integration.md +0 -287
  108. package/skills/ti-howtos/references/webpack-build-pipeline.md +0 -124
  109. package/skills/ti-synthengine/references/android-sim80-correction-evidence.zip +0 -0
  110. package/skills/ti-synthengine/references/android-sim80-correction.json +0 -162
  111. package/skills/ti-synthengine/references/audio-pipeline-validation.md +0 -19
  112. package/skills/ti-synthengine/references/bypass-physical-recheck-evidence.zip +0 -0
  113. package/skills/ti-synthengine/references/frontier-android-evidence.zip +0 -0
  114. package/skills/ti-synthengine/references/frontier-ipad-evidence.zip +0 -0
  115. package/skills/ti-synthengine/references/frontier-physical-validation.json +0 -1918
  116. package/skills/ti-synthengine/references/native-tone-repetition-validation.md +0 -59
  117. package/skills/ti-synthengine/references/native-variation-proposal.md +0 -182
  118. package/skills/ti-synthengine/references/native-variation-validation.md +0 -63
  119. package/skills/ti-synthengine/references/performance-review-evidence.zip +0 -0
  120. package/skills/ti-synthengine/references/performance-review.json +0 -1146
  121. package/skills/ti-synthengine/references/physical-validation.json +0 -1457
  122. package/skills/ti-synthengine/references/source-snapshot.json +0 -542
  123. package/skills/ti-synthengine/references/stats-performance.json +0 -2992
  124. package/skills/ti-synthengine/references/stats-performance.md +0 -82
  125. package/skills/ti-synthengine/references/studio-validation.json +0 -6202
  126. package/skills/ti-synthengine/references/unified-bypass-performance.json +0 -22425
  127. package/skills/ti-synthengine/references/unified-validation.json +0 -314
  128. package/skills/ti-ui/references/accessibility-deep-dive.md +0 -288
  129. package/skills/ti-ui/references/animation-and-matrices.md +0 -569
  130. package/skills/ti-ui/references/application-structures.md +0 -626
  131. package/skills/ti-ui/references/custom-fonts-styling.md +0 -549
  132. package/skills/ti-ui/references/event-handling.md +0 -401
  133. package/skills/ti-ui/references/gestures.md +0 -448
  134. package/skills/ti-ui/references/orientation.md +0 -374
  135. package/skills/ti-ui/references/platform-ui-android.md +0 -727
  136. package/skills/ti-ui/references/platform-ui-ios.md +0 -576
  137. package/skills/ti-ui/references/scrolling-views.md +0 -288
  138. package/skills/ti-ui/references/tableviews.md +0 -542
@@ -1,160 +1,82 @@
1
- # Alloy Widgets
1
+ # Alloy widgets
2
2
 
3
- ## Introduction
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
- 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.
5
+ ## Create and declare
6
6
 
7
- ## Using Widgets
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
- If you have an image located at `app/widgets/foo/assets/images/foo.png`, to reference it:
11
+ The default controller is named `widget`, with these files under `app/widgets/com.example.rating/`:
26
12
 
27
- ```javascript
28
- WPATH('images/foo.png')
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.widget",
40
- "name": "My Widget",
41
- "description": "A sample widget",
42
- "author": "Your Name",
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
- ## Controllers
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
- **app/widgets/foo/controllers/widget.js**
59
-
60
- ```javascript
61
- const button = Widget.createController('button').getView();
62
- $.widget.add(button);
32
+ ```json
33
+ {
34
+ "dependencies": {
35
+ "com.example.rating": "1.0.0"
36
+ }
37
+ }
63
38
  ```
64
39
 
65
- 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.
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
- **app/widgets/foo/controllers/widget.js**
42
+ ## Use and communicate
68
43
 
69
- ```javascript
70
- $.init = args => {
71
- $.button.title = args.title || 'Yes';
72
- $.button.color = args.color || 'black';
73
- const message = args.message || 'Hello World';
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
- Then, in the Alloy project:
52
+ The widget reads `$.args.score`. Or construct it from JavaScript:
78
53
 
79
54
  ```javascript
80
- $.foo.init({title:'Yes', color:'gray', message:'I pity the foo.'});
55
+ const rating = Alloy.createWidget('com.example.rating', { score: 4 });
56
+ $.index.add(rating.getView());
81
57
  ```
82
58
 
83
- ## Models
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
- ## Themes
94
-
95
- 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. When using a theme, the files in these folders replace the files in the widget's folders.
96
-
97
- Create two folders, `assets` and `styles`, to place your custom images and styles for your widget, respectively.
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
- Ti.API.info("button state: " + $.foo.button.enabled);
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
- 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. For Alloy 1.4.x and prior, you need to assign the `src` attribute to the widget's name.
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
- ## Widgets
78
+ ## Isolation and styling
157
79
 
158
- 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`.
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
- To create a widget inside a widget controller, use the `Widget.createWidget(widget_name, [controller_name], [params])` method.
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 an Alloy MVC project needs help with the Alloy CLI (`alloy new`, `alloy generate`, `alloy compile`, `alloy extract-i18n`), configuration files (`alloy.jmk` build hooks, `config.json` env/platform precedence, `widget.json`), conditional views (`if=` attribute in XML/TSS), custom XML tags via `app/lib/`, Backbone.Events for cross-controller communication, or debugging Alloy compilation errors. Triggers include `app/views/` + `app/controllers/`, `alloy.jmk`, or `config.json` in the project root.
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
- # alloy-howtos
6
+ # Alloy workflows and configuration
7
7
 
8
- ## Overview
8
+ Load the relevant reference before changing an Alloy project's configuration or workflow.
9
9
 
10
- Practical reference for Titanium Alloy MVC projects: CLI usage, project configuration, conditional rendering, custom XML tags, cross-controller communication, and common compilation/runtime errors. Reference-style — load the relevant file from `references/` for deeper detail.
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
- ## When to use
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
- Use this skill when:
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
- - The project contains `app/views/` + `app/controllers/`, `alloy.jmk`, or `config.json`
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
- Do NOT use for:
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 best practices and recommendations
1
+ # Practical Alloy conventions
2
2
 
3
- Recommendations for writing Alloy apps. This supplements the Titanium SDK [Best Practices and Recommendations](https://titaniumsdk.com/docs/build) guide and focuses on coding style and conventions.
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
- ## Titanium-to-Alloy Guidance
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
- ### Loading Libraries in Alloy
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
- If you need global functionality, require modules in all controllers or create a single global reference:
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
- **alloy.js**
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
- ### Performance Best Practices
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
- The same best practices from traditional Titanium development apply to Alloy. Alloy controllers can do what classic controllers can.
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
- Use compiler directives to reduce runtime work (see Conditional Code in Alloy Controllers).
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).