@maccesar/titools 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/AGENTS-TEMPLATE.md +173 -0
  2. package/README.md +867 -0
  3. package/agents/ti-researcher.md +108 -0
  4. package/bin/titools.js +53 -0
  5. package/lib/commands/agents.js +126 -0
  6. package/lib/commands/install.js +188 -0
  7. package/lib/commands/uninstall.js +215 -0
  8. package/lib/commands/update.js +159 -0
  9. package/lib/config.js +119 -0
  10. package/lib/downloader.js +153 -0
  11. package/lib/installer.js +253 -0
  12. package/lib/platform.js +108 -0
  13. package/lib/symlink.js +142 -0
  14. package/lib/utils.js +270 -0
  15. package/package.json +67 -0
  16. package/skills/alloy-expert/SKILL.md +247 -0
  17. package/skills/alloy-expert/assets/ControllerAutoCleanup.js +182 -0
  18. package/skills/alloy-expert/references/alloy-structure.md +381 -0
  19. package/skills/alloy-expert/references/anti-patterns.md +133 -0
  20. package/skills/alloy-expert/references/code-conventions.md +469 -0
  21. package/skills/alloy-expert/references/contracts.md +280 -0
  22. package/skills/alloy-expert/references/controller-patterns.md +520 -0
  23. package/skills/alloy-expert/references/error-handling.md +484 -0
  24. package/skills/alloy-expert/references/examples.md +735 -0
  25. package/skills/alloy-expert/references/migration-patterns.md +298 -0
  26. package/skills/alloy-expert/references/patterns.md +448 -0
  27. package/skills/alloy-expert/references/performance-patterns.md +855 -0
  28. package/skills/alloy-expert/references/security-patterns.md +847 -0
  29. package/skills/alloy-expert/references/state-management.md +779 -0
  30. package/skills/alloy-expert/references/testing.md +872 -0
  31. package/skills/alloy-guides/SKILL.md +214 -0
  32. package/skills/alloy-guides/references/CLI_TASKS.md +243 -0
  33. package/skills/alloy-guides/references/CONCEPTS.md +191 -0
  34. package/skills/alloy-guides/references/CONTROLLERS.md +298 -0
  35. package/skills/alloy-guides/references/MODELS.md +1028 -0
  36. package/skills/alloy-guides/references/PURGETSS.md +56 -0
  37. package/skills/alloy-guides/references/VIEWS_DYNAMIC.md +242 -0
  38. package/skills/alloy-guides/references/VIEWS_STYLES.md +388 -0
  39. package/skills/alloy-guides/references/VIEWS_WITHOUT_CONTROLLERS.md +109 -0
  40. package/skills/alloy-guides/references/VIEWS_XML.md +558 -0
  41. package/skills/alloy-guides/references/WIDGETS.md +176 -0
  42. package/skills/alloy-howtos/SKILL.md +203 -0
  43. package/skills/alloy-howtos/references/best_practices.md +138 -0
  44. package/skills/alloy-howtos/references/cli_reference.md +253 -0
  45. package/skills/alloy-howtos/references/config_files.md +87 -0
  46. package/skills/alloy-howtos/references/custom_tags.md +147 -0
  47. package/skills/alloy-howtos/references/debugging_troubleshooting.md +101 -0
  48. package/skills/alloy-howtos/references/samples.md +167 -0
  49. package/skills/purgetss/SKILL.md +442 -0
  50. package/skills/purgetss/assets/purgetss.config.cjs +17 -0
  51. package/skills/purgetss/references/EXAMPLES.md +247 -0
  52. package/skills/purgetss/references/animation-system.md +1294 -0
  53. package/skills/purgetss/references/apply-directive.md +375 -0
  54. package/skills/purgetss/references/arbitrary-values.md +612 -0
  55. package/skills/purgetss/references/class-index.md +1350 -0
  56. package/skills/purgetss/references/cli-commands.md +948 -0
  57. package/skills/purgetss/references/configurable-properties.md +654 -0
  58. package/skills/purgetss/references/custom-rules.md +161 -0
  59. package/skills/purgetss/references/customization-deep-dive.md +722 -0
  60. package/skills/purgetss/references/dynamic-component-creation.md +489 -0
  61. package/skills/purgetss/references/grid-layout.md +455 -0
  62. package/skills/purgetss/references/icon-fonts.md +609 -0
  63. package/skills/purgetss/references/installation-setup.md +366 -0
  64. package/skills/purgetss/references/opacity-modifier.md +291 -0
  65. package/skills/purgetss/references/platform-modifiers.md +479 -0
  66. package/skills/purgetss/references/smart-mappings.md +42 -0
  67. package/skills/purgetss/references/titanium-resets.md +359 -0
  68. package/skills/purgetss/references/ui-ux-design.md +1526 -0
  69. package/skills/ti-guides/SKILL.md +94 -0
  70. package/skills/ti-guides/references/advanced-data-and-images.md +19 -0
  71. package/skills/ti-guides/references/alloy-cli-advanced.md +84 -0
  72. package/skills/ti-guides/references/alloy-data-mastery.md +29 -0
  73. package/skills/ti-guides/references/alloy-widgets-and-themes.md +19 -0
  74. package/skills/ti-guides/references/android-manifest.md +97 -0
  75. package/skills/ti-guides/references/app-distribution.md +258 -0
  76. package/skills/ti-guides/references/application-frameworks.md +377 -0
  77. package/skills/ti-guides/references/cli-reference.md +402 -0
  78. package/skills/ti-guides/references/coding-best-practices.md +102 -0
  79. package/skills/ti-guides/references/commonjs-advanced.md +134 -0
  80. package/skills/ti-guides/references/hello-world.md +100 -0
  81. package/skills/ti-guides/references/hyperloop-native-access.md +62 -0
  82. package/skills/ti-guides/references/javascript-primer.md +411 -0
  83. package/skills/ti-guides/references/reserved-words.md +36 -0
  84. package/skills/ti-guides/references/resources.md +183 -0
  85. package/skills/ti-guides/references/style-and-conventions.md +48 -0
  86. package/skills/ti-guides/references/tiapp-config.md +609 -0
  87. package/skills/ti-howtos/SKILL.md +174 -0
  88. package/skills/ti-howtos/references/android-platform-deep-dives.md +658 -0
  89. package/skills/ti-howtos/references/automation-fastlane-appium.md +95 -0
  90. package/skills/ti-howtos/references/buffer-codec-streams.md +140 -0
  91. package/skills/ti-howtos/references/cross-platform-development.md +348 -0
  92. package/skills/ti-howtos/references/debugging-profiling.md +543 -0
  93. package/skills/ti-howtos/references/extending-titanium.md +723 -0
  94. package/skills/ti-howtos/references/google-maps-v2.md +169 -0
  95. package/skills/ti-howtos/references/ios-map-kit.md +143 -0
  96. package/skills/ti-howtos/references/ios-platform-deep-dives.md +783 -0
  97. package/skills/ti-howtos/references/local-data-sources.md +301 -0
  98. package/skills/ti-howtos/references/location-and-maps.md +252 -0
  99. package/skills/ti-howtos/references/media-apis.md +210 -0
  100. package/skills/ti-howtos/references/notification-services.md +599 -0
  101. package/skills/ti-howtos/references/remote-data-sources.md +349 -0
  102. package/skills/ti-howtos/references/tutorials.md +502 -0
  103. package/skills/ti-howtos/references/using-modules.md +237 -0
  104. package/skills/ti-howtos/references/web-content-integration.md +307 -0
  105. package/skills/ti-howtos/references/webpack-build-pipeline.md +78 -0
  106. package/skills/ti-ui/SKILL.md +179 -0
  107. package/skills/ti-ui/references/accessibility-deep-dive.md +242 -0
  108. package/skills/ti-ui/references/animation-and-matrices.md +599 -0
  109. package/skills/ti-ui/references/application-structures.md +655 -0
  110. package/skills/ti-ui/references/custom-fonts-styling.md +579 -0
  111. package/skills/ti-ui/references/event-handling.md +393 -0
  112. package/skills/ti-ui/references/gestures.md +473 -0
  113. package/skills/ti-ui/references/icons-and-splash-screens.md +409 -0
  114. package/skills/ti-ui/references/layouts-and-positioning.md +462 -0
  115. package/skills/ti-ui/references/listviews-and-performance.md +619 -0
  116. package/skills/ti-ui/references/orientation.md +362 -0
  117. package/skills/ti-ui/references/platform-ui-android.md +635 -0
  118. package/skills/ti-ui/references/platform-ui-ios.md +469 -0
  119. package/skills/ti-ui/references/scrolling-views.md +252 -0
  120. package/skills/ti-ui/references/tableviews.md +568 -0
