@maccesar/titools 2.10.0 → 3.1.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 (99) hide show
  1. package/AGENTS-VERCEL-RESEARCH.md +23 -12
  2. package/README.md +81 -182
  3. package/agents/ti-pro.md +8 -14
  4. package/lib/cleanup.js +13 -0
  5. package/lib/commands/skills.js +2 -1
  6. package/lib/commands/update.js +4 -1
  7. package/lib/config.js +9 -11
  8. package/lib/platform.js +1 -1
  9. package/package.json +2 -3
  10. package/skills/purgetss/SKILL.md +12 -0
  11. package/skills/purgetss/references/animation-advanced.md +0 -9
  12. package/skills/purgetss/references/app-branding.md +20 -0
  13. package/skills/purgetss/references/appearance-module.md +85 -27
  14. package/skills/purgetss/references/apply-directive.md +60 -0
  15. package/skills/purgetss/references/arbitrary-values.md +41 -0
  16. package/skills/purgetss/references/cli-commands.md +52 -17
  17. package/skills/purgetss/references/custom-rules.md +36 -19
  18. package/skills/purgetss/references/customization-deep-dive.md +37 -15
  19. package/skills/purgetss/references/grid-layout.md +45 -26
  20. package/skills/purgetss/references/icon-fonts.md +27 -25
  21. package/skills/purgetss/references/installation-setup.md +28 -2
  22. package/skills/purgetss/references/ios-large-titles.md +31 -15
  23. package/skills/purgetss/references/multi-density-images.md +57 -0
  24. package/skills/purgetss/references/opacity-modifier.md +11 -2
  25. package/skills/purgetss/references/semantic-colors.md +44 -1
  26. package/skills/purgetss/references/tikit-components.md +1 -3
  27. package/skills/alloy-guides/SKILL.md +0 -190
  28. package/skills/alloy-guides/references/CLI_TASKS.md +0 -233
  29. package/skills/alloy-guides/references/CONCEPTS.md +0 -171
  30. package/skills/alloy-guides/references/CONTROLLERS.md +0 -279
  31. package/skills/alloy-guides/references/MODELS.md +0 -1214
  32. package/skills/alloy-guides/references/PURGETSS.md +0 -46
  33. package/skills/alloy-guides/references/VIEWS_DYNAMIC.md +0 -235
  34. package/skills/alloy-guides/references/VIEWS_STYLES.md +0 -375
  35. package/skills/alloy-guides/references/VIEWS_WITHOUT_CONTROLLERS.md +0 -102
  36. package/skills/alloy-guides/references/VIEWS_XML.md +0 -581
  37. package/skills/alloy-guides/references/WIDGETS.md +0 -160
  38. package/skills/alloy-howtos/SKILL.md +0 -181
  39. package/skills/alloy-howtos/references/best_practices.md +0 -121
  40. package/skills/alloy-howtos/references/cli_reference.md +0 -230
  41. package/skills/alloy-howtos/references/config_files.md +0 -158
  42. package/skills/alloy-howtos/references/custom_tags.md +0 -148
  43. package/skills/alloy-howtos/references/debugging_troubleshooting.md +0 -78
  44. package/skills/alloy-howtos/references/samples.md +0 -156
  45. package/skills/ti-api/SKILL.md +0 -109
  46. package/skills/ti-api/references/api-android.md +0 -675
  47. package/skills/ti-api/references/api-app-platform.md +0 -636
  48. package/skills/ti-api/references/api-core.md +0 -764
  49. package/skills/ti-api/references/api-data-network.md +0 -641
  50. package/skills/ti-api/references/api-media.md +0 -655
  51. package/skills/ti-api/references/api-modules-ble-bluetooth.md +0 -657
  52. package/skills/ti-api/references/api-modules-coremotion-urlsession.md +0 -411
  53. package/skills/ti-api/references/api-modules-map.md +0 -632
  54. package/skills/ti-api/references/api-modules-nfc.md +0 -725
  55. package/skills/ti-api/references/api-modules-social-misc.md +0 -526
  56. package/skills/ti-api/references/api-services.md +0 -700
  57. package/skills/ti-api/references/api-ui-android.md +0 -499
  58. package/skills/ti-api/references/api-ui-extras.md +0 -702
  59. package/skills/ti-api/references/api-ui-ios-animator.md +0 -378
  60. package/skills/ti-api/references/api-ui-ios.md +0 -756
  61. package/skills/ti-api/references/api-ui-lists.md +0 -581
  62. package/skills/ti-api/references/api-ui-text-input.md +0 -607
  63. package/skills/ti-api/references/api-ui-views.md +0 -572
  64. package/skills/ti-api/references/api-ui-windows-navigation.md +0 -676
  65. package/skills/ti-api/references/api-xml-global.md +0 -743
  66. package/skills/ti-guides/SKILL.md +0 -75
  67. package/skills/ti-guides/references/advanced-data-and-images.md +0 -155
  68. package/skills/ti-guides/references/android-manifest.md +0 -97
  69. package/skills/ti-guides/references/app-distribution.md +0 -373
  70. package/skills/ti-guides/references/application-frameworks.md +0 -366
  71. package/skills/ti-guides/references/cli-reference.md +0 -700
  72. package/skills/ti-guides/references/coding-best-practices.md +0 -150
  73. package/skills/ti-guides/references/commonjs-advanced.md +0 -279
  74. package/skills/ti-guides/references/hello-world.md +0 -99
  75. package/skills/ti-guides/references/hyperloop-native-access.md +0 -458
  76. package/skills/ti-guides/references/javascript-primer.md +0 -402
  77. package/skills/ti-guides/references/reserved-words.md +0 -36
  78. package/skills/ti-guides/references/resources.md +0 -172
  79. package/skills/ti-guides/references/style-and-conventions.md +0 -104
  80. package/skills/ti-guides/references/tiapp-config.md +0 -655
  81. package/skills/ti-howtos/SKILL.md +0 -143
  82. package/skills/ti-howtos/references/android-platform-deep-dives.md +0 -609
  83. package/skills/ti-howtos/references/automation-fastlane-appium.md +0 -96
  84. package/skills/ti-howtos/references/buffer-codec-streams.md +0 -162
  85. package/skills/ti-howtos/references/cross-platform-development.md +0 -358
  86. package/skills/ti-howtos/references/debugging-profiling.md +0 -473
  87. package/skills/ti-howtos/references/extending-titanium.md +0 -684
  88. package/skills/ti-howtos/references/google-maps-v2.md +0 -172
  89. package/skills/ti-howtos/references/ios-map-kit.md +0 -149
  90. package/skills/ti-howtos/references/ios-platform-deep-dives.md +0 -595
  91. package/skills/ti-howtos/references/local-data-sources.md +0 -310
  92. package/skills/ti-howtos/references/location-and-maps.md +0 -267
  93. package/skills/ti-howtos/references/media-apis.md +0 -268
  94. package/skills/ti-howtos/references/notification-services.md +0 -539
  95. package/skills/ti-howtos/references/remote-data-sources.md +0 -339
  96. package/skills/ti-howtos/references/tutorials.md +0 -552
  97. package/skills/ti-howtos/references/using-modules.md +0 -182
  98. package/skills/ti-howtos/references/web-content-integration.md +0 -288
  99. package/skills/ti-howtos/references/webpack-build-pipeline.md +0 -125
