@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,235 +1,25 @@
1
- # Dynamic Styles
1
+ # Runtime TSS classes
2
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**
3
+ The current styling guide exposes controller methods to change classes on an existing view:
12
4
 
13
5
  ```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
- }
6
+ $.addClass($.row, 'selected');
7
+ $.removeClass($.row, 'selected');
8
+ $.resetClass($.row, 'row');
61
9
  ```
62
10
 
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.
11
+ `resetClass` replaces the class list instead of adding to it. Use it for mutually exclusive states. Provide a view with ID `row` and the referenced TSS classes before calling these methods.
70
12
 
71
- **app/views/dialog.xml**
13
+ Released Alloy requires autostyle to track the class list and recompute properties correctly when classes are removed. Enable it before creating these components, for example on their view root:
72
14
 
73
15
  ```xml
74
- <Alloy>
75
- <Window id="win">
76
- <Button id="button" onClick="doClick" />
16
+ <Alloy autoStyle="true">
17
+ <Window>
18
+ <View id="row" class="row" />
77
19
  </Window>
78
20
  </Alloy>
79
21
  ```
80
22
 
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.
23
+ This is a required correction to the current guide's abbreviated recipe: without class tracking, removal can leave old property values in place. This opt-in has a cost, so apply it to the components that need dynamic classes.
234
24
 
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.
25
+ Source: [styles and themes, Classes at runtime](https://titaniumsdk.com/docs/alloy/styles.md). The prerequisite is verified against the released Alloy 3.0.1 controller implementation.
@@ -1,387 +1,68 @@
1
- # Alloy Styles and Themes
1
+ # Alloy styles and themes
2
2
 
3
- <!-- TOC-START -->
4
- ## Contents
3
+ TSS uses Titanium property names. It resembles JSON with selectors, not browser CSS. Select an element (`Label`), class (`.container`) or ID (`#greeting`):
5
4
 
6
- - [Titanium Style Sheets](#titanium-style-sheets)
7
- - [Global Styles](#global-styles)
8
- - [Platform-Specific Styles](#platform-specific-styles)
9
- - [Custom Query Styles](#custom-query-styles)
10
- - [Themes](#themes)
11
- - [Style Priorities](#style-priorities)
12
-
13
- <!-- TOC-END -->
14
-
15
- ## Titanium Style Sheets
16
-
17
- 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.
18
-
19
- 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.
20
-
21
- 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.
22
-
23
- You can use the following values and operators in your TSS file:
24
-
25
- * JSON values: Strings, Numbers, Objects, Array, Booleans and null
26
- * `undefined` to unset a property (since Alloy 1.4.0)
27
- * Titanium SDK constants: `Ti.UI.SIZE`
28
- * Localization functions: `Ti.Locale.getString()` and `L()`
29
- * Variables from `Alloy.CFG` or `Alloy.Globals`
30
- * Bitwise operators: `>>`, `<<`, `>>>`, `&`, `|`, `^` (since Alloy 1.3.0)
31
- * Single (`//comment`) and multiline comments (`/* comment */`)
32
-
33
- > **⚠️ ⚠️ Warning**
34
- > Alloy does not support the CSS concept of child or descendent selectors.
35
-
36
- **app/styles/index.tss**
37
-
38
- ```javascript
39
- // Applied to any element with class "container"
40
- ".container": {
41
- backgroundColor:"white"
42
- },
43
- // Applied to all Labels
44
- "Label": {
45
- width: Ti.UI.SIZE,
46
- height: Ti.UI.SIZE,
47
- color: "#000",
48
- transform: Alloy.Globals.rotateLeft
49
- },
50
- // Applied only to element with id="label"
51
- "#label": {
52
- color: "#999"
53
- }
54
- ```
55
-
56
- 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:
57
-
58
- **app/alloy.js**
59
-
60
- ```javascript
61
- Alloy.Globals.rotateLeft = Ti.UI.createMatrix2D().rotate(-90);
62
- ```
63
-
64
- **app/views/index.xml**
65
-
66
- ```xml
67
- <Alloy>
68
- <Window class="container">
69
- <Label id="label" onClick="doClick">Hello, World</Label>
70
- </Window>
71
- </Alloy>
72
- ```
73
-
74
- ## Global Styles
75
-
76
- 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.
77
-
78
- **styles/app.tss**
79
-
80
- ```javascript
81
- "Window":{
82
- backgroundColor: 'white',
83
- layout: 'vertical'
84
- }
85
- "Label":{
86
- color: 'gray',
87
- textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT,
88
- backgroundColor: 'transparent',
89
- font: {
90
- fontFamily:'Helvetica',
91
- fontSize: '12dp',
92
- fontStyle: 'normal',
93
- fontWeight: 'normal'
94
- }
95
- }
96
- ```
97
-
98
- **styles/index.tss**
99
-
100
- ```javascript
101
- "Window":{
102
- backgroundColor: 'blue'
103
- }
104
- "Label":{
105
- top: 20,
106
- left: '25dp',
107
- right: '25dp'
108
- }
109
- "#subtitle":{
110
- width: Ti.UI.FILL,
111
- textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
112
- font: {
113
- fontSize: '16dp',
114
- fontWeight: 'bold'
115
- }
116
- }
117
- ```
118
-
119
- **views/index.xml**
120
-
121
- ```xml
122
- <Alloy>
123
- <Window titleid="story_title" modal="true" exitOnClose="true">
124
- <Label id="subtitle" color="orange" textid="story_subtitle" />
125
- <Label top="25" color="white" textid="story_content" />
126
- </Window>
127
- </Alloy>
128
- ```
129
-
130
- 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.
131
-
132
- ## Platform-Specific Styles
133
-
134
- > **🚨 CRITICAL: Platform-Specific Properties Require Modifiers**
135
- > **Using `Ti.UI.iOS.*` or `Ti.UI.Android.*` properties in TSS WITHOUT platform modifiers will:**
136
- >
137
- > 1. **Add iOS code to Android builds** → compilation failures
138
- > 2. **Add Android code to iOS builds** → compilation failures
139
- >
140
- > **Example of the damage:**
141
- > ```tss
142
- > // ❌ WRONG - Adds Ti.UI.iOS to Android project
143
- > "#mainWindow": {
144
- > statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT // FAILS on Android!
145
- > }
146
- > ```
147
- >
148
- > **CORRECT - Always use platform modifiers:**
149
- > ```tss
150
- > // ✅ CORRECT - Only adds to iOS
151
- > "#mainWindow[platform=ios]": {
152
- > statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT
153
- > }
154
- >
155
- > // ✅ CORRECT - Only adds to Android
156
- > "#mainWindow[platform=android]": {
157
- > actionBar: {
158
- > displayHomeAsUp: true
159
- > }
160
- > }
161
- > ```
162
- >
163
- > **Common platform-specific properties that REQUIRE `[platform=...]` modifiers:**
164
- > - iOS: `statusBarStyle`, `modalStyle`, `modalTransitionStyle`, any `Ti.UI.iOS.*`
165
- > - Android: `actionBar` config, any `Ti.Android.*` constant
166
-
167
- As with views, separate styles may be defined based on the platform and device size.
168
-
169
- **To specify platform or device size conditionals:**
170
-
171
- 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.**
172
- 2. Inside the brackets:
173
- * `platform` attribute: assign a platform (`android`, `ios`). Comma separate to OR values. Prepend with `!` to negate.
174
- * `formFactor` attribute: assign a device size (`handheld` or `tablet`).
175
-
176
- ```
177
- // Default label
178
- "Label": {
179
- backgroundColor: "#000",
180
- text: 'Another platform'
181
- },
182
- // iPhone
183
- "Label[platform=ios formFactor=handheld]": {
184
- backgroundColor: "#f00",
185
- text: 'iPhone'
5
+ ```tss
6
+ "Window": {
7
+ backgroundColor: "white"
186
8
  },
187
- // iPad
188
- "Label[platform=ios formFactor=tablet]": {
189
- backgroundColor: "#0f0",
190
- text: 'iPad'
9
+ ".container": {
10
+ layout: "vertical",
11
+ top: 20
191
12
  },
192
- // Android
193
- "Label[platform=android]": {
194
- backgroundColor: "#00f",
195
- text: 'Android'
13
+ "#greeting": {
14
+ color: "#333",
15
+ font: { fontSize: 18, fontWeight: "bold" }
196
16
  }
197
17
  ```
198
18
 
199
- Alternatively, create subfolders named as the platform in the `styles` directory.
200
-
201
- ## Custom Query Styles
202
-
203
- 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.
19
+ ## Scope and precedence
204
20
 
205
- 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 (`!`).
21
+ `app/styles/app.tss` applies throughout the app; `app/styles/<name>.tss` applies to the matching view. Use global styles for shared typography and palette, local styles for a screen.
206
22
 
207
- **To use a custom query:**
23
+ The current guide describes these layers from weakest to strongest: global TSS, the view's own TSS, XML attributes, then controller assignments. Within a stylesheet, IDs outrank classes, classes outrank element selectors, and later equally specific rules win. An XML value can therefore explain why changing a TSS value appears to do nothing.
208
24
 
209
- 1. Define a conditional statement that returns a boolean value, and assign it to a property in `Alloy.Globals` or a local function.
210
- 2. Assign the `if` attribute to an element in the XML or TSS file.
25
+ ## Queries
211
26
 
212
- ### Example Using Custom Properties
213
-
214
- 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.
215
-
216
- 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.
217
-
218
- **apps/controllers/index.js**
219
-
220
- ```javascript
221
- function openBar (e) {
222
- Alloy.createController('win2', {'fooBar': true}).getView().open();
223
- };
224
-
225
- function openBaz (e) {
226
- Alloy.createController('win2', {'fooBaz': true}).getView().open();
227
- };
228
- ```
229
-
230
- 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.
231
-
232
- **app/styles/win2.tss**
233
-
234
- ```javascript
235
- "#label[if=$.args.fooBar]": {
236
- 'text' : 'Foobar',
237
- 'color' : 'blue'
238
- }
239
-
240
- "#label[if=$.args.fooBaz]": {
241
- 'text' : 'Foobaz',
242
- 'color' : 'red'
243
- }
244
- ```
245
-
246
- 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.
247
-
248
- **app/views/win2.xml**
249
-
250
- ```xml
251
- <Alloy>
252
- <Window>
253
- <Label if="$.args.fooBar" color="blue">Foobar</Label>
254
- <Label if="$.args.fooBaz" color="red">Foobaz</Label>
255
- </Window>
256
- </Alloy>
257
- ```
258
-
259
- ### Example Using Conditional Statements
260
-
261
- 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:
262
-
263
- **app/views/index.xml**
264
-
265
- ```xml
266
- <Alloy>
267
- <Window>
268
- <Label id="title" textid="title"/>
269
- <ScrollView>
270
- <Label id="content" textid="content"/>
271
- </ScrollView>
272
- <Label id="info">TextViewer by BluthCo</Label>
273
- </Window>
274
- </Alloy>
275
- ```
276
-
277
- 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:
278
-
279
- **app/alloy.js**
280
-
281
- ```javascript
282
- Alloy.Globals.isIos7Plus = (OS_IOS && parseInt(Ti.Platform.version.split(".")[0]) >= 7);
283
- Alloy.Globals.iPhoneTall = (OS_IOS && Ti.Platform.osname == "iphone" && Ti.Platform.displayCaps.platformHeight == 568);
284
- ```
285
-
286
- 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.
287
-
288
- **app/styles/index.tss**
289
-
290
- ```javascript
291
- // Default Styles
292
- "#content": {
293
- color: 'gray',
294
- top: '25dp',
295
- left: '10dp',
296
- font: {
297
- fontSize: '12dp'
298
- }
299
- },
300
- "#info": {
301
- color: 'gray',
302
- bottom: '20dp',
303
- font: {
304
- fontSize: '9dp'
305
- }
306
- },
307
- "#title": {
308
- color: 'black',
309
- top: '15dp',
310
- font: {
311
- fontSize: '14dp',
312
- fontWeight: 'bold'
313
- }
314
- },
315
- "Window": {
316
- layout: 'vertical',
317
- backgroundColor: 'white'
318
- },
319
- "ScrollView": {
320
- height: '415dp'
27
+ ```tss
28
+ "Button[platform=android]": {
29
+ backgroundColor: "#2f6f4f"
321
30
  },
322
- // Query styles
323
- "#info[if=Alloy.Globals.isIos7Plus]": {
324
- font: { textStyle : Ti.UI.TEXT_STYLE_FOOTNOTE }
31
+ "Button[platform=ios]": {
32
+ color: "#0b6bcb"
325
33
  },
326
- "#title[if=Alloy.Globals.isIos7Plus]": {
327
- top: '25dp', // compensate for the status bar on iOS 7
328
- font: { textStyle : Ti.UI.TEXT_STYLE_HEADLINE }
34
+ "#hero[formFactor=tablet]": {
35
+ height: 400
329
36
  },
330
- "#content[if=Alloy.Globals.isIos7Plus]": {
331
- font: { textStyle : Ti.UI.TEXT_STYLE_CAPTION1 }
37
+ "Label[platform=ios formFactor=handheld]": {
38
+ font: { fontSize: 14 }
332
39
  },
333
- "ScrollView[if=Alloy.Globals.iPhoneTall]": {
334
- height: '500dp'
40
+ "#banner[if=Alloy.Globals.isPromo]": {
41
+ visible: true
335
42
  }
336
43
  ```
337
44
 
338
- ## Themes
45
+ Queries combine with spaces. Platform conditions can be resolved while compiling; device form factor and global flags are evaluated when views/styles are created. Set `Alloy.Globals.isPromo` in `app/alloy.js` before constructing the controller. Changing that variable later does not itself restyle an existing view.
339
46
 
340
- Themes provide a way to overwrite or modify files for a specific brand of your app.
47
+ ## Themes
341
48
 
342
- To create a theme, create a folder called `themes` in your Alloy `app` directory. In the `themes` folder, create a folder for your theme.
49
+ A theme lives under `app/themes/<name>/`. Its `styles/app.tss` merges over base styles, and its assets replace same-path assets:
343
50
 
344
- | Folder or Filename | Supported Since | Merges or Overwrites |
345
- | ------------------ | ----------------------- | -------------------------------- |
346
- | config.json | Alloy 1.4.0 | merges |
347
- | i18n | Alloy 1.7.6 / CLI 5.0.0 | merges folders and files |
348
- | assets | | merges folders, overwrites files |
349
- | lib | Alloy 1.7.6 / CLI 5.0.0 | merges folders, overwrites files |
350
- | platform | Alloy 1.7.6 / CLI 5.0.0 | merges folders, overwrites files |
351
- | styles | | merges folders and files |
352
- | widgets/\*/assets | Alloy 1.4.0 | merges folders, overwrites files |
353
- | widgets/\*/styles | Alloy 1.4.0 | merges folders and files |
51
+ ```text
52
+ app/themes/dark/styles/app.tss
53
+ app/themes/dark/assets/images/logo.png
54
+ ```
354
55
 
355
- To use a theme, add it to your `config.json`:
56
+ Select one at build time:
356
57
 
357
- ```
58
+ ```json
358
59
  {
359
- "global": {
360
- "theme":"mytheme"
361
- },
362
- "os:ios": {
363
- "theme":"green"
364
- },
365
- "os:android": {
366
- "theme":"blue"
367
- },
368
- "dependencies": {}
60
+ "global": { "theme": "dark" }
369
61
  }
370
62
  ```
371
63
 
372
- ## Style Priorities
64
+ Rebuild to change the theme. For a runtime light/dark response, use semantic colors in `app/assets/semantic.colors.json`, as described in the [first app](https://titaniumsdk.com/docs/build/first-app.md); a build-time theme is not a runtime switch.
373
65
 
374
- 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:
66
+ For runtime class changes, see [dynamic styles](./VIEWS_DYNAMIC.md).
375
67
 
376
- | Style Defined in... | Example |
377
- | ------------------------------------------------------------------- | ------------------------------------------------------------- |
378
- | Global Style File | `styles/app.tss` |
379
- | Global Style File in a Theme | `themes/<theme_name>/styles/app.tss` |
380
- | Global Style File with Platform-Specific Styles | `styles/<platform>/app.tss` |
381
- | Global Style File in a Theme with Platform-Specific Styles | `themes/<theme_name>/styles/<platform>/app.tss` |
382
- | View-Controller Style File | `styles/<view_controller>.tss` |
383
- | View-Controller Style File in a Theme | `themes/<theme_name>/styles/<view_controller>.tss` |
384
- | View-Controller Style File with Platform-Specific Styles | `styles/<platform>/<view_controller>.tss` |
385
- | View-Controller Style File in a Theme with Platform-Specific Styles | `themes/<theme_name>/styles/<platform>/<view_controller>.tss` |
386
- | XML Markup | `views/<view_controller>.xml` |
387
- | XML Markup with Platform-Specific Styles | `views/<platform>/<view_controller>.xml` |
68
+ Source: [styles and themes](https://titaniumsdk.com/docs/alloy/styles.md).