@@ -0,0 +1,489 @@
1
+ # Dynamic Component Creation with PurgeTSS
2
+
3
+ ## Table of Contents
4
+
5
+ - [Dynamic Component Creation with PurgeTSS](#dynamic-component-creation-with-purgetss)
6
+ - [Table of Contents](#table-of-contents)
7
+ - [Overview](#overview)
8
+ - [Method 1: `$.UI.create()` (Recommended)](#method-1-uicreate-recommended)
9
+ - [Basic Syntax](#basic-syntax)
10
+ - [Complete Example: Theme Card](#complete-example-theme-card)
11
+ - [Supported Components](#supported-components)
12
+ - [Classes Format Options](#classes-format-options)
13
+ - [Platform Modifiers in Dynamic Components](#platform-modifiers-in-dynamic-components)
14
+ - [Arbitrary Values](#arbitrary-values)
15
+ - [Adding Children Dynamically](#adding-children-dynamically)
16
+ - [Method 2: `Alloy.createStyle()` + `applyProperties()`](#method-2-alloycreatestyle--applyproperties)
17
+ - [When to Use This Method](#when-to-use-this-method)
18
+ - [Basic Syntax](#basic-syntax-1)
19
+ - [Complete Example](#complete-example)
20
+ - [Classes Format](#classes-format)
21
+ - [Comparison: Which Method to Use?](#comparison-which-method-to-use)
22
+ - [Real-World Examples](#real-world-examples)
23
+ - [Example 1: Dynamic Form Fields](#example-1-dynamic-form-fields)
24
+ - [Example 2: Dynamic List Items](#example-2-dynamic-list-items)
25
+ - [Example 3: Dynamic Theme Switching](#example-3-dynamic-theme-switching)
26
+ - [Example 4: Dynamic Icon Grid](#example-4-dynamic-icon-grid)
27
+ - [Important Notes](#important-notes)
28
+ - [PurgeTSS Processes Classes During Build](#purgetss-processes-classes-during-build)
29
+ - [Class Verification](#class-verification)
30
+ - [Platform-Specific Best Practices](#platform-specific-best-practices)
31
+ - [Anti-Patterns to Avoid](#anti-patterns-to-avoid)
32
+ - [❌ Don't Use `Ti.UI.create()` with Manual Styles](#-dont-use-tiuicreate-with-manual-styles)
33
+ - [✅ Use `$.UI.create()` with PurgeTSS Classes](#-use-uicreate-with-purgetss-classes)
34
+ - [❌ Don't Mix Styles and Classes](#-dont-mix-styles-and-classes)
35
+ - [✅ Use Only Classes (or Only Styles)](#-use-only-classes-or-only-styles)
36
+ - [Summary](#summary)
37
+
38
+ ---
39
+
40
+ ## Overview
41
+
42
+ When creating components dynamically in Controllers (not declaratively in XML), PurgeTSS provides two powerful methods to apply utility classes:
43
+
44
+ 1. **`$.UI.create()`** - Create components with PurgeTSS classes (Recommended)
45
+ 2. **`Alloy.createStyle()` + `applyProperties()`** - Apply PurgeTSS styles to existing components
46
+
47
+ :::tip BEST PRACTICE
48
+ **Always prefer `$.UI.create()` for dynamic components** - it's cleaner, more readable, and PurgeTSS will process the classes automatically during build.
49
+ :::
50
+
51
+ ---
52
+
53
+ ## Method 1: `$.UI.create()` (Recommended)
54
+
55
+ ### Basic Syntax
56
+
57
+ ```javascript
58
+ $.UI.create('ComponentType', {
59
+ // Component properties
60
+ property: value,
61
+
62
+ // PurgeTSS utility classes
63
+ classes: ['class-1', 'class-2', 'class-3']
64
+ // OR as string:
65
+ // classes: 'class-1 class-2 class-3'
66
+ })
67
+ ```
68
+
69
+ ### Complete Example: Theme Card
70
+
71
+ ```javascript
72
+ // controllers/settings/themes.js
73
+ function createThemeCard(themeName, themeTitle, imagePath) {
74
+ return $.UI.create('View', {
75
+ // View properties
76
+ valor: themeName,
77
+ title: themeTitle, // Add title for TTS support
78
+
79
+ // PurgeTSS utility classes
80
+ classes: [
81
+ 'w-(160)', // Arbitrary width: 160px
82
+ 'ios:mx-1', // Platform-specific margin (iOS only)
83
+ 'border-6', // Border width: 6dp
84
+ 'h-auto', // Height: SIZE
85
+ 'rounded', // Border radius: 4dp
86
+ 'border-white', // Border color: white
87
+ 'bg-white' // Background: white
88
+ ]
89
+ })
90
+ }
91
+ ```
92
+
93
+ ### Supported Components
94
+
95
+ `$.UI.create()` works with **ALL Titanium UI components**:
96
+
97
+ | Component Type | Example |
98
+ | ---------------- | ----------------------------------------------------------------------------------- |
99
+ | `View` | `$.UI.create('View', { classes: ['w-screen', 'h-auto'] })` |
100
+ | `Label` | `$.UI.create('Label', { text: 'Hello', classes: ['text-xl', 'font-bold'] })` |
101
+ | `Button` | `$.UI.create('Button', { title: 'Click', classes: ['bg-blue-500', 'rounded-lg'] })` |
102
+ | `ImageView` | `$.UI.create('ImageView', { image: '/img.png', classes: ['wh-16', 'rounded'] })` |
103
+ | `TextField` | `$.UI.create('TextField', { classes: ['border-gray-300', 'border-(1)'] })` |
104
+ | `ScrollView` | `$.UI.create('ScrollView', { classes: ['wh-screen', 'bg-gray-50'] })` |
105
+ | Any UI component | All `Ti.UI.*` components are supported |
106
+
107
+ ### Classes Format Options
108
+
109
+ ```javascript
110
+ // Option 1: Array of classes (recommended for readability)
111
+ classes: ['w-screen', 'h-auto', 'bg-white', 'rounded-lg']
112
+
113
+ // Option 2: String with space-separated classes
114
+ classes: 'w-screen h-auto bg-white rounded-lg'
115
+
116
+ // Option 3: Mix arbitrary values with predefined classes
117
+ classes: ['w-(100px)', 'h-auto', 'bg-(#ff0000)', 'rounded-lg']
118
+ ```
119
+
120
+ ### Platform Modifiers in Dynamic Components
121
+
122
+ ```javascript
123
+ // Platform-specific classes work perfectly
124
+ classes: [
125
+ 'ios:mx-2', // iOS: horizontal margin
126
+ 'android:mx-1', // Android: horizontal margin
127
+ 'bg-white', // Both platforms: white background
128
+ 'tablet:text-lg' // Tablets only: larger text
129
+ ]
130
+ ```
131
+
132
+ ### Arbitrary Values
133
+
134
+ ```javascript
135
+ // Arbitrary values use parentheses notation
136
+ classes: [
137
+ 'w-(160)', // Custom width
138
+ 'h-(200px)', // Custom height with unit
139
+ 'bg-(#3b82f6)', // Custom hex color
140
+ 'm-(10dp)', // Custom margin with unit
141
+ 'border-(2)' // Custom border width
142
+ ]
143
+ ```
144
+
145
+ ### Adding Children Dynamically
146
+
147
+ ```javascript
148
+ function createListItem(text, icon) {
149
+ const container = $.UI.create('View', {
150
+ classes: ['horizontal', 'm-4', 'p-4', 'bg-white', 'rounded-lg']
151
+ })
152
+
153
+ const iconView = $.UI.create('Label', {
154
+ text: icon,
155
+ classes: ['text-2xl', 'mr-4']
156
+ })
157
+
158
+ const label = $.UI.create('Label', {
159
+ text: text,
160
+ classes: ['text-base', 'font-semibold']
161
+ })
162
+
163
+ container.add(iconView)
164
+ container.add(label)
165
+
166
+ return container
167
+ }
168
+ ```
169
+
170
+ ---
171
+
172
+ ## Method 2: `Alloy.createStyle()` + `applyProperties()`
173
+
174
+ ### When to Use This Method
175
+
176
+ Use `Alloy.createStyle()` when you need to:
177
+ - Apply PurgeTSS styles to an **existing component** (created without `$.UI.create()`)
178
+ - Modify styles dynamically after component creation
179
+ - Apply styles from a different view/controller
180
+
181
+ ### Basic Syntax
182
+
183
+ ```javascript
184
+ // Create style object
185
+ const style = Alloy.createStyle('viewName', {
186
+ apiName: 'Ti.UI.View',
187
+ classes: 'bg-white rounded-lg'
188
+ })
189
+
190
+ // Apply to existing component
191
+ $.myView.applyProperties(style)
192
+ ```
193
+
194
+ ### Complete Example
195
+
196
+ ```javascript
197
+ // controllers/form/validation.js
198
+ function showError(inputField, errorMessage) {
199
+ // Create error style
200
+ const errorStyle = Alloy.createStyle('index', {
201
+ apiName: 'Ti.UI.TextField',
202
+ classes: ['border-2', 'border-red-500', 'bg-red-50']
203
+ })
204
+
205
+ // Apply to existing input field
206
+ inputField.applyProperties(errorStyle)
207
+ }
208
+
209
+ function clearError(inputField) {
210
+ // Create normal style
211
+ const normalStyle = Alloy.createStyle('index', {
212
+ apiName: 'Ti.UI.TextField',
213
+ classes: ['border-1', 'border-gray-300', 'bg-white']
214
+ })
215
+
216
+ // Apply to existing input field
217
+ inputField.applyProperties(normalStyle)
218
+ }
219
+ ```
220
+
221
+ ### Classes Format
222
+
223
+ ```javascript
224
+ // String format
225
+ Alloy.createStyle('index', { classes: 'bg-white rounded-lg' })
226
+
227
+ // Array format
228
+ Alloy.createStyle('index', {
229
+ classes: ['bg-white', 'rounded-lg', 'text-center']
230
+ })
231
+ ```
232
+
233
+ ---
234
+
235
+ ## Comparison: Which Method to Use?
236
+
237
+ | Scenario | Recommended Method | Example |
238
+ | ------------------------------- | ------------------------------------------- | ------------------------------------------------ |
239
+ | **Creating new components** | `$.UI.create()` | `$.UI.create('View', { classes: ['bg-white'] })` |
240
+ | **Styling existing components** | `Alloy.createStyle()` + `applyProperties()` | `view.applyProperties(Alloy.createStyle(...))` |
241
+ | **Dynamic style changes** | `Alloy.createStyle()` + `applyProperties()` | Form validation, theme switching |
242
+ | **Component factories** | `$.UI.create()` | Reusable component creators |
243
+
244
+ ---
245
+
246
+ ## Real-World Examples
247
+
248
+ ### Example 1: Dynamic Form Fields
249
+
250
+ ```javascript
251
+ // lib/factories/formFactory.js
252
+ exports.createFormField = function fieldType, options) {
253
+ const baseClasses = ['w-screen', 'h-12', 'mx-4', 'border-gray-300', 'border-(1)', 'rounded-lg']
254
+
255
+ switch (fieldType) {
256
+ case 'text':
257
+ return $.UI.create('TextField', {
258
+ hintText: options.hint,
259
+ classes: [...baseClasses, 'bg-white', 'px-4']
260
+ })
261
+
262
+ case 'textarea':
263
+ return $.UI.create('TextArea', {
264
+ hintText: options.hint,
265
+ classes: [...baseClasses, 'h-24', 'bg-white', 'px-4']
266
+ })
267
+
268
+ case 'button':
269
+ return $.UI.create('Button', {
270
+ title: options.title,
271
+ classes: ['w-screen', 'h-14', 'mx-4', 'mt-6', 'bg-blue-500', 'rounded-xl', 'text-white', 'font-bold']
272
+ })
273
+ }
274
+ }
275
+ ```
276
+
277
+ ### Example 2: Dynamic List Items
278
+
279
+ ```javascript
280
+ // controllers/products/list.js
281
+ function createProductCard(product) {
282
+ const card = $.UI.create('View', {
283
+ classes: ['mx-4', 'mb-4', 'bg-white', 'rounded-xl', 'shadow-lg']
284
+ })
285
+
286
+ const image = $.UI.create('ImageView', {
287
+ image: product.imageUrl,
288
+ classes: ['w-screen', 'h-40', 'rounded-t-xl']
289
+ })
290
+
291
+ const info = $.UI.create('View', {
292
+ classes: ['vertical', 'p-4']
293
+ })
294
+
295
+ const title = $.UI.create('Label', {
296
+ text: product.name,
297
+ classes: ['text-lg', 'font-bold', 'mb-2']
298
+ })
299
+
300
+ const price = $.UI.create('Label', {
301
+ text: `$${product.price}`,
302
+ classes: ['text-xl', 'text-green-600', 'font-bold']
303
+ })
304
+
305
+ info.add(title)
306
+ info.add(price)
307
+ card.add(image)
308
+ card.add(info)
309
+
310
+ return card
311
+ }
312
+ ```
313
+
314
+ ### Example 3: Dynamic Theme Switching
315
+
316
+ ```javascript
317
+ // controllers/settings/theme.js
318
+ function applyTheme(theme) {
319
+ const themes = {
320
+ light: {
321
+ window: Alloy.createStyle('index', { classes: 'bg-white' }),
322
+ text: Alloy.createStyle('index', { classes: 'text-gray-900' })
323
+ },
324
+ dark: {
325
+ window: Alloy.createStyle('index', { classes: 'bg-gray-900' }),
326
+ text: Alloy.createStyle('index', { classes: 'text-gray-100' })
327
+ }
328
+ }
329
+
330
+ $.mainWindow.applyProperties(themes[theme].window)
331
+ $.titleLabel.applyProperties(themes[theme].text)
332
+ }
333
+ ```
334
+
335
+ ### Example 4: Dynamic Icon Grid
336
+
337
+ ```javascript
338
+ // controllers/dashboard/grid.js
339
+ function createIconGrid(items) {
340
+ const grid = $.UI.create('View', {
341
+ classes: ['w-screen', 'grid-cols-4', 'gap-4', 'p-4']
342
+ })
343
+
344
+ items.forEach(item => {
345
+ const icon = $.UI.create('View', {
346
+ classes: ['vertical', 'items-center']
347
+ })
348
+
349
+ const iconView = $.UI.create('Label', {
350
+ text: item.icon,
351
+ classes: ['text-3xl', 'mb-2', 'text-blue-500']
352
+ })
353
+
354
+ const label = $.UI.create('Label', {
355
+ text: item.label,
356
+ classes: ['text-xs', 'text-center', 'text-gray-600']
357
+ })
358
+
359
+ icon.add(iconView)
360
+ icon.add(label)
361
+ grid.add(icon)
362
+ })
363
+
364
+ return grid
365
+ }
366
+ ```
367
+
368
+ ---
369
+
370
+ ## Important Notes
371
+
372
+ ### PurgeTSS Processes Classes During Build
373
+
374
+ :::info HOW IT WORKS
375
+ When you use `$.UI.create()` or `Alloy.createStyle()` with classes:
376
+
377
+ 1. PurgeTSS scans your controllers for these class references
378
+ 2. It adds the classes to the generated `app.tss`
379
+ 3. At runtime, Alloy applies the styles to your components
380
+
381
+ This means you get **full PurgeTSS power** even with dynamic components!
382
+ :::
383
+
384
+ ### Class Verification
385
+
386
+ Just like with XML views, **always verify classes exist** before using them:
387
+
388
+ ```javascript
389
+ // ✅ CORRECT - Verified classes
390
+ classes: ['w-screen', 'h-auto', 'bg-white', 'rounded-lg']
391
+
392
+ // ❌ WRONG - These classes don't exist
393
+ classes: ['flex-row', 'justify-center', 'p-4'] // No flexbox, no p-* on View
394
+ ```
395
+
396
+ See [Class Index](class-index.md) for available classes.
397
+
398
+ ### Platform-Specific Best Practices
399
+
400
+ ```javascript
401
+ // Best practice: Use platform modifiers
402
+ classes: [
403
+ 'w-screen',
404
+ 'ios:mx-4', // iOS spacing
405
+ 'android:mx-2', // Android spacing
406
+ 'bg-white'
407
+ ]
408
+
409
+ // Avoid: Conditional logic in controllers
410
+ if (OS_IOS) {
411
+ classes.push('mx-4')
412
+ } else {
413
+ classes.push('mx-2')
414
+ }
415
+ ```
416
+
417
+ ---
418
+
419
+ ## Anti-Patterns to Avoid
420
+
421
+ ### ❌ Don't Use `Ti.UI.create()` with Manual Styles
422
+
423
+ ```javascript
424
+ // WRONG - Manual styling, no PurgeTSS benefits
425
+ const view = Ti.UI.createView({
426
+ width: Ti.UI.FILL,
427
+ height: Ti.UI.SIZE,
428
+ backgroundColor: '#ffffff',
429
+ borderRadius: 8
430
+ })
431
+ ```
432
+
433
+ ### ✅ Use `$.UI.create()` with PurgeTSS Classes
434
+
435
+ ```javascript
436
+ // CORRECT - Full PurgeTSS power
437
+ const view = $.UI.create('View', {
438
+ classes: ['w-screen', 'h-auto', 'bg-white', 'rounded-lg']
439
+ })
440
+ ```
441
+
442
+ ### ❌ Don't Mix Styles and Classes
443
+
444
+ ```javascript
445
+ // CONFUSING - Mix of styles and classes
446
+ const view = $.UI.create('View', {
447
+ backgroundColor: '#ffffff', // Manual style
448
+ classes: ['w-screen', 'rounded-lg'] // PurgeTSS classes
449
+ })
450
+ ```
451
+
452
+ ### ✅ Use Only Classes (or Only Styles)
453
+
454
+ ```javascript
455
+ // CORRECT - Pure PurgeTSS
456
+ const view = $.UI.create('View', {
457
+ classes: ['w-screen', 'h-auto', 'bg-white', 'rounded-lg']
458
+ })
459
+
460
+ // OR for truly dynamic/runtime-only values
461
+ const view = Ti.UI.createView({
462
+ backgroundColor: dynamicColor, // Runtime value
463
+ width: calculatedWidth
464
+ })
465
+ // Then apply PurgeTSS classes
466
+ view.applyProperties(Alloy.createStyle('index', {
467
+ classes: ['rounded-lg', 'm-4']
468
+ }))
469
+ ```
470
+
471
+ ---
472
+
473
+ ## Summary
474
+
475
+ | Method | Use Case | Syntax |
476
+ | ------------------------- | --------------------------- | ---------------------------------------------------- |
477
+ | **`$.UI.create()`** | Creating new components | `$.UI.create('View', { classes: ['bg-white'] })` |
478
+ | **`Alloy.createStyle()`** | Styling existing components | `Alloy.createStyle('view', { classes: 'bg-white' })` |
479
+ | **`applyProperties()`** | Apply style to component | `component.applyProperties(style)` |
480
+
481
+ :::tip REMEMBER
482
+ Both methods give you **full access to PurgeTSS utilities**:
483
+ - All color classes (`bg-*`, `text-*`, `border-*`)
484
+ - All spacing classes (`m-*`, `p-*`, `gap-*`)
485
+ - All layout classes (`horizontal`, `vertical`)
486
+ - All typography classes (`text-*`, `font-*`)
487
+ - Platform modifiers (`ios:*`, `android:*`)
488
+ - Arbitrary values (`w-(100px)`, `bg-(#ff0000)`)
489
+ :::