@@ -1,46 +0,0 @@
1
- # PurgeTSS
2
-
3
- ## Overview
4
-
5
- **PurgeTSS** is an **optional** Alloy addon designed to enhance the process of developing visually captivating mobile applications for Titanium. It is NOT required for Alloy development — many projects use manual TSS styling successfully. Only recommend PurgeTSS when the user explicitly asks about it or their project already uses it.
6
-
7
- 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.
8
-
9
- ## Command-Line Interface Usage
10
-
11
- ```bash
12
- alloy purgetss
13
- ```
14
-
15
- ## Key Features
16
-
17
- - **21,000+ Utility Classes**: Provides more than Tailwind-like utility classes ready to use in your projects
18
- - **Clean app.tss**: Creates a clean `app.tss` file with only the classes used in your project by parsing all your XML files
19
- - **Customization**: Customize default classes via config file or create just-in-time classes with arbitrary values
20
- - **Icon Fonts**: Easily use icon fonts from Font Awesome, Material Icons, Material Symbols, and Framework7-Icons
21
- - **fonts.tss Generation**: Generates a fonts.tss file with all class definitions and fontFamily selectors
22
- - **Shades Command**: Generate custom color shades from hex colors
23
- - **Animation Module**: Apply basic 2D Matrix animations or transform to elements
24
- - **Grid System**: Simple two-dimensional grid system to align and distribute elements
25
-
26
- ## Documentation
27
-
28
- For complete documentation, visit the official PurgeTSS site at [purgetss.com](https://purgetss.com).
29
-
30
- ### Topics
31
-
32
- - [Installation](https://purgetss.com/docs/installation)
33
- - [Commands](https://purgetss.com/docs/commands)
34
- - [Customization](https://purgetss.com/docs/customization)
35
- - [Config file](https://purgetss.com/docs/customization/the-config-file)
36
- - [Custom rules](https://purgetss.com/docs/customization/custom-rules)
37
- - [Apply directive](https://purgetss.com/docs/customization/the-apply-directive)
38
- - [Opacity modifier](https://purgetss.com/docs/customization/the-opacity-modifier)
39
- - [Arbitrary values in XMLs](https://purgetss.com/docs/customization/arbitrary-values)
40
- - [Platform and Device modifiers](https://purgetss.com/docs/customization/platform-and-device-modifiers)
41
- - [Icon Fonts Libraries](https://purgetss.com/docs/customization/icon-fonts-libraries)
42
- - [Animation Module](https://purgetss.com/docs/animation-module)
43
- - [Introduction](https://purgetss.com/docs/animation-module/introduction)
44
- - [Available utilities](https://purgetss.com/docs/animation-module/available-utilities)
45
- - [Complex UI elements](https://purgetss.com/docs/animation-module/complex-ui-elements)
46
- - [Grid System](https://purgetss.com/docs/grid-system)
@@ -1,235 +0,0 @@
1
- # Dynamic Styles
2
-
3
- ## Introduction
4
-
5
- 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.
6
-
7
- ## Define Class Styles
8
-
9
- 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.
10
-
11
- **app/styles/app.tss**
12
-
13
- ```javascript
14
- ".bluetext" : {
15
- color: 'blue'
16
- },
17
- ".orangetext" : {
18
- color: 'orange'
19
- },
20
- ".shadow" : {
21
- shadowColor: '#88f',
22
- shadowOffset: {x:1,y:3}
23
- },
24
- ".ldpi" : {
25
- font: {fontSize: '9dp', fontWeight: 'normal' }
26
- },
27
- ".mdpi" : {
28
- font: {fontSize: '12dp', fontWeight: 'normal' }
29
- },
30
- ".hdpi" : {
31
- font: {fontSize: '18dp', fontWeight: 'bold' }
32
- },
33
- ".xhdpi" : {
34
- font: {fontSize: '24dp', fontWeight: 'bold' }
35
- },
36
- "Label" : {
37
- font: {fontSize: '14dp', fontWeight: 'normal' },
38
- shadow : {},
39
- color : 'black'
40
- },
41
- ".rude_button" : {
42
- title: 'Go Away'
43
- },
44
- ".nice_button" : {
45
- title: 'Please Close'
46
- },
47
- "Button" : {
48
- width: Ti.UI.SIZE,
49
- height: Ti.UI.SIZE
50
- }
51
- ".tiny_win" : {
52
- height: '150dp',
53
- width: '200dp',
54
- backgroundColor: 'blue'
55
- },
56
- ".big_win" : {
57
- height: '300dp',
58
- width: '400dp',
59
- backgroundColor: 'red'
60
- }
61
- ```
62
-
63
- 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. Since the Label size of 14 dp is a markup element style and even though it appears after the class styles, it does not have a higher priority number since class styles have higher precedence over markup element styles. The label is still 24 dp not 14 dp. Properties defined inline in the markup and TSS id styles still take precedence over class styles.
64
-
65
- ## Generate a Dynamic Style
66
-
67
- 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.
68
-
69
- You can use the controller's `UI.create` method to create a view component that is dynamically styled. The `UI.create` method accepts the element name (such as `Button`) or the full API name (such as `Ti.UI.Button`). You can optionally add additional properties inline specific to the component in the dictionary parameter.
70
-
71
- **app/views/dialog.xml**
72
-
73
- ```xml
74
- <Alloy>
75
- <Window id="win">
76
- <Button id="button" onClick="doClick" />
77
- </Window>
78
- </Alloy>
79
- ```
80
-
81
- **app/controllers/dialog.js**
82
-
83
- ```javascript
84
- function doClick(e) {
85
- $.win.close();
86
- }
87
-
88
- const args = arguments[0] || {};
89
- if (args.button) {
90
- const style = $.createStyle({
91
- classes: args.button,
92
- apiName: 'Button',
93
- color: 'blue'
94
- });
95
- $.button.applyProperties(style);
96
- }
97
- if (args.win) {
98
- const style = $.createStyle({
99
- classes: args.win,
100
- apiName: 'Window',
101
- backgroundColor: 'white'
102
- });
103
- $.win.applyProperties(style);
104
- }
105
- if (args.label) {
106
- args.label.top = 10
107
- const label = $.UI.create("Label", args.label);
108
- $.win.add(label);
109
- }
110
- ```
111
-
112
- **app/controllers/index.js**
113
-
114
- ```javascript
115
- const args = {};
116
- args.button = ['rude_button'];
117
- args.win = ['tiny_win'];
118
- args.label = {
119
- classes: ['hdpi', 'shadow'],
120
- text: 'No zombies allowed!'
121
- };
122
- Alloy.createController('dialog', args).getView().open();
123
- ```
124
-
125
- ### Equivalent Code Outside Controller
126
-
127
- 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:
128
-
129
- **app/controllers/index.js**
130
-
131
- ```javascript
132
- const dialog = Alloy.createController('dialog');
133
- let style = dialog.createStyle({
134
- classes: 'rude_button',
135
- apiName: 'Button',
136
- color: 'blue'
137
- });
138
- dialog.button.applyProperties(style);
139
- style = dialog.createStyle({
140
- classes: 'tiny_win',
141
- apiName: 'Window',
142
- backgroundColor: 'white'
143
- });
144
- dialog.win.applyProperties(style);
145
- style = {
146
- top: 10,
147
- text: 'No zombies allowed!',
148
- classes: 'hdpi shadow'
149
- }
150
- const label = dialog.UI.create('Label', style);
151
- dialog.win.add(label);
152
- dialog.getView().open();
153
- ```
154
-
155
- 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.
156
-
157
- ## Modify TSS Classes
158
-
159
- 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. As the classes are modified using these API calls, the view is automatically updated. To take advantage of these APIs, you need to enable autostyle for the components or else the view may not update properly.
160
-
161
- > **⚠️ ⚠️ Warning**
162
- > Using the `Require` or `Widget` elements to include external views in a controller-less view does not work with the `updateViews` method — you can include the external views, but the styles cannot be updated.
163
-
164
- 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.
165
-
166
- **app/controllers/index.js**
167
-
168
- ```javascript
169
- const dialog = Alloy.createController('dialog');
170
- dialog.addClass(dialog.win, 'tiny_win', {backgroundColor:'white'});
171
- dialog.addClass(dialog.button, 'rude_button', {color: 'blue'});
172
- const style = {
173
- top: 10,
174
- text: 'No zombies allowed!',
175
- classes: 'hdpi shadow'
176
- }
177
- const label = dialog.UI.create('Label', style);
178
- dialog.getView().open();
179
- ```
180
-
181
- Later on, you can change the classes:
182
-
183
- ```
184
- dialog.resetClass(dialog.button, 'nice_button orangetext hdpi');
185
- ```
186
-
187
- ## Autostyle
188
-
189
- 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.
190
-
191
- To enable autostyle, set the `autoStyle` attribute to `true` either in the XML markup or the `config.json` file.
192
-
193
- * To enable autostyle for an individual component, set the `autoStyle` attribute to true on the XML tag: `<View autoStyle="true">`.
194
- * To enable autostyle for components in a controller, set the `autoStyle` attribute to true on the root `<Alloy/>` tag: `<Alloy autoStyle="true">`.
195
- * To enable autostyle for all controllers in an Alloy project, set the `autoStyle` field to true in the `config.json` file.
196
-
197
- **app/config.json**
198
-
199
- ```json
200
- {
201
- "autoStyle": true
202
- }
203
- ```
204
-
205
- ### Why Autostyle is Needed
206
-
207
- Consider the following example without autostyle:
208
-
209
- **app/styles/index.tss**
210
-
211
- ```javascript
212
- ".coloronly" : {
213
- color: 'red'
214
- },
215
- ".colorsize" : {
216
- color: 'blue',
217
- font: {fontSize: '24dp'}
218
- },
219
- "Label" : {
220
- color: 'black',
221
- font: {fontSize: '12dp'}
222
- }
223
- ```
224
-
225
- **app/controllers/index.js**
226
-
227
- ```javascript
228
- $.addClass($.label, "coloronly colorsize"); // --> appears blue and 24dp
229
- $.removeClass($.label, "colorsize"); // --> appears red and 24dp (font size not updated!)
230
- $.removeClass($.label, "coloronly"); // --> appears red and 24dp (not black!)
231
- ```
232
-
233
- With autostyle enabled, the styles update as expected when classes are added or removed.
234
-
235
- **Workarounds without autostyle:** If you cannot enable autostyle, you can either create a default class that defines all possible properties (so removing a class reverts to the defaults), or pass in the optional inline properties as the third parameter to `addClass`/`removeClass`/`resetClass` to explicitly set the desired values.
@@ -1,375 +0,0 @@
1
- # Alloy Styles and Themes
2
-
3
- ## Titanium Style Sheets
4
-
5
- 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.
6
-
7
- 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.
8
-
9
- 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.
10
-
11
- You can use the following values and operators in your TSS file:
12
-
13
- * JSON values: Strings, Numbers, Objects, Array, Booleans and null
14
- * `undefined` to unset a property (since Alloy 1.4.0)
15
- * Titanium SDK constants: `Ti.UI.SIZE`
16
- * Localization functions: `Ti.Locale.getString()` and `L()`
17
- * Variables from `Alloy.CFG` or `Alloy.Globals`
18
- * Bitwise operators: `>>`, `<<`, `>>>`, `&`, `|`, `^` (since Alloy 1.3.0)
19
- * Single (`//comment`) and multiline comments (`/* comment */`)
20
-
21
- > **⚠️ ⚠️ Warning**
22
- > Alloy does not support the CSS concept of child or descendent selectors.
23
-
24
- **app/styles/index.tss**
25
-
26
- ```javascript
27
- // Applied to any element with class "container"
28
- ".container": {
29
- backgroundColor:"white"
30
- },
31
- // Applied to all Labels
32
- "Label": {
33
- width: Ti.UI.SIZE,
34
- height: Ti.UI.SIZE,
35
- color: "#000",
36
- transform: Alloy.Globals.rotateLeft
37
- },
38
- // Applied only to element with id="label"
39
- "#label": {
40
- color: "#999"
41
- }
42
- ```
43
-
44
- 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:
45
-
46
- **app/alloy.js**
47
-
48
- ```javascript
49
- Alloy.Globals.rotateLeft = Ti.UI.createMatrix2D().rotate(-90);
50
- ```
51
-
52
- **app/views/index.xml**
53
-
54
- ```xml
55
- <Alloy>
56
- <Window class="container">
57
- <Label id="label" onClick="doClick">Hello, World</Label>
58
- </Window>
59
- </Alloy>
60
- ```
61
-
62
- ## Global Styles
63
-
64
- 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.
65
-
66
- **styles/app.tss**
67
-
68
- ```javascript
69
- "Window":{
70
- backgroundColor: 'white',
71
- layout: 'vertical'
72
- }
73
- "Label":{
74
- color: 'gray',
75
- textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT,
76
- backgroundColor: 'transparent',
77
- font: {
78
- fontFamily:'Helvetica',
79
- fontSize: '12dp',
80
- fontStyle: 'normal',
81
- fontWeight: 'normal'
82
- }
83
- }
84
- ```
85
-
86
- **styles/index.tss**
87
-
88
- ```javascript
89
- "Window":{
90
- backgroundColor: 'blue'
91
- }
92
- "Label":{
93
- top: 20,
94
- left: '25dp',
95
- right: '25dp'
96
- }
97
- "#subtitle":{
98
- width: Ti.UI.FILL,
99
- textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
100
- font: {
101
- fontSize: '16dp',
102
- fontWeight: 'bold'
103
- }
104
- }
105
- ```
106
-
107
- **views/index.xml**
108
-
109
- ```xml
110
- <Alloy>
111
- <Window titleid="story_title" modal="true" exitOnClose="true">
112
- <Label id="subtitle" color="orange" textid="story_subtitle" />
113
- <Label top="25" color="white" textid="story_content" />
114
- </Window>
115
- </Alloy>
116
- ```
117
-
118
- 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.
119
-
120
- ## Platform-Specific Styles
121
-
122
- > **🚨 CRITICAL: Platform-Specific Properties Require Modifiers**
123
- > **Using `Ti.UI.iOS.*` or `Ti.UI.Android.*` properties in TSS WITHOUT platform modifiers will:**
124
- >
125
- > 1. **Add iOS code to Android builds** → compilation failures
126
- > 2. **Add Android code to iOS builds** → compilation failures
127
- >
128
- > **Example of the damage:**
129
- > ```tss
130
- > // ❌ WRONG - Adds Ti.UI.iOS to Android project
131
- > "#mainWindow": {
132
- > statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT // FAILS on Android!
133
- > }
134
- > ```
135
- >
136
- > **CORRECT - Always use platform modifiers:**
137
- > ```tss
138
- > // ✅ CORRECT - Only adds to iOS
139
- > "#mainWindow[platform=ios]": {
140
- > statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT
141
- > }
142
- >
143
- > // ✅ CORRECT - Only adds to Android
144
- > "#mainWindow[platform=android]": {
145
- > actionBar: {
146
- > displayHomeAsUp: true
147
- > }
148
- > }
149
- > ```
150
- >
151
- > **Common platform-specific properties that REQUIRE `[platform=...]` modifiers:**
152
- > - iOS: `statusBarStyle`, `modalStyle`, `modalTransitionStyle`, any `Ti.UI.iOS.*`
153
- > - Android: `actionBar` config, any `Ti.Android.*` constant
154
-
155
- As with views, separate styles may be defined based on the platform and device size.
156
-
157
- **To specify platform or device size conditionals:**
158
-
159
- 1. Place a set of square brackets (`[]`) **directly** after the name of the markup element, class name or id name in the TSS file. **Do NOT place a space between the name and brackets. The condition statements will be ignored.**
160
- 2. Inside the brackets:
161
- * `platform` attribute: assign a platform (`android`, `ios`). Comma separate to OR values. Prepend with `!` to negate.
162
- * `formFactor` attribute: assign a device size (`handheld` or `tablet`).
163
-
164
- ```
165
- // Default label
166
- "Label": {
167
- backgroundColor: "#000",
168
- text: 'Another platform'
169
- },
170
- // iPhone
171
- "Label[platform=ios formFactor=handheld]": {
172
- backgroundColor: "#f00",
173
- text: 'iPhone'
174
- },
175
- // iPad
176
- "Label[platform=ios formFactor=tablet]": {
177
- backgroundColor: "#0f0",
178
- text: 'iPad'
179
- },
180
- // Android
181
- "Label[platform=android]": {
182
- backgroundColor: "#00f",
183
- text: 'Android'
184
- }
185
- ```
186
-
187
- Alternatively, create subfolders named as the platform in the `styles` directory.
188
-
189
- ## Custom Query Styles
190
-
191
- You can create custom queries to select which styles to apply in both the TSS and XML files. Custom query styles override all styles (class, id, and markup element styles), except styles defined as attributes in the XML file.
192
-
193
- You may use the `if` attribute in combination with the `platform` and `formFactor` attributes. You can only add **one** custom query to the `if` attribute. The `if` attribute does **not** support multiple queries or the not operator (`!`).
194
-
195
- **To use a custom query:**
196
-
197
- 1. Define a conditional statement that returns a boolean value, and assign it to a property in `Alloy.Globals` or a local function.
198
- 2. Assign the `if` attribute to an element in the XML or TSS file.
199
-
200
- ### Example Using Custom Properties
201
-
202
- 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.
203
-
204
- 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.
205
-
206
- **apps/controllers/index.js**
207
-
208
- ```javascript
209
- function openBar (e) {
210
- Alloy.createController('win2', {'fooBar': true}).getView().open();
211
- };
212
-
213
- function openBaz (e) {
214
- Alloy.createController('win2', {'fooBaz': true}).getView().open();
215
- };
216
- ```
217
-
218
- 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.
219
-
220
- **app/styles/win2.tss**
221
-
222
- ```javascript
223
- "#label[if=$.args.fooBar]": {
224
- 'text' : 'Foobar',
225
- 'color' : 'blue'
226
- }
227
-
228
- "#label[if=$.args.fooBaz]": {
229
- 'text' : 'Foobaz',
230
- 'color' : 'red'
231
- }
232
- ```
233
-
234
- 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.
235
-
236
- **app/views/win2.xml**
237
-
238
- ```xml
239
- <Alloy>
240
- <Window>
241
- <Label if="$.args.fooBar" color="blue">Foobar</Label>
242
- <Label if="$.args.fooBaz" color="red">Foobaz</Label>
243
- </Window>
244
- </Alloy>
245
- ```
246
-
247
- ### Example Using Conditional Statements
248
-
249
- 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:
250
-
251
- **app/views/index.xml**
252
-
253
- ```xml
254
- <Alloy>
255
- <Window>
256
- <Label id="title" textid="title"/>
257
- <ScrollView>
258
- <Label id="content" textid="content"/>
259
- </ScrollView>
260
- <Label id="info">TextViewer by BluthCo</Label>
261
- </Window>
262
- </Alloy>
263
- ```
264
-
265
- 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:
266
-
267
- **app/alloy.js**
268
-
269
- ```javascript
270
- Alloy.Globals.isIos7Plus = (OS_IOS && parseInt(Ti.Platform.version.split(".")[0]) >= 7);
271
- Alloy.Globals.iPhoneTall = (OS_IOS && Ti.Platform.osname == "iphone" && Ti.Platform.displayCaps.platformHeight == 568);
272
- ```
273
-
274
- 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.
275
-
276
- **app/styles/index.tss**
277
-
278
- ```javascript
279
- // Default Styles
280
- "#content": {
281
- color: 'gray',
282
- top: '25dp',
283
- left: '10dp',
284
- font: {
285
- fontSize: '12dp'
286
- }
287
- },
288
- "#info": {
289
- color: 'gray',
290
- bottom: '20dp',
291
- font: {
292
- fontSize: '9dp'
293
- }
294
- },
295
- "#title": {
296
- color: 'black',
297
- top: '15dp',
298
- font: {
299
- fontSize: '14dp',
300
- fontWeight: 'bold'
301
- }
302
- },
303
- "Window": {
304
- layout: 'vertical',
305
- backgroundColor: 'white'
306
- },
307
- "ScrollView": {
308
- height: '415dp'
309
- },
310
- // Query styles
311
- "#info[if=Alloy.Globals.isIos7Plus]": {
312
- font: { textStyle : Ti.UI.TEXT_STYLE_FOOTNOTE }
313
- },
314
- "#title[if=Alloy.Globals.isIos7Plus]": {
315
- top: '25dp', // compensate for the status bar on iOS 7
316
- font: { textStyle : Ti.UI.TEXT_STYLE_HEADLINE }
317
- },
318
- "#content[if=Alloy.Globals.isIos7Plus]": {
319
- font: { textStyle : Ti.UI.TEXT_STYLE_CAPTION1 }
320
- },
321
- "ScrollView[if=Alloy.Globals.iPhoneTall]": {
322
- height: '500dp'
323
- }
324
- ```
325
-
326
- ## Themes
327
-
328
- Themes provide a way to overwrite or modify files for a specific brand of your app.
329
-
330
- To create a theme, create a folder called `themes` in your Alloy `app` directory. In the `themes` folder, create a folder for your theme.
331
-
332
- | Folder or Filename | Supported Since | Merges or Overwrites |
333
- | ------------------ | ----------------------- | -------------------------------- |
334
- | config.json | Alloy 1.4.0 | merges |
335
- | i18n | Alloy 1.7.6 / CLI 5.0.0 | merges folders and files |
336
- | assets | | merges folders, overwrites files |
337
- | lib | Alloy 1.7.6 / CLI 5.0.0 | merges folders, overwrites files |
338
- | platform | Alloy 1.7.6 / CLI 5.0.0 | merges folders, overwrites files |
339
- | styles | | merges folders and files |
340
- | widgets/\*/assets | Alloy 1.4.0 | merges folders, overwrites files |
341
- | widgets/\*/styles | Alloy 1.4.0 | merges folders and files |
342
-
343
- To use a theme, add it to your `config.json`:
344
-
345
- ```
346
- {
347
- "global": {
348
- "theme":"mytheme"
349
- },
350
- "os:ios": {
351
- "theme":"green"
352
- },
353
- "os:android": {
354
- "theme":"blue"
355
- },
356
- "dependencies": {}
357
- }
358
- ```
359
-
360
- ## Style Priorities
361
-
362
- 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:
363
-
364
- | Style Defined in... | Example |
365
- | ------------------------------------------------------------------- | ------------------------------------------------------------- |
366
- | Global Style File | `styles/app.tss` |
367
- | Global Style File in a Theme | `themes/<theme_name>/styles/app.tss` |
368
- | Global Style File with Platform-Specific Styles | `styles/<platform>/app.tss` |
369
- | Global Style File in a Theme with Platform-Specific Styles | `themes/<theme_name>/styles/<platform>/app.tss` |
370
- | View-Controller Style File | `styles/<view_controller>.tss` |
371
- | View-Controller Style File in a Theme | `themes/<theme_name>/styles/<view_controller>.tss` |
372
- | View-Controller Style File with Platform-Specific Styles | `styles/<platform>/<view_controller>.tss` |
373
- | View-Controller Style File in a Theme with Platform-Specific Styles | `themes/<theme_name>/styles/<platform>/<view_controller>.tss` |
374
- | XML Markup | `views/<view_controller>.xml` |
375
- | XML Markup with Platform-Specific Styles | `views/<platform>/<view_controller>.xml` |