@maccesar/titools 5.3.0 → 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.
- package/CONTRIBUTING.md +1 -1
- package/README.md +31 -60
- package/agents/ti-pro.md +3 -1
- package/commands/ti-audit.md +6 -4
- package/docs/examples.md +9 -0
- package/docs/knowledge-index.md +2 -1
- package/lib/config.js +1 -0
- package/package.json +1 -1
- package/skills/alloy-guides/SKILL.md +18 -179
- package/skills/alloy-guides/references/CLI_TASKS.md +17 -216
- package/skills/alloy-guides/references/CONCEPTS.md +27 -162
- package/skills/alloy-guides/references/CONTROLLERS.md +38 -236
- package/skills/alloy-guides/references/MODELS.md +47 -723
- package/skills/alloy-guides/references/MODELS_ADVANCED.md +21 -482
- package/skills/alloy-guides/references/VIEWS_DYNAMIC.md +12 -222
- package/skills/alloy-guides/references/VIEWS_STYLES.md +39 -358
- package/skills/alloy-guides/references/VIEWS_XML.md +36 -552
- package/skills/alloy-guides/references/WIDGETS.md +49 -127
- package/skills/alloy-howtos/SKILL.md +14 -169
- package/skills/alloy-howtos/references/best_practices.md +9 -113
- package/skills/alloy-howtos/references/cli_reference.md +18 -223
- package/skills/alloy-howtos/references/config_files.md +50 -133
- package/skills/alloy-howtos/references/debugging_troubleshooting.md +19 -63
- package/skills/alloy-howtos/references/samples.md +21 -138
- package/skills/ti-api/SKILL.md +10 -2
- package/skills/ti-api/references/api-android.md +36 -2
- package/skills/ti-api/references/api-app-platform.md +39 -3
- package/skills/ti-api/references/api-core.md +50 -18
- package/skills/ti-api/references/api-data-network.md +49 -35
- package/skills/ti-api/references/api-media.md +45 -27
- package/skills/ti-api/references/api-services.md +39 -9
- package/skills/ti-api/references/api-ui-android.md +33 -13
- package/skills/ti-api/references/api-ui-extras.md +41 -15
- package/skills/ti-api/references/api-ui-ios-animator.md +42 -26
- package/skills/ti-api/references/api-ui-ios.md +74 -2
- package/skills/ti-api/references/api-ui-lists.md +32 -16
- package/skills/ti-api/references/api-ui-text-input.md +34 -17
- package/skills/ti-api/references/api-ui-views.md +27 -1
- package/skills/ti-api/references/api-ui-windows-navigation.md +32 -18
- package/skills/ti-api/references/api-xml-global.md +66 -16
- package/skills/ti-create-release/SKILL.md +98 -0
- package/skills/ti-create-release/references/module-discovery.md +69 -0
- package/skills/ti-expert/references/adaptive-layouts.md +1 -1
- package/skills/ti-guides/SKILL.md +37 -76
- package/skills/ti-guides/references/advanced-data-and-images.md +122 -126
- package/skills/ti-guides/references/android-manifest.md +24 -83
- package/skills/ti-guides/references/app-distribution.md +31 -377
- package/skills/ti-guides/references/application-frameworks.md +127 -335
- package/skills/ti-guides/references/cli-reference.md +184 -633
- package/skills/ti-guides/references/commonjs-advanced.md +81 -231
- package/skills/ti-guides/references/compatibility-matrix.md +36 -75
- package/skills/ti-guides/references/hello-world.md +95 -70
- package/skills/ti-guides/references/hyperloop-native-access.md +52 -448
- package/skills/ti-guides/references/resources.md +174 -142
- package/skills/ti-guides/references/sdk-release-notes.md +28 -71
- package/skills/ti-guides/references/tiapp-config.md +222 -598
- package/skills/ti-howtos/SKILL.md +23 -123
- package/skills/ti-howtos/references/cross-platform-development.md +119 -324
- package/skills/ti-howtos/references/debugging-profiling.md +77 -445
- package/skills/ti-howtos/references/extending-titanium.md +199 -673
- package/skills/ti-howtos/references/local-data-sources.md +87 -300
- package/skills/ti-howtos/references/location-and-maps.md +86 -213
- package/skills/ti-howtos/references/media-apis.md +103 -223
- package/skills/ti-howtos/references/notification-services.md +86 -506
- package/skills/ti-howtos/references/remote-data-sources.md +97 -316
- package/skills/ti-howtos/references/using-modules.md +77 -133
- package/skills/ti-ui/SKILL.md +28 -143
- package/skills/ti-ui/references/icons-and-splash-screens.md +74 -403
- package/skills/ti-ui/references/layouts-and-positioning.md +175 -402
- package/skills/ti-ui/references/listviews-and-performance.md +100 -703
- package/skills/ti-ui/references/platform-conventions.md +180 -0
- package/skills/ti-ui/references/user-interface.md +43 -0
- package/skills/alloy-guides/references/VIEWS_WITHOUT_CONTROLLERS.md +0 -102
- package/skills/alloy-howtos/references/custom_tags.md +0 -148
- package/skills/ti-guides/references/coding-best-practices.md +0 -149
- package/skills/ti-guides/references/javascript-primer.md +0 -414
- package/skills/ti-guides/references/reserved-words.md +0 -36
- package/skills/ti-guides/references/style-and-conventions.md +0 -103
- package/skills/ti-howtos/references/android-platform-deep-dives.md +0 -624
- package/skills/ti-howtos/references/automation-fastlane-appium.md +0 -96
- package/skills/ti-howtos/references/buffer-codec-streams.md +0 -162
- package/skills/ti-howtos/references/google-maps-v2.md +0 -172
- package/skills/ti-howtos/references/ios-map-kit.md +0 -149
- package/skills/ti-howtos/references/ios-platform-deep-dives.md +0 -611
- package/skills/ti-howtos/references/tutorials.md +0 -565
- package/skills/ti-howtos/references/web-content-integration.md +0 -287
- package/skills/ti-howtos/references/webpack-build-pipeline.md +0 -124
- package/skills/ti-ui/references/accessibility-deep-dive.md +0 -288
- package/skills/ti-ui/references/animation-and-matrices.md +0 -569
- package/skills/ti-ui/references/application-structures.md +0 -626
- package/skills/ti-ui/references/custom-fonts-styling.md +0 -549
- package/skills/ti-ui/references/event-handling.md +0 -401
- package/skills/ti-ui/references/gestures.md +0 -448
- package/skills/ti-ui/references/orientation.md +0 -374
- package/skills/ti-ui/references/platform-ui-android.md +0 -727
- package/skills/ti-ui/references/platform-ui-ios.md +0 -576
- package/skills/ti-ui/references/scrolling-views.md +0 -288
- package/skills/ti-ui/references/tableviews.md +0 -542
|
@@ -1,235 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Runtime TSS classes
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
76
|
-
<
|
|
16
|
+
<Alloy autoStyle="true">
|
|
17
|
+
<Window>
|
|
18
|
+
<View id="row" class="row" />
|
|
77
19
|
</Window>
|
|
78
20
|
</Alloy>
|
|
79
21
|
```
|
|
80
22
|
|
|
81
|
-
|
|
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
|
-
|
|
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
|
|
1
|
+
# Alloy styles and themes
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
text: 'iPad'
|
|
9
|
+
".container": {
|
|
10
|
+
layout: "vertical",
|
|
11
|
+
top: 20
|
|
191
12
|
},
|
|
192
|
-
|
|
193
|
-
"
|
|
194
|
-
|
|
195
|
-
text: 'Android'
|
|
13
|
+
"#greeting": {
|
|
14
|
+
color: "#333",
|
|
15
|
+
font: { fontSize: 18, fontWeight: "bold" }
|
|
196
16
|
}
|
|
197
17
|
```
|
|
198
18
|
|
|
199
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
210
|
-
2. Assign the `if` attribute to an element in the XML or TSS file.
|
|
25
|
+
## Queries
|
|
211
26
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
323
|
-
"#
|
|
324
|
-
font: { textStyle : Ti.UI.TEXT_STYLE_FOOTNOTE }
|
|
31
|
+
"Button[platform=ios]": {
|
|
32
|
+
color: "#0b6bcb"
|
|
325
33
|
},
|
|
326
|
-
"#
|
|
327
|
-
|
|
328
|
-
font: { textStyle : Ti.UI.TEXT_STYLE_HEADLINE }
|
|
34
|
+
"#hero[formFactor=tablet]": {
|
|
35
|
+
height: 400
|
|
329
36
|
},
|
|
330
|
-
"
|
|
331
|
-
font: {
|
|
37
|
+
"Label[platform=ios formFactor=handheld]": {
|
|
38
|
+
font: { fontSize: 14 }
|
|
332
39
|
},
|
|
333
|
-
"
|
|
334
|
-
|
|
40
|
+
"#banner[if=Alloy.Globals.isPromo]": {
|
|
41
|
+
visible: true
|
|
335
42
|
}
|
|
336
43
|
```
|
|
337
44
|
|
|
338
|
-
|
|
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
|
|
47
|
+
## Themes
|
|
341
48
|
|
|
342
|
-
|
|
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
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
66
|
+
For runtime class changes, see [dynamic styles](./VIEWS_DYNAMIC.md).
|
|
375
67
|
|
|
376
|
-
|
|
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).
|