@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.
Files changed (120) hide show
  1. package/AGENTS-TEMPLATE.md +173 -0
  2. package/README.md +867 -0
  3. package/agents/ti-researcher.md +108 -0
  4. package/bin/titools.js +53 -0
  5. package/lib/commands/agents.js +126 -0
  6. package/lib/commands/install.js +188 -0
  7. package/lib/commands/uninstall.js +215 -0
  8. package/lib/commands/update.js +159 -0
  9. package/lib/config.js +119 -0
  10. package/lib/downloader.js +153 -0
  11. package/lib/installer.js +253 -0
  12. package/lib/platform.js +108 -0
  13. package/lib/symlink.js +142 -0
  14. package/lib/utils.js +270 -0
  15. package/package.json +67 -0
  16. package/skills/alloy-expert/SKILL.md +247 -0
  17. package/skills/alloy-expert/assets/ControllerAutoCleanup.js +182 -0
  18. package/skills/alloy-expert/references/alloy-structure.md +381 -0
  19. package/skills/alloy-expert/references/anti-patterns.md +133 -0
  20. package/skills/alloy-expert/references/code-conventions.md +469 -0
  21. package/skills/alloy-expert/references/contracts.md +280 -0
  22. package/skills/alloy-expert/references/controller-patterns.md +520 -0
  23. package/skills/alloy-expert/references/error-handling.md +484 -0
  24. package/skills/alloy-expert/references/examples.md +735 -0
  25. package/skills/alloy-expert/references/migration-patterns.md +298 -0
  26. package/skills/alloy-expert/references/patterns.md +448 -0
  27. package/skills/alloy-expert/references/performance-patterns.md +855 -0
  28. package/skills/alloy-expert/references/security-patterns.md +847 -0
  29. package/skills/alloy-expert/references/state-management.md +779 -0
  30. package/skills/alloy-expert/references/testing.md +872 -0
  31. package/skills/alloy-guides/SKILL.md +214 -0
  32. package/skills/alloy-guides/references/CLI_TASKS.md +243 -0
  33. package/skills/alloy-guides/references/CONCEPTS.md +191 -0
  34. package/skills/alloy-guides/references/CONTROLLERS.md +298 -0
  35. package/skills/alloy-guides/references/MODELS.md +1028 -0
  36. package/skills/alloy-guides/references/PURGETSS.md +56 -0
  37. package/skills/alloy-guides/references/VIEWS_DYNAMIC.md +242 -0
  38. package/skills/alloy-guides/references/VIEWS_STYLES.md +388 -0
  39. package/skills/alloy-guides/references/VIEWS_WITHOUT_CONTROLLERS.md +109 -0
  40. package/skills/alloy-guides/references/VIEWS_XML.md +558 -0
  41. package/skills/alloy-guides/references/WIDGETS.md +176 -0
  42. package/skills/alloy-howtos/SKILL.md +203 -0
  43. package/skills/alloy-howtos/references/best_practices.md +138 -0
  44. package/skills/alloy-howtos/references/cli_reference.md +253 -0
  45. package/skills/alloy-howtos/references/config_files.md +87 -0
  46. package/skills/alloy-howtos/references/custom_tags.md +147 -0
  47. package/skills/alloy-howtos/references/debugging_troubleshooting.md +101 -0
  48. package/skills/alloy-howtos/references/samples.md +167 -0
  49. package/skills/purgetss/SKILL.md +442 -0
  50. package/skills/purgetss/assets/purgetss.config.cjs +17 -0
  51. package/skills/purgetss/references/EXAMPLES.md +247 -0
  52. package/skills/purgetss/references/animation-system.md +1294 -0
  53. package/skills/purgetss/references/apply-directive.md +375 -0
  54. package/skills/purgetss/references/arbitrary-values.md +612 -0
  55. package/skills/purgetss/references/class-index.md +1350 -0
  56. package/skills/purgetss/references/cli-commands.md +948 -0
  57. package/skills/purgetss/references/configurable-properties.md +654 -0
  58. package/skills/purgetss/references/custom-rules.md +161 -0
  59. package/skills/purgetss/references/customization-deep-dive.md +722 -0
  60. package/skills/purgetss/references/dynamic-component-creation.md +489 -0
  61. package/skills/purgetss/references/grid-layout.md +455 -0
  62. package/skills/purgetss/references/icon-fonts.md +609 -0
  63. package/skills/purgetss/references/installation-setup.md +366 -0
  64. package/skills/purgetss/references/opacity-modifier.md +291 -0
  65. package/skills/purgetss/references/platform-modifiers.md +479 -0
  66. package/skills/purgetss/references/smart-mappings.md +42 -0
  67. package/skills/purgetss/references/titanium-resets.md +359 -0
  68. package/skills/purgetss/references/ui-ux-design.md +1526 -0
  69. package/skills/ti-guides/SKILL.md +94 -0
  70. package/skills/ti-guides/references/advanced-data-and-images.md +19 -0
  71. package/skills/ti-guides/references/alloy-cli-advanced.md +84 -0
  72. package/skills/ti-guides/references/alloy-data-mastery.md +29 -0
  73. package/skills/ti-guides/references/alloy-widgets-and-themes.md +19 -0
  74. package/skills/ti-guides/references/android-manifest.md +97 -0
  75. package/skills/ti-guides/references/app-distribution.md +258 -0
  76. package/skills/ti-guides/references/application-frameworks.md +377 -0
  77. package/skills/ti-guides/references/cli-reference.md +402 -0
  78. package/skills/ti-guides/references/coding-best-practices.md +102 -0
  79. package/skills/ti-guides/references/commonjs-advanced.md +134 -0
  80. package/skills/ti-guides/references/hello-world.md +100 -0
  81. package/skills/ti-guides/references/hyperloop-native-access.md +62 -0
  82. package/skills/ti-guides/references/javascript-primer.md +411 -0
  83. package/skills/ti-guides/references/reserved-words.md +36 -0
  84. package/skills/ti-guides/references/resources.md +183 -0
  85. package/skills/ti-guides/references/style-and-conventions.md +48 -0
  86. package/skills/ti-guides/references/tiapp-config.md +609 -0
  87. package/skills/ti-howtos/SKILL.md +174 -0
  88. package/skills/ti-howtos/references/android-platform-deep-dives.md +658 -0
  89. package/skills/ti-howtos/references/automation-fastlane-appium.md +95 -0
  90. package/skills/ti-howtos/references/buffer-codec-streams.md +140 -0
  91. package/skills/ti-howtos/references/cross-platform-development.md +348 -0
  92. package/skills/ti-howtos/references/debugging-profiling.md +543 -0
  93. package/skills/ti-howtos/references/extending-titanium.md +723 -0
  94. package/skills/ti-howtos/references/google-maps-v2.md +169 -0
  95. package/skills/ti-howtos/references/ios-map-kit.md +143 -0
  96. package/skills/ti-howtos/references/ios-platform-deep-dives.md +783 -0
  97. package/skills/ti-howtos/references/local-data-sources.md +301 -0
  98. package/skills/ti-howtos/references/location-and-maps.md +252 -0
  99. package/skills/ti-howtos/references/media-apis.md +210 -0
  100. package/skills/ti-howtos/references/notification-services.md +599 -0
  101. package/skills/ti-howtos/references/remote-data-sources.md +349 -0
  102. package/skills/ti-howtos/references/tutorials.md +502 -0
  103. package/skills/ti-howtos/references/using-modules.md +237 -0
  104. package/skills/ti-howtos/references/web-content-integration.md +307 -0
  105. package/skills/ti-howtos/references/webpack-build-pipeline.md +78 -0
  106. package/skills/ti-ui/SKILL.md +179 -0
  107. package/skills/ti-ui/references/accessibility-deep-dive.md +242 -0
  108. package/skills/ti-ui/references/animation-and-matrices.md +599 -0
  109. package/skills/ti-ui/references/application-structures.md +655 -0
  110. package/skills/ti-ui/references/custom-fonts-styling.md +579 -0
  111. package/skills/ti-ui/references/event-handling.md +393 -0
  112. package/skills/ti-ui/references/gestures.md +473 -0
  113. package/skills/ti-ui/references/icons-and-splash-screens.md +409 -0
  114. package/skills/ti-ui/references/layouts-and-positioning.md +462 -0
  115. package/skills/ti-ui/references/listviews-and-performance.md +619 -0
  116. package/skills/ti-ui/references/orientation.md +362 -0
  117. package/skills/ti-ui/references/platform-ui-android.md +635 -0
  118. package/skills/ti-ui/references/platform-ui-ios.md +469 -0
  119. package/skills/ti-ui/references/scrolling-views.md +252 -0
  120. package/skills/ti-ui/references/tableviews.md +568 -0
@@ -0,0 +1,56 @@
1
+ # PurgeTSS
2
+
3
+ ## Table of Contents
4
+
5
+ - [PurgeTSS](#purgetss)
6
+ - [Table of Contents](#table-of-contents)
7
+ - [Overview](#overview)
8
+ - [Command-Line Interface Usage](#command-line-interface-usage)
9
+ - [Key Features](#key-features)
10
+ - [Documentation](#documentation)
11
+ - [Topics](#topics)
12
+
13
+ ## Overview
14
+
15
+ **PurgeTSS** is a powerful Alloy addon designed to enhance the process of developing visually captivating mobile applications for Titanium.
16
+
17
+ It offers a range of tools such as customizable utility classes, support for icon fonts, a user-friendly Animation module, a straightforward grid system, and the added convenience of the `shades` command for crafting personalized colors.
18
+
19
+ ## Command-Line Interface Usage
20
+
21
+ ```bash
22
+ alloy purgetss
23
+ ```
24
+
25
+ ## Key Features
26
+
27
+ - **21,000+ Utility Classes**: Provides more than Tailwind-like utility classes ready to use in your projects
28
+ - **Clean app.tss**: Creates a clean `app.tss` file with only the classes used in your project by parsing all your XML files
29
+ - **Customization**: Customize default classes via config file or create just-in-time classes with arbitrary values
30
+ - **Icon Fonts**: Easily use icon fonts from Font Awesome, Material Icons, Material Symbols, and Framework7-Icons
31
+ - **fonts.tss Generation**: Generates a fonts.tss file with all class definitions and fontFamily selectors
32
+ - **Shades Command**: Generate custom color shades from hex colors
33
+ - **Animation Module**: Apply basic 2D Matrix animations or transform to elements
34
+ - **Grid System**: Simple two-dimensional grid system to align and distribute elements
35
+
36
+ ## Documentation
37
+
38
+ For complete documentation, visit the official PurgeTSS site at [purgetss.com](https://purgetss.com).
39
+
40
+ ### Topics
41
+
42
+ - [Installation](https://purgetss.com/docs/installation)
43
+ - [Commands](https://purgetss.com/docs/commands)
44
+ - [Customization](https://purgetss.com/docs/customization)
45
+ - [Config file](https://purgetss.com/docs/customization/the-config-file)
46
+ - [Custom rules](https://purgetss.com/docs/customization/custom-rules)
47
+ - [Apply directive](https://purgetss.com/docs/customization/the-apply-directive)
48
+ - [Opacity modifier](https://purgetss.com/docs/customization/the-opacity-modifier)
49
+ - [Arbitrary values in XMLs](https://purgetss.com/docs/customization/arbitrary-values)
50
+ - [Platform and Device modifiers](https://purgetss.com/docs/customization/platform-and-device-modifiers)
51
+ - [Icon Fonts Libraries](https://purgetss.com/docs/customization/icon-fonts-libraries)
52
+ - [Animation Module](https://purgetss.com/docs/animation-module)
53
+ - [Introduction](https://purgetss.com/docs/animation-module/introduction)
54
+ - [Available utilities](https://purgetss.com/docs/animation-module/available-utilities)
55
+ - [Complex UI elements](https://purgetss.com/docs/animation-module/complex-ui-elements)
56
+ - [Grid System](https://purgetss.com/docs/grid-system)
@@ -0,0 +1,242 @@
1
+ # Dynamic Styles
2
+
3
+ ## Table of Contents
4
+
5
+ - [Dynamic Styles](#dynamic-styles)
6
+ - [Table of Contents](#table-of-contents)
7
+ - [Introduction](#introduction)
8
+ - [Define Class Styles](#define-class-styles)
9
+ - [Generate a Dynamic Style](#generate-a-dynamic-style)
10
+ - [Equivalent Code Outside Controller](#equivalent-code-outside-controller)
11
+ - [Modify TSS Classes](#modify-tss-classes)
12
+ - [Autostyle](#autostyle)
13
+ - [Why Autostyle is Needed](#why-autostyle-is-needed)
14
+
15
+ ## Introduction
16
+
17
+ Since Alloy 1.2.0, Alloy supports changing styles dynamically or during runtime. There are two methods to support dynamic styling in Alloy. You can either generate a dynamic style dictionary that can be passed to `applyProperties` or a create method, or modify TSS class styles to an existing component on the fly.
18
+
19
+ ## Define Class Styles
20
+
21
+ Before using either method, you need to create class styles in the TSS files, either in the global style file or in the individual TSS files.
22
+
23
+ **app/styles/app.tss**
24
+
25
+ ```javascript
26
+ ".bluetext" : {
27
+ color: 'blue'
28
+ },
29
+ ".orangetext" : {
30
+ color: 'orange'
31
+ },
32
+ ".shadow" : {
33
+ shadowColor: '#88f',
34
+ shadowOffset: {x:1,y:3}
35
+ },
36
+ ".ldpi" : {
37
+ font: {fontSize: '9dp', fontWeight: 'normal' }
38
+ },
39
+ ".mdpi" : {
40
+ font: {fontSize: '12dp', fontWeight: 'normal' }
41
+ },
42
+ ".hdpi" : {
43
+ font: {fontSize: '18dp', fontWeight: 'bold' }
44
+ },
45
+ ".xhdpi" : {
46
+ font: {fontSize: '24dp', fontWeight: 'bold' }
47
+ },
48
+ "Label" : {
49
+ font: {fontSize: '14dp', fontWeight: 'normal' },
50
+ shadow : {},
51
+ color : 'black'
52
+ },
53
+ ".rude_button" : {
54
+ title: 'Go Away'
55
+ },
56
+ ".nice_button" : {
57
+ title: 'Please Close'
58
+ },
59
+ "Button" : {
60
+ width: Ti.UI.SIZE,
61
+ height: Ti.UI.SIZE
62
+ }
63
+ ".tiny_win" : {
64
+ height: '150dp',
65
+ width: '200dp',
66
+ backgroundColor: 'blue'
67
+ },
68
+ ".big_win" : {
69
+ height: '300dp',
70
+ width: '400dp',
71
+ backgroundColor: 'red'
72
+ }
73
+ ```
74
+
75
+ The previous style sheet defines various class and markup element styles for labels, buttons and windows. Alloy assigns a priority for each class, based on its order in the TSS file. Styles listed first receive a lower priority than ones listed afterwards. For example, if both the ldpi and hdpi classes are assigned to a label, since hdpi is after ldpi, the label text is 24 dp not 9 dp.
76
+
77
+ ## Generate a Dynamic Style
78
+
79
+ To generate a dynamic style, use the controller's `createStyle` method by passing it a dictionary with TSS classes. This method returns a dictionary that can be passed to the view object's `applyProperties` method or a create view object method.
80
+
81
+ You can use the controller's `UI.create` method to create a view component that is dynamically styled.
82
+
83
+ **app/views/dialog.xml**
84
+
85
+ ```xml
86
+ <Alloy>
87
+ <Window id="win">
88
+ <Button id="button" onClick="doClick" />
89
+ </Window>
90
+ </Alloy>
91
+ ```
92
+
93
+ **app/controllers/dialog.js**
94
+
95
+ ```javascript
96
+ function doClick(e) {
97
+ $.win.close();
98
+ }
99
+
100
+ const args = arguments[0] || {};
101
+ if (args.button) {
102
+ const style = $.createStyle({
103
+ classes: args.button,
104
+ apiName: 'Button',
105
+ color: 'blue'
106
+ });
107
+ $.button.applyProperties(style);
108
+ }
109
+ if (args.win) {
110
+ const style = $.createStyle({
111
+ classes: args.win,
112
+ apiName: 'Window',
113
+ backgroundColor: 'white'
114
+ });
115
+ $.win.applyProperties(style);
116
+ }
117
+ if (args.label) {
118
+ args.label.top = 10
119
+ const label = $.UI.create("Label", args.label);
120
+ $.win.add(label);
121
+ }
122
+ ```
123
+
124
+ **app/controllers/index.js**
125
+
126
+ ```javascript
127
+ const args = {};
128
+ args.button = ['rude_button'];
129
+ args.win = ['tiny_win'];
130
+ args.label = {
131
+ classes: ['hdpi', 'shadow'],
132
+ text: 'No zombies allowed!'
133
+ };
134
+ Alloy.createController('dialog', args).getView().open();
135
+ ```
136
+
137
+ ### Equivalent Code Outside Controller
138
+
139
+ In this example, the dialog controller code is not necessary. The dialog can be generated and styled outside the view-controller. The following code using only the previous XML markup is equivalent to what the previous two controllers are doing:
140
+
141
+ **app/controllers/index.js**
142
+
143
+ ```javascript
144
+ const dialog = Alloy.createController('dialog');
145
+ let style = dialog.createStyle({
146
+ classes: 'rude_button',
147
+ apiName: 'Button',
148
+ color: 'blue'
149
+ });
150
+ dialog.button.applyProperties(style);
151
+ style = dialog.createStyle({
152
+ classes: 'tiny_win',
153
+ apiName: 'Window',
154
+ backgroundColor: 'white'
155
+ });
156
+ dialog.win.applyProperties(style);
157
+ style = {
158
+ top: 10,
159
+ text: 'No zombies allowed!',
160
+ classes: 'hdpi shadow'
161
+ }
162
+ const label = dialog.UI.create('Label', style);
163
+ dialog.win.add(label);
164
+ dialog.getView().open();
165
+ ```
166
+
167
+ Note that code outside of the dialog view-controller is using the instance variable name `dialog` to make the API calls with the `createStyle` and `UI.create` methods rather than the `$` variable, which is used when making controller API calls inside its own view-controller.
168
+
169
+ ## Modify TSS Classes
170
+
171
+ To modify the TSS classes of an object that has already been created, use the controller's `addClass`, `removeClass` and `resetClass` methods, which adds, removes or resets the TSS classes of a view object, respectively.
172
+
173
+ Pass a reference to the view object as the first parameter, then pass the classes to add or remove as an array or space-separated string as the second parameter. You can optionally specify inline properties as an optional third parameter.
174
+
175
+ **app/controllers/index.js**
176
+
177
+ ```javascript
178
+ const dialog = Alloy.createController('dialog');
179
+ dialog.addClass(dialog.win, 'tiny_win', {backgroundColor:'white'});
180
+ dialog.addClass(dialog.button, 'rude_button', {color: 'blue'});
181
+ const style = {
182
+ top: 10,
183
+ text: 'No zombies allowed!',
184
+ classes: 'hdpi shadow'
185
+ }
186
+ const label = dialog.UI.create('Label', style);
187
+ dialog.getView().open();
188
+ ```
189
+
190
+ Later on, you can change the classes:
191
+
192
+ ```
193
+ dialog.resetClass(dialog.button, 'nice_button orangetext hdpi');
194
+ ```
195
+
196
+ ## Autostyle
197
+
198
+ A view component with autostyle enabled has its TSS classes stored with the view object. Autostyle is necessary to take full advantage of the `addClass()`, `removeClass()` and `resetClass()` classes to properly update the view as classes are removed and added. There is a small performance overhead for using this feature and should only be enabled on components that use this feature. By default, autostyle is disabled.
199
+
200
+ To enable autostyle, set the `autoStyle` attribute to `true` either in the XML markup or the `config.json` file.
201
+
202
+ * To enable autostyle for an individual component, set the `autoStyle` attribute to true on the XML tag: `<View autoStyle="true">`.
203
+ * To enable autostyle for components in a controller, set the `autoStyle` attribute to true on the root `<Alloy/>` tag: `<Alloy autoStyle="true">`.
204
+ * To enable autostyle for all controllers in an Alloy project, set the `autoStyle` field to true in the `config.json` file.
205
+
206
+ **app/config.json**
207
+
208
+ ```json
209
+ {
210
+ "autoStyle": true
211
+ }
212
+ ```
213
+
214
+ ### Why Autostyle is Needed
215
+
216
+ Consider the following example without autostyle:
217
+
218
+ **app/styles/index.tss**
219
+
220
+ ```javascript
221
+ ".coloronly" : {
222
+ color: 'red'
223
+ },
224
+ ".colorsize" : {
225
+ color: 'blue',
226
+ font: {fontSize: '24dp'}
227
+ },
228
+ "Label" : {
229
+ color: 'black',
230
+ font: {fontSize: '12dp'}
231
+ }
232
+ ```
233
+
234
+ **app/controllers/index.js**
235
+
236
+ ```javascript
237
+ $.addClass($.label, "coloronly colorsize"); // --> appears blue and 24dp
238
+ $.removeClass($.label, "colorsize"); // --> appears red and 24dp (font size not updated!)
239
+ $.removeClass($.label, "coloronly"); // --> appears red and 24dp (not black!)
240
+ ```
241
+
242
+ With autostyle enabled, the styles update as expected when classes are added or removed.
@@ -0,0 +1,388 @@
1
+ # Alloy Styles and Themes
2
+
3
+ ## Table of Contents
4
+
5
+ - [Alloy Styles and Themes](#alloy-styles-and-themes)
6
+ - [Table of Contents](#table-of-contents)
7
+ - [Titanium Style Sheets](#titanium-style-sheets)
8
+ - [Global Styles](#global-styles)
9
+ - [Platform-Specific Styles](#platform-specific-styles)
10
+ - [Custom Query Styles](#custom-query-styles)
11
+ - [Example Using Custom Properties](#example-using-custom-properties)
12
+ - [Example Using Conditional Statements](#example-using-conditional-statements)
13
+ - [Themes](#themes)
14
+ - [Style Priorities](#style-priorities)
15
+
16
+ ## Titanium Style Sheets
17
+
18
+ The Titanium Style Sheets (TSS) file uses a JSON-like syntax to define the attributes of elements in the XML files. All TSS attributes are the properties of the Titanium object.
19
+
20
+ Styles are defined at three different levels: markup element, class attribute and the id attribute. When mixed together, the id attribute overrides both the class attribute and markup element, and the class attribute overrides the markup element.
21
+
22
+ In the TSS file, define attributes as key-value pairs, where the key is the name of the markup element, the class name prefixed with a period (`.`), or the id name prefixed with a hash tag (`#`) and the value is a dictionary of attributes.
23
+
24
+ You can use the following values and operators in your TSS file:
25
+
26
+ * JSON values: Strings, Numbers, Objects, Array, Booleans and null
27
+ * `undefined` to unset a property (since Alloy 1.4.0)
28
+ * Titanium SDK constants: `Ti.UI.SIZE`
29
+ * Localization functions: `Ti.Locale.getString()` and `L()`
30
+ * Variables from `Alloy.CFG` or `Alloy.Globals`
31
+ * Bitwise operators: `>>`, `<<`, `>>>`, `&`, `|`, `^` (since Alloy 1.3.0)
32
+ * Single (`//comment`) and multiline comments (`/* comment */`)
33
+
34
+ ::: warning ⚠️ Warning
35
+ Alloy does not support the CSS concept of child or descendent selectors.
36
+ :::
37
+
38
+ **app/styles/index.tss**
39
+
40
+ ```javascript
41
+ // Applied to any element with class "container"
42
+ ".container": {
43
+ backgroundColor:"white"
44
+ },
45
+ // Applied to all Labels
46
+ "Label": {
47
+ width: Ti.UI.SIZE,
48
+ height: Ti.UI.SIZE,
49
+ color: "#000",
50
+ transform: Alloy.Globals.rotateLeft
51
+ },
52
+ // Applied only to element with id="label"
53
+ "#label": {
54
+ color: "#999"
55
+ }
56
+ ```
57
+
58
+ For the Label's `transform` property in the example above, the TSS file is using a function assigned to the `Alloy.Globals` namespace defined in the initializer file:
59
+
60
+ **app/alloy.js**
61
+
62
+ ```javascript
63
+ Alloy.Globals.rotateLeft = Ti.UI.createMatrix2D().rotate(-90);
64
+ ```
65
+
66
+ **app/views/index.xml**
67
+
68
+ ```xml
69
+ <Alloy>
70
+ <Window class="container">
71
+ <Label id="label" onClick="doClick">Hello, World</Label>
72
+ </Window>
73
+ </Alloy>
74
+ ```
75
+
76
+ ## Global Styles
77
+
78
+ You can create a global style file, called `app.tss`, which applies all styles defined inside it to all views, but does not override the non-global styles or property attributes in the markup.
79
+
80
+ **styles/app.tss**
81
+
82
+ ```javascript
83
+ "Window":{
84
+ backgroundColor: 'white',
85
+ layout: 'vertical'
86
+ }
87
+ "Label":{
88
+ color: 'gray',
89
+ textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT,
90
+ backgroundColor: 'transparent',
91
+ font: {
92
+ fontFamily:'Helvetica',
93
+ fontSize: '12dp',
94
+ fontStyle: 'normal',
95
+ fontWeight: 'normal'
96
+ }
97
+ }
98
+ ```
99
+
100
+ **styles/index.tss**
101
+
102
+ ```javascript
103
+ "Window":{
104
+ backgroundColor: 'blue'
105
+ }
106
+ "Label":{
107
+ top: 20,
108
+ left: '25dp',
109
+ right: '25dp'
110
+ }
111
+ "#subtitle":{
112
+ width: Ti.UI.FILL,
113
+ textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
114
+ font: {
115
+ fontSize: '16dp',
116
+ fontWeight: 'bold'
117
+ }
118
+ }
119
+ ```
120
+
121
+ **views/index.xml**
122
+
123
+ ```xml
124
+ <Alloy>
125
+ <Window titleid="story_title" modal="true" exitOnClose="true">
126
+ <Label id="subtitle" color="orange" textid="story_subtitle" />
127
+ <Label top="25" color="white" textid="story_content" />
128
+ </Window>
129
+ </Alloy>
130
+ ```
131
+
132
+ Style priority (lowest to highest): Global Style File → Global Style File in Theme → Platform-Specific Global → View-Controller Style File → View-Controller Style in Theme → Platform-Specific View-Controller → XML Markup → Platform-Specific XML Markup.
133
+
134
+ ## Platform-Specific Styles
135
+
136
+ :::danger CRITICAL: Platform-Specific Properties Require Modifiers
137
+ **Using `Ti.UI.iOS.*` or `Ti.UI.Android.*` properties in TSS WITHOUT platform modifiers will:**
138
+
139
+ 1. **Add iOS code to Android builds** → compilation failures
140
+ 2. **Add Android code to iOS builds** → compilation failures
141
+
142
+ **Example of the damage:**
143
+ ```tss
144
+ // ❌ WRONG - Adds Ti.UI.iOS to Android project
145
+ "#mainWindow": {
146
+ statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT // FAILS on Android!
147
+ }
148
+ ```
149
+
150
+ **CORRECT - Always use platform modifiers:**
151
+ ```tss
152
+ // ✅ CORRECT - Only adds to iOS
153
+ "#mainWindow[platform=ios]": {
154
+ statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT
155
+ }
156
+
157
+ // ✅ CORRECT - Only adds to Android
158
+ "#mainWindow[platform=android]": {
159
+ actionBar: {
160
+ displayHomeAsUp: true
161
+ }
162
+ }
163
+ ```
164
+
165
+ **Common platform-specific properties that REQUIRE `[platform=...]` modifiers:**
166
+ - iOS: `statusBarStyle`, `modalStyle`, `modalTransitionStyle`, any `Ti.UI.iOS.*`
167
+ - Android: `actionBar` config, any `Ti.Android.*` constant
168
+ :::
169
+
170
+ As with views, separate styles may be defined based on the platform and device size.
171
+
172
+ **To specify platform or device size conditionals:**
173
+
174
+ 1. Place a set of square brackets (`[]`) directly after the name of the markup element, class name or id name in the TSS file.
175
+ 2. Inside the brackets:
176
+ * `platform` attribute: assign a platform (`android`, `ios`). Comma separate to OR values. Prepend with `!` to negate.
177
+ * `formFactor` attribute: assign a device size (`handheld` or `tablet`).
178
+
179
+ ```
180
+ // Default label
181
+ "Label": {
182
+ backgroundColor: "#000",
183
+ text: 'Another platform'
184
+ },
185
+ // iPhone
186
+ "Label[platform=ios formFactor=handheld]": {
187
+ backgroundColor: "#f00",
188
+ text: 'iPhone'
189
+ },
190
+ // iPad
191
+ "Label[platform=ios formFactor=tablet]": {
192
+ backgroundColor: "#0f0",
193
+ text: 'iPad'
194
+ },
195
+ // Android
196
+ "Label[platform=android]": {
197
+ backgroundColor: "#00f",
198
+ text: 'Android'
199
+ }
200
+ ```
201
+
202
+ Alternatively, create subfolders named as the platform in the `styles` directory.
203
+
204
+ ## Custom Query Styles
205
+
206
+ You can create custom queries to select which styles to apply in both the TSS and XML files.
207
+
208
+ **To use a custom query:**
209
+
210
+ 1. Define a conditional statement that returns a boolean value, and assign it to a property in `Alloy.Globals` or a local function.
211
+ 2. Assign the `if` attribute to an element in the XML or TSS file.
212
+
213
+ ### Example Using Custom Properties
214
+
215
+ The application can pass custom Boolean properties to the `Alloy.createController()` method. These properties can be accessed by both the XML and TSS files. When calling the `createController()` method, pass the custom Boolean properties in the second argument of the method.
216
+
217
+ The controller below defines two functions that create and open an instance of the `win2` controller, but each function passes a different property to the controller.
218
+
219
+ **apps/controllers/index.js**
220
+
221
+ ```javascript
222
+ function openBar (e) {
223
+ Alloy.createController('win2', {'fooBar': true}).getView().open();
224
+ };
225
+
226
+ function openBaz (e) {
227
+ Alloy.createController('win2', {'fooBaz': true}).getView().open();
228
+ };
229
+ ```
230
+
231
+ In the TSS file, add the conditional block and assign the `if` attribute to the property passed to the `createController()` method. Prefix the property name with the `$.args` namespace. Based on the property passed to the method, the application displays a different styled label.
232
+
233
+ **app/styles/win2.tss**
234
+
235
+ ```javascript
236
+ "#label[if=$.args.fooBar]": {
237
+ 'text' : 'Foobar',
238
+ 'color' : 'blue'
239
+ }
240
+
241
+ "#label[if=$.args.fooBaz]": {
242
+ 'text' : 'Foobaz',
243
+ 'color' : 'red'
244
+ }
245
+ ```
246
+
247
+ In the XML markup, add the `if` attribute to an element and assign it to the property passed to the `createController()` method. Prefix the property name with the `$.args` namespace. Based on the property passed to the method, the application displays a different label.
248
+
249
+ **app/views/win2.xml**
250
+
251
+ ```xml
252
+ <Alloy>
253
+ <Window>
254
+ <Label if="$.args.fooBar" color="blue">Foobar</Label>
255
+ <Label if="$.args.fooBaz" color="red">Foobaz</Label>
256
+ </Window>
257
+ </Alloy>
258
+ ```
259
+
260
+ ### Example Using Conditional Statements
261
+
262
+ In this example, the application defines conditional statements to determine the iPhone device the application is running on. This iPhone application displays a scrolling block of text with a title above it and a caption below it:
263
+
264
+ **app/views/index.xml**
265
+
266
+ ```xml
267
+ <Alloy>
268
+ <Window>
269
+ <Label id="title" textid="title"/>
270
+ <ScrollView>
271
+ <Label id="content" textid="content"/>
272
+ </ScrollView>
273
+ <Label id="info">TextViewer by BluthCo</Label>
274
+ </Window>
275
+ </Alloy>
276
+ ```
277
+
278
+ To take advantage of the various iPhone devices, we need to see if the device is running iOS 7 and above, and whether the iPhone is using the old regular or the latest tall form factor. We can define both of these query statements in the initializer file:
279
+
280
+ **app/alloy.js**
281
+
282
+ ```javascript
283
+ Alloy.Globals.isIos7Plus = (OS_IOS && parseInt(Ti.Platform.version.split(".")[0]) >= 7);
284
+ Alloy.Globals.iPhoneTall = (OS_IOS && Ti.Platform.osname == "iphone" && Ti.Platform.displayCaps.platformHeight == 568);
285
+ ```
286
+
287
+ In the style file, use these conditional statements to create styles for specific devices. For example, since iOS 7, you can take advantage of the built-in text styles instead of defining all the attributes for a Font object, and since the iPhone 5 (and later) is taller, you need to make the ScrollView longer.
288
+
289
+ **app/styles/index.tss**
290
+
291
+ ```javascript
292
+ // Default Styles
293
+ "#content": {
294
+ color: 'gray',
295
+ top: '25dp',
296
+ left: '10dp',
297
+ font: {
298
+ fontSize: '12dp'
299
+ }
300
+ },
301
+ "#info": {
302
+ color: 'gray',
303
+ bottom: '20dp',
304
+ font: {
305
+ fontSize: '9dp'
306
+ }
307
+ },
308
+ "#title": {
309
+ color: 'black',
310
+ top: '15dp',
311
+ font: {
312
+ fontSize: '14dp',
313
+ fontWeight: 'bold'
314
+ }
315
+ },
316
+ "Window": {
317
+ layout: 'vertical',
318
+ backgroundColor: 'white'
319
+ },
320
+ "ScrollView": {
321
+ height: '415dp'
322
+ },
323
+ // Query styles
324
+ "#info[if=Alloy.Globals.isIos7Plus]": {
325
+ font: { textStyle : Ti.UI.TEXT_STYLE_FOOTNOTE }
326
+ },
327
+ "#title[if=Alloy.Globals.isIos7Plus]": {
328
+ top: '25dp', // compensate for the status bar on iOS 7
329
+ font: { textStyle : Ti.UI.TEXT_STYLE_HEADLINE }
330
+ },
331
+ "#content[if=Alloy.Globals.isIos7Plus]": {
332
+ font: { textStyle : Ti.UI.TEXT_STYLE_CAPTION1 }
333
+ },
334
+ "ScrollView[if=Alloy.Globals.iPhoneTall]": {
335
+ height: '500dp'
336
+ }
337
+ ```
338
+
339
+ ## Themes
340
+
341
+ Themes provide a way to overwrite or modify files for a specific brand of your app.
342
+
343
+ To create a theme, create a folder called `themes` in your Alloy `app` directory. In the `themes` folder, create a folder for your theme.
344
+
345
+ | Folder or Filename | Merges or Overwrites |
346
+ | ------------------ | -------------------------------- |
347
+ | config.json | merges |
348
+ | i18n | merges folders and files |
349
+ | assets | merges folders, overwrites files |
350
+ | lib | merges folders, overwrites files |
351
+ | platform | merges folders, overwrites files |
352
+ | styles | merges folders and files |
353
+ | widgets/\*/assets | merges folders, overwrites files |
354
+ | widgets/\*/styles | merges folders and files |
355
+
356
+ To use a theme, add it to your `config.json`:
357
+
358
+ ```
359
+ {
360
+ "global": {
361
+ "theme":"mytheme"
362
+ },
363
+ "os:ios": {
364
+ "theme":"green"
365
+ },
366
+ "os:android": {
367
+ "theme":"blue"
368
+ },
369
+ "dependencies": {}
370
+ }
371
+ ```
372
+
373
+ ## Style Priorities
374
+
375
+ When mixing themes, the global style file, view style files and defining styles inline in the XML markup, Alloy applies the styles in the following order from lowest to highest priority:
376
+
377
+ | Style Defined in... | Example |
378
+ | ------------------------------------------------------------------- | ------------------------------------------------------------- |
379
+ | Global Style File | `styles/app.tss` |
380
+ | Global Style File in a Theme | `themes/<theme_name>/styles/app.tss` |
381
+ | Global Style File with Platform-Specific Styles | `styles/<platform>/app.tss` |
382
+ | Global Style File in a Theme with Platform-Specific Styles | `themes/<theme_name>/styles/<platform>/app.tss` |
383
+ | View-Controller Style File | `styles/<view_controller>.tss` |
384
+ | View-Controller Style File in a Theme | `themes/<theme_name>/styles/<view_controller>.tss` |
385
+ | View-Controller Style File with Platform-Specific Styles | `styles/<platform>/<view_controller>.tss` |
386
+ | View-Controller Style File in a Theme with Platform-Specific Styles | `themes/<theme_name>/styles/<platform>/<view_controller>.tss` |
387
+ | XML Markup | `views/<view_controller>.xml` |
388
+ | XML Markup with Platform-Specific Styles | `views/<platform>/<view_controller>.xml` |