@maccesar/titools 2.2.4 → 2.2.8
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/README.md +23 -23
- package/lib/commands/update.js +4 -12
- package/package.json +1 -1
- package/skills/alloy-guides/SKILL.md +31 -31
- package/skills/alloy-guides/references/CONCEPTS.md +3 -3
- package/skills/alloy-guides/references/CONTROLLERS.md +1 -1
- package/skills/alloy-guides/references/MODELS.md +6 -6
- package/skills/alloy-guides/references/VIEWS_WITHOUT_CONTROLLERS.md +1 -1
- package/skills/alloy-guides/references/VIEWS_XML.md +1 -1
- package/skills/alloy-guides/references/WIDGETS.md +1 -1
- package/skills/alloy-howtos/SKILL.md +27 -27
- package/skills/alloy-howtos/references/best_practices.md +9 -9
- package/skills/alloy-howtos/references/cli_reference.md +14 -14
- package/skills/alloy-howtos/references/config_files.md +16 -16
- package/skills/alloy-howtos/references/custom_tags.md +16 -16
- package/skills/alloy-howtos/references/debugging_troubleshooting.md +11 -15
- package/skills/alloy-howtos/references/samples.md +19 -19
- package/skills/purgetss/SKILL.md +11 -1
- package/skills/purgetss/references/animation-system.md +1 -1
- package/skills/purgetss/references/cli-commands.md +3 -3
- package/skills/purgetss/references/customization-deep-dive.md +1 -1
- package/skills/purgetss/references/dynamic-component-creation.md +1 -1
- package/skills/purgetss/references/icon-fonts.md +4 -0
- package/skills/purgetss/references/installation-setup.md +8 -1
- package/skills/purgetss/references/migration-guide.md +4 -0
- package/skills/purgetss/references/tikit-components.md +193 -204
- package/skills/purgetss/references/ui-ux-design.md +1 -1
- package/skills/ti-expert/SKILL.md +78 -118
- package/skills/ti-expert/references/alloy-builtins.md +18 -18
- package/skills/ti-expert/references/alloy-structure.md +21 -21
- package/skills/ti-expert/references/anti-patterns.md +15 -15
- package/skills/ti-expert/references/cli-expert.md +15 -15
- package/skills/ti-expert/references/code-conventions.md +38 -38
- package/skills/ti-expert/references/contracts.md +8 -8
- package/skills/ti-expert/references/controller-patterns.md +14 -14
- package/skills/ti-expert/references/error-handling.md +11 -11
- package/skills/ti-expert/references/examples.md +12 -12
- package/skills/ti-expert/references/migration-patterns.md +24 -24
- package/skills/ti-expert/references/patterns.md +10 -10
- package/skills/ti-expert/references/performance-listview.md +16 -16
- package/skills/ti-expert/references/performance-optimization.md +41 -41
- package/skills/ti-expert/references/security-device.md +22 -22
- package/skills/ti-expert/references/security-fundamentals.md +19 -19
- package/skills/ti-expert/references/state-management.md +33 -33
- package/skills/ti-expert/references/testing-e2e-ci.md +25 -25
- package/skills/ti-expert/references/testing-unit.md +24 -24
- package/skills/ti-expert/references/theming.md +15 -15
- package/skills/ti-guides/SKILL.md +58 -60
- package/skills/ti-guides/references/advanced-data-and-images.md +33 -33
- package/skills/ti-guides/references/android-manifest.md +15 -15
- package/skills/ti-guides/references/app-distribution.md +70 -166
- package/skills/ti-guides/references/application-frameworks.md +96 -114
- package/skills/ti-guides/references/cli-reference.md +294 -294
- package/skills/ti-guides/references/coding-best-practices.md +42 -33
- package/skills/ti-guides/references/commonjs-advanced.md +57 -51
- package/skills/ti-guides/references/hello-world.md +36 -36
- package/skills/ti-guides/references/hyperloop-native-access.md +66 -66
- package/skills/ti-guides/references/javascript-primer.md +83 -101
- package/skills/ti-guides/references/reserved-words.md +9 -9
- package/skills/ti-guides/references/resources.md +75 -83
- package/skills/ti-guides/references/style-and-conventions.md +35 -28
- package/skills/ti-guides/references/tiapp-config.md +110 -74
- package/skills/ti-howtos/SKILL.md +88 -92
- package/skills/ti-howtos/references/android-platform-deep-dives.md +104 -104
- package/skills/ti-howtos/references/automation-fastlane-appium.md +39 -39
- package/skills/ti-howtos/references/buffer-codec-streams.md +60 -60
- package/skills/ti-howtos/references/cross-platform-development.md +115 -136
- package/skills/ti-howtos/references/debugging-profiling.md +167 -181
- package/skills/ti-howtos/references/extending-titanium.md +121 -121
- package/skills/ti-howtos/references/google-maps-v2.md +84 -82
- package/skills/ti-howtos/references/ios-map-kit.md +65 -60
- package/skills/ti-howtos/references/ios-platform-deep-dives.md +123 -123
- package/skills/ti-howtos/references/local-data-sources.md +79 -78
- package/skills/ti-howtos/references/location-and-maps.md +116 -120
- package/skills/ti-howtos/references/media-apis.md +87 -86
- package/skills/ti-howtos/references/notification-services.md +250 -260
- package/skills/ti-howtos/references/remote-data-sources.md +98 -93
- package/skills/ti-howtos/references/tutorials.md +226 -216
- package/skills/ti-howtos/references/using-modules.md +73 -102
- package/skills/ti-howtos/references/web-content-integration.md +101 -103
- package/skills/ti-howtos/references/webpack-build-pipeline.md +52 -44
- package/skills/ti-ui/SKILL.md +85 -85
- package/skills/ti-ui/references/accessibility-deep-dive.md +57 -57
- package/skills/ti-ui/references/animation-and-matrices.md +79 -79
- package/skills/ti-ui/references/application-structures.md +96 -99
- package/skills/ti-ui/references/custom-fonts-styling.md +99 -99
- package/skills/ti-ui/references/event-handling.md +58 -58
- package/skills/ti-ui/references/gestures.md +62 -64
- package/skills/ti-ui/references/icons-and-splash-screens.md +88 -88
- package/skills/ti-ui/references/layouts-and-positioning.md +87 -97
- package/skills/ti-ui/references/listviews-and-performance.md +107 -107
- package/skills/ti-ui/references/orientation.md +87 -88
- package/skills/ti-ui/references/platform-ui-android.md +87 -81
- package/skills/ti-ui/references/platform-ui-ios.md +63 -61
- package/skills/ti-ui/references/scrolling-views.md +29 -29
- package/skills/ti-ui/references/tableviews.md +56 -56
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
# Titanium Alloy
|
|
1
|
+
# Titanium Alloy anti-patterns
|
|
2
2
|
|
|
3
|
-
## 1. Inline
|
|
3
|
+
## 1. Inline styling instead of TSS
|
|
4
4
|
**Symptom:** Using inline attributes like `backgroundColor="#fff"` directly in XML views.
|
|
5
5
|
**Problem:** Inline attributes make theme changes impossible and scatter visual definitions across views.
|
|
6
6
|
**Solution:** Define styles in TSS files using IDs or class selectors.
|
|
7
7
|
|
|
8
|
-
## 2. Fat
|
|
8
|
+
## 2. Fat controllers
|
|
9
9
|
**Symptom:** Controllers with 100+ lines handling logic, API, and UI.
|
|
10
10
|
**Solution:** Delegate business logic to `lib/services/` and API calls to `lib/api/`.
|
|
11
11
|
|
|
12
|
-
## 3. Memory
|
|
12
|
+
## 3. Memory leaks (Missing Cleanup)
|
|
13
13
|
**Symptom:** Adding `Ti.App` or `Alloy.Collections` listeners without a `cleanup()` function.
|
|
14
14
|
**Solution:** Always implement `$.cleanup = cleanup` and remove listeners there.
|
|
15
15
|
|
|
16
|
-
## 4. Direct
|
|
16
|
+
## 4. Direct native module calls
|
|
17
17
|
**Symptom:** Calling `require('ti.module')` directly in a controller.
|
|
18
18
|
**Solution:** Wrap it in a service in `lib/services/` (e.g., `audioService.js`).
|
|
19
19
|
|
|
20
|
-
## 5. Direct
|
|
20
|
+
## 5. Direct controller navigation
|
|
21
21
|
**Symptom:** `Alloy.createController('name').getView().open()`.
|
|
22
22
|
**Solution:** Use a Navigation Service to centralize `open/close` and trigger the `cleanup()` function automatically.
|
|
23
23
|
|
|
24
|
-
## 6. Complex
|
|
24
|
+
## 6. Complex matrix animations
|
|
25
25
|
**Symptom:** Manual use of `Ti.UI.create2DMatrix()` for simple animations.
|
|
26
26
|
**Solution:** Use `Ti.UI.createAnimation()` for opacity, transform, and duration-based animations. Reserve 2D Matrix for complex multi-property transforms.
|
|
27
27
|
|
|
28
|
-
## 7. Hardcoded
|
|
28
|
+
## 7. Hardcoded strings & missing a11y
|
|
29
29
|
**Symptom:** `text="Login"` instead of `text="L('login')"`, or missing `accessibilityLabel`.
|
|
30
30
|
**Solution:** Always use i18n and accessibility properties.
|
|
31
31
|
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
|
|
36
36
|
---
|
|
37
37
|
|
|
38
|
-
## Titanium
|
|
38
|
+
## Titanium layout anti-patterns
|
|
39
39
|
|
|
40
|
-
## 9. Padding on
|
|
40
|
+
## 9. Padding on container views
|
|
41
41
|
**Symptom:** Setting `padding` on View, Window, ScrollView, or TableView.
|
|
42
42
|
**Problem:** Base container elements don't support padding in Titanium.
|
|
43
43
|
**Solution:** Use margins on children instead:
|
|
@@ -49,17 +49,17 @@
|
|
|
49
49
|
"#childLabel": { left: 16, top: 16, right: 16 }
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
## 10. Redundant
|
|
52
|
+
## 10. Redundant composite layout
|
|
53
53
|
**Symptom:** Adding `layout: 'composite'` to Views.
|
|
54
54
|
**Problem:** Composite (absolute positioning) is the DEFAULT layout. Setting it is redundant.
|
|
55
55
|
**Solution:** Omit `layout` for composite, only specify `layout: 'horizontal'` or `layout: 'vertical'` when needed.
|
|
56
56
|
|
|
57
|
-
## 11. Using `lib/`
|
|
57
|
+
## 11. Using `lib/` prefix in require statements
|
|
58
58
|
**Symptom:** `const service = require('lib/services/picsum')`
|
|
59
59
|
**Problem:** Alloy flattens the `lib/` folder during build. Files in `app/lib/services/` become `Resources/iphone/services/`.
|
|
60
60
|
**Solution:** Omit the `lib/` prefix: `const service = require('services/picsum')`
|
|
61
61
|
|
|
62
|
-
## 12. Wrong
|
|
62
|
+
## 12. Wrong window ID in controller
|
|
63
63
|
**Symptom:** Using `$.index.open()` when the Window has `id="mainWindow"`.
|
|
64
64
|
**Problem:** Alloy generates `$` references from XML IDs. If Window is `id="mainWindow"`, `$.index` doesn't exist.
|
|
65
65
|
**Solution:** Match the ID: `$.mainWindow.open()`
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
**Problem:** This API doesn't exist in Titanium. Causes "invalid method" error.
|
|
70
70
|
**Solution:** Use `Ti.UI.createAlertDialog` for simple messages, or create custom toast views.
|
|
71
71
|
|
|
72
|
-
## 14. Using
|
|
72
|
+
## 14. Using nonexistent iOS share APIs
|
|
73
73
|
**Symptom:** `Ti.UI.iOS.createActivityPopover` or `alloy/social` with wrong methods.
|
|
74
74
|
**Problem:** These APIs either don't exist or have changed. Causes runtime errors.
|
|
75
75
|
**Solution:**
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
|
|
79
79
|
---
|
|
80
80
|
|
|
81
|
-
## Quick
|
|
81
|
+
## Quick reference table
|
|
82
82
|
|
|
83
83
|
| Anti-Pattern | Why It Fails | Correct Approach |
|
|
84
84
|
| ----------------------- | ------------------------ | --------------------- |
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
# CLI
|
|
1
|
+
# CLI expert strategies & TiNy
|
|
2
2
|
|
|
3
3
|
Mastering the command line is essential for a Titanium expert. This guide covers advanced workflows, optimization techniques, and the use of **TiNy (`tn`)** for efficient development.
|
|
4
4
|
|
|
5
|
-
## The
|
|
5
|
+
## The expert workflow
|
|
6
6
|
|
|
7
7
|
An expert doesn't just run `ti build`. They optimize for speed, reliability, and automation.
|
|
8
8
|
|
|
9
|
-
### 1. The "
|
|
9
|
+
### 1. The "inner loop" optimization
|
|
10
10
|
Reduce the time between writing code and seeing it on the device.
|
|
11
11
|
|
|
12
12
|
- **LiveView**: Use `--liveview` for near-instant UI updates without full recompilation.
|
|
@@ -22,27 +22,27 @@ Reduce the time between writing code and seeing it on the device.
|
|
|
22
22
|
ti build -p ios --skip-js-minify
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
### 2. Precise
|
|
25
|
+
### 2. Precise cleaning
|
|
26
26
|
Don't use `ti clean` as a first resort (it's slow).
|
|
27
27
|
- **Targeted Clean**: If Alloy isn't reflecting changes, try deleting `Resources/` and `build/` manually or use `ti clean -p <platform>`.
|
|
28
|
-
- **Pre-Production**: Always run a full `ti clean` before a production/App Store build to
|
|
28
|
+
- **Pre-Production**: Always run a full `ti clean` before a production/App Store build to make sure no stale assets are included.
|
|
29
29
|
|
|
30
|
-
### 3. Advanced
|
|
30
|
+
### 3. Advanced debugging
|
|
31
31
|
- **Trace Logging**: Use `--log-level trace` when a build fails for mysterious reasons (e.g., a broken hook or native module issue).
|
|
32
32
|
- **Build Logs**: Check `build/build.log` for the full output of the last build process.
|
|
33
33
|
|
|
34
34
|
---
|
|
35
35
|
|
|
36
|
-
## TiNy (`tn`):
|
|
36
|
+
## TiNy (`tn`): the expert's power tool
|
|
37
37
|
|
|
38
38
|
**TiNy** is a modern CLI wrapper for Titanium SDK that drastically reduces keystrokes and manages complex build configurations through "recipes".
|
|
39
39
|
|
|
40
|
-
### Why
|
|
40
|
+
### Why experts use TiNy
|
|
41
41
|
- **Speed**: `tn ios` vs `ti build -p ios -T simulator`.
|
|
42
|
-
- **Consistency**: Recipes
|
|
42
|
+
- **Consistency**: Recipes make sure every team member builds with the same flags.
|
|
43
43
|
- **Device Management**: Easily target specific simulators/emulators by name.
|
|
44
44
|
|
|
45
|
-
### Quick
|
|
45
|
+
### Quick start
|
|
46
46
|
1. **Install**: `npm install -g tn`
|
|
47
47
|
2. **Repo**: https://github.com/jasonkneen/tn
|
|
48
48
|
3. **Generate Recipes**: Detect all connected devices/simulators.
|
|
@@ -55,7 +55,7 @@ Don't use `ti clean` as a first resort (it's slow).
|
|
|
55
55
|
tn pixel-8-pro-api-34
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
### Expert
|
|
58
|
+
### Expert recipes
|
|
59
59
|
Recipes can be flags or options. Multiple recipes can be combined.
|
|
60
60
|
|
|
61
61
|
| Command | Expansion |
|
|
@@ -66,7 +66,7 @@ Recipes can be flags or options. Multiple recipes can be combined.
|
|
|
66
66
|
| `tn playstore` | `--android --target dist-playstore` |
|
|
67
67
|
| `tn watch` | `--ios --launch-watch-app` |
|
|
68
68
|
|
|
69
|
-
### Customizing
|
|
69
|
+
### Customizing your workflow
|
|
70
70
|
- **Save Global Recipe**:
|
|
71
71
|
```bash
|
|
72
72
|
tn save my-debug --ios --simulator --log-level trace --skip-js-minify
|
|
@@ -76,7 +76,7 @@ Recipes can be flags or options. Multiple recipes can be combined.
|
|
|
76
76
|
tn project save release --playstore --keystore ./android/release.keystore
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
### Composition &
|
|
79
|
+
### Composition & placeholders
|
|
80
80
|
You can use `%s` as a placeholder in recipes for values:
|
|
81
81
|
```bash
|
|
82
82
|
tn save ci -b --pp-uuid <UUID> --distribution-name "<NAME>" --ah --installr --installr-release-notes %s
|
|
@@ -87,7 +87,7 @@ tn ci "Fixed login bug"
|
|
|
87
87
|
|
|
88
88
|
---
|
|
89
89
|
|
|
90
|
-
## Automation
|
|
90
|
+
## Automation integration
|
|
91
91
|
|
|
92
92
|
Experts automate their builds using `package.json` scripts, often combining `ti` or `tn` with other tools.
|
|
93
93
|
|
|
@@ -103,7 +103,7 @@ Experts automate their builds using `package.json` scripts, often combining `ti`
|
|
|
103
103
|
|
|
104
104
|
---
|
|
105
105
|
|
|
106
|
-
## Pro-
|
|
106
|
+
## Pro-tips
|
|
107
107
|
- **SDK Switching**: Use `-s <version>` to test your app against a specific SDK version without changing your global default.
|
|
108
108
|
- **Sim Focus**: Use `--no-sim-focus` if you want to keep your editor in focus while the simulator launches in the background.
|
|
109
109
|
- **Concurrent Builds**: You can often build for iOS and Android simultaneously in different terminal tabs if your machine has the resources.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# TSS
|
|
1
|
+
# TSS styling & code conventions
|
|
2
2
|
|
|
3
|
-
## Module
|
|
3
|
+
## Module system: CommonJS (NOT ES6 modules)
|
|
4
4
|
|
|
5
5
|
Titanium uses **CommonJS** for modules. Do NOT use ES6 `import`/`export`:
|
|
6
6
|
|
|
@@ -14,7 +14,7 @@ import { Navigation } from 'services/navigation'
|
|
|
14
14
|
export const Navigation = { /* ... */ }
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
## ES6+
|
|
17
|
+
## ES6+ features (Non-Module)
|
|
18
18
|
|
|
19
19
|
Use `const`, `let`, destructuring, and template literals. Prefer arrow functions for callbacks and traditional functions for main logic.
|
|
20
20
|
|
|
@@ -25,7 +25,7 @@ const loadUserData = (userId) => {
|
|
|
25
25
|
}
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
## No
|
|
28
|
+
## No semicolons
|
|
29
29
|
Omit semicolons at the end of lines (ASI handles it).
|
|
30
30
|
|
|
31
31
|
```javascript
|
|
@@ -35,7 +35,7 @@ const name = user.name
|
|
|
35
35
|
|
|
36
36
|
## Styling with TSS
|
|
37
37
|
|
|
38
|
-
### TSS
|
|
38
|
+
### TSS file organization
|
|
39
39
|
|
|
40
40
|
Every controller can have a matching TSS file. Alloy also supports a global `app.tss`.
|
|
41
41
|
|
|
@@ -49,11 +49,11 @@ app/styles/
|
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
**Style cascade (priority low → high):**
|
|
52
|
-
1. `app.tss`
|
|
53
|
-
2. `<controller>.tss`
|
|
52
|
+
1. `app.tss` , global base styles
|
|
53
|
+
2. `<controller>.tss` , controller-specific styles
|
|
54
54
|
3. Theme overrides (`app/themes/<name>/styles/`)
|
|
55
55
|
|
|
56
|
-
### Selector
|
|
56
|
+
### Selector types
|
|
57
57
|
|
|
58
58
|
```tss
|
|
59
59
|
/* Element selector — applies to ALL elements of this type */
|
|
@@ -79,7 +79,7 @@ app/styles/
|
|
|
79
79
|
| Class (`".card"`) | Reusable patterns (3+ uses) | Cards, buttons, inputs |
|
|
80
80
|
| ID (`"#name"`) | Unique element positioning | Specific layout needs |
|
|
81
81
|
|
|
82
|
-
### Class
|
|
82
|
+
### Class selectors in XML
|
|
83
83
|
|
|
84
84
|
```xml
|
|
85
85
|
<!-- Combine multiple classes -->
|
|
@@ -91,7 +91,7 @@ app/styles/
|
|
|
91
91
|
|
|
92
92
|
Classes defined in `app.tss` are available in every controller. Classes in `<controller>.tss` are only available in that controller.
|
|
93
93
|
|
|
94
|
-
### ID +
|
|
94
|
+
### ID + class combined
|
|
95
95
|
|
|
96
96
|
When an element has both an ID and classes, properties merge with ID taking priority:
|
|
97
97
|
|
|
@@ -108,7 +108,7 @@ When an element has both an ID and classes, properties merge with ID taking prio
|
|
|
108
108
|
<Button id="saveButton" class="btn-primary" title="L('save')" />
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
### Building a
|
|
111
|
+
### Building a design system in app.tss
|
|
112
112
|
|
|
113
113
|
Define reusable style classes for consistency:
|
|
114
114
|
|
|
@@ -162,7 +162,7 @@ Define reusable style classes for consistency:
|
|
|
162
162
|
}
|
|
163
163
|
```
|
|
164
164
|
|
|
165
|
-
### Complete
|
|
165
|
+
### Complete example
|
|
166
166
|
|
|
167
167
|
```xml
|
|
168
168
|
<!-- views/feature/list.xml -->
|
|
@@ -188,15 +188,15 @@ Define reusable style classes for consistency:
|
|
|
188
188
|
}
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
-
### Titanium
|
|
191
|
+
### Titanium layout rules
|
|
192
192
|
|
|
193
|
-
- Three layout modes: `layout: 'horizontal'`, `layout: 'vertical'`, and composite (default
|
|
194
|
-
- NO padding on container Views
|
|
193
|
+
- Three layout modes: `layout: 'horizontal'`, `layout: 'vertical'`, and composite (default , no `layout` needed)
|
|
194
|
+
- NO padding on container Views , use margins on children instead
|
|
195
195
|
- `width: Ti.UI.FILL` fills available space, `width: Ti.UI.SIZE` wraps content
|
|
196
196
|
- `height: Ti.UI.SIZE` is essential for vertical layouts with dynamic content
|
|
197
197
|
- Use percentage widths (`width: '50%'`) for proportional column layouts
|
|
198
198
|
|
|
199
|
-
## Platform &
|
|
199
|
+
## Platform & device modifiers
|
|
200
200
|
Use TSS platform modifiers instead of writing conditional logic in controllers.
|
|
201
201
|
|
|
202
202
|
```tss
|
|
@@ -205,7 +205,7 @@ Use TSS platform modifiers instead of writing conditional logic in controllers.
|
|
|
205
205
|
"#header[formFactor=tablet]": { top: 80 }
|
|
206
206
|
```
|
|
207
207
|
|
|
208
|
-
## applyProperties()
|
|
208
|
+
## applyProperties() pattern
|
|
209
209
|
Use `applyProperties()` to batch UI updates and minimize bridge crossings for properties not managed by classes.
|
|
210
210
|
|
|
211
211
|
```javascript
|
|
@@ -215,7 +215,7 @@ $.nameLabel.applyProperties({
|
|
|
215
215
|
})
|
|
216
216
|
```
|
|
217
217
|
|
|
218
|
-
## ListView
|
|
218
|
+
## ListView templates
|
|
219
219
|
Always use templates for performance. Never create views dynamically inside list rows.
|
|
220
220
|
|
|
221
221
|
```javascript
|
|
@@ -228,7 +228,7 @@ function renderUsers(users) {
|
|
|
228
228
|
}
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
-
## Memory
|
|
231
|
+
## Memory cleanup
|
|
232
232
|
Always remove listeners to avoid memory leaks. Implement a `cleanup` function.
|
|
233
233
|
|
|
234
234
|
```javascript
|
|
@@ -238,7 +238,7 @@ function cleanup() {
|
|
|
238
238
|
}
|
|
239
239
|
```
|
|
240
240
|
|
|
241
|
-
## i18n and
|
|
241
|
+
## i18n and accessibility (a11y)
|
|
242
242
|
Use `L()` for all text and always include `accessibilityLabel` for interactive elements.
|
|
243
243
|
|
|
244
244
|
```xml
|
|
@@ -246,7 +246,7 @@ Use `L()` for all text and always include `accessibilityLabel` for interactive e
|
|
|
246
246
|
<ImageView image="/images/user.png" accessibilityLabel="User Profile Picture" />
|
|
247
247
|
```
|
|
248
248
|
|
|
249
|
-
## Percentage-
|
|
249
|
+
## Percentage-based layouts
|
|
250
250
|
Use percentage widths in TSS for responsive column layouts.
|
|
251
251
|
|
|
252
252
|
```xml
|
|
@@ -262,9 +262,9 @@ Use percentage widths in TSS for responsive column layouts.
|
|
|
262
262
|
"#colRight": { width: '33.33%', backgroundColor: '#3b82f6' }
|
|
263
263
|
```
|
|
264
264
|
|
|
265
|
-
## Naming
|
|
265
|
+
## Naming conventions
|
|
266
266
|
|
|
267
|
-
### Files and
|
|
267
|
+
### Files and folders
|
|
268
268
|
```
|
|
269
269
|
app/
|
|
270
270
|
├── controllers/
|
|
@@ -286,7 +286,7 @@ app/
|
|
|
286
286
|
│ └── settings.xml
|
|
287
287
|
```
|
|
288
288
|
|
|
289
|
-
### Variables and
|
|
289
|
+
### Variables and functions
|
|
290
290
|
```javascript
|
|
291
291
|
// Constants: UPPER_SNAKE_CASE
|
|
292
292
|
const API_BASE_URL = 'https://api.example.com'
|
|
@@ -317,7 +317,7 @@ function onSearchChange(e) { /* ... */ }
|
|
|
317
317
|
function _calculateTotal(items) { /* ... */ }
|
|
318
318
|
```
|
|
319
319
|
|
|
320
|
-
### Classes and
|
|
320
|
+
### Classes and services
|
|
321
321
|
```javascript
|
|
322
322
|
// Classes: PascalCase
|
|
323
323
|
class UserService {
|
|
@@ -332,7 +332,7 @@ function createHTTPClient(config) { /* ... */ }
|
|
|
332
332
|
function createAnimationController() { /* ... */ }
|
|
333
333
|
```
|
|
334
334
|
|
|
335
|
-
### Events and
|
|
335
|
+
### Events and constants
|
|
336
336
|
```javascript
|
|
337
337
|
// Event names: namespace:action format
|
|
338
338
|
const Events = {
|
|
@@ -350,9 +350,9 @@ const ErrorCodes = {
|
|
|
350
350
|
}
|
|
351
351
|
```
|
|
352
352
|
|
|
353
|
-
## Import/Export
|
|
353
|
+
## Import/Export patterns
|
|
354
354
|
|
|
355
|
-
### Named
|
|
355
|
+
### Named exports (Preferred)
|
|
356
356
|
```javascript
|
|
357
357
|
// lib/api/userApi.js
|
|
358
358
|
exports.getUser = async function(id) { /* ... */ }
|
|
@@ -363,7 +363,7 @@ exports.deleteUser = async function(id) { /* ... */ }
|
|
|
363
363
|
const { getUser, updateUser } = require('api/userApi')
|
|
364
364
|
```
|
|
365
365
|
|
|
366
|
-
### Default
|
|
366
|
+
### Default export (For Classes/Singletons)
|
|
367
367
|
```javascript
|
|
368
368
|
// lib/services/logger.js
|
|
369
369
|
class Logger {
|
|
@@ -378,7 +378,7 @@ module.exports = new Logger()
|
|
|
378
378
|
const logger = require('services/logger')
|
|
379
379
|
```
|
|
380
380
|
|
|
381
|
-
### Mixed
|
|
381
|
+
### Mixed exports
|
|
382
382
|
```javascript
|
|
383
383
|
// lib/services/eventBus.js
|
|
384
384
|
const _ = require('alloy/underscore')._
|
|
@@ -411,7 +411,7 @@ exports.orderApi = require('./orderApi').orderApi
|
|
|
411
411
|
const { userApi, productApi } = require('api')
|
|
412
412
|
```
|
|
413
413
|
|
|
414
|
-
### CommonJS
|
|
414
|
+
### CommonJS compatibility
|
|
415
415
|
```javascript
|
|
416
416
|
// When using native modules that use require()
|
|
417
417
|
const SomeNativeModule = require('ti.somemodule')
|
|
@@ -424,7 +424,7 @@ exports.nativeService = {
|
|
|
424
424
|
}
|
|
425
425
|
```
|
|
426
426
|
|
|
427
|
-
## Async/Promise
|
|
427
|
+
## Async/Promise patterns
|
|
428
428
|
|
|
429
429
|
### Async/Await (Preferred)
|
|
430
430
|
```javascript
|
|
@@ -454,7 +454,7 @@ async function loadData() {
|
|
|
454
454
|
}
|
|
455
455
|
```
|
|
456
456
|
|
|
457
|
-
### Parallel
|
|
457
|
+
### Parallel requests
|
|
458
458
|
```javascript
|
|
459
459
|
// When requests are independent - run in parallel
|
|
460
460
|
async function loadDashboard() {
|
|
@@ -468,7 +468,7 @@ async function loadDashboard() {
|
|
|
468
468
|
}
|
|
469
469
|
```
|
|
470
470
|
|
|
471
|
-
### Sequential with
|
|
471
|
+
### Sequential with dependencies
|
|
472
472
|
```javascript
|
|
473
473
|
// When each request depends on the previous
|
|
474
474
|
async function processOrder(cartId) {
|
|
@@ -485,7 +485,7 @@ async function processOrder(cartId) {
|
|
|
485
485
|
}
|
|
486
486
|
```
|
|
487
487
|
|
|
488
|
-
### Error
|
|
488
|
+
### Error handling with specific catches
|
|
489
489
|
```javascript
|
|
490
490
|
async function login(email, password) {
|
|
491
491
|
try {
|
|
@@ -508,7 +508,7 @@ async function login(email, password) {
|
|
|
508
508
|
}
|
|
509
509
|
```
|
|
510
510
|
|
|
511
|
-
### Converting
|
|
511
|
+
### Converting callbacks to promises
|
|
512
512
|
```javascript
|
|
513
513
|
// Wrap Ti.Network.createHTTPClient in Promise
|
|
514
514
|
function httpGet(url) {
|
|
@@ -544,7 +544,7 @@ function takePhoto() {
|
|
|
544
544
|
}
|
|
545
545
|
```
|
|
546
546
|
|
|
547
|
-
### Debouncing
|
|
547
|
+
### Debouncing async operations
|
|
548
548
|
```javascript
|
|
549
549
|
// Useful for search, auto-save, etc.
|
|
550
550
|
let searchTimeout = null
|
|
@@ -575,7 +575,7 @@ function cleanup() {
|
|
|
575
575
|
}
|
|
576
576
|
```
|
|
577
577
|
|
|
578
|
-
### Retry
|
|
578
|
+
### Retry pattern
|
|
579
579
|
```javascript
|
|
580
580
|
async function fetchWithRetry(fn, maxRetries = 3) {
|
|
581
581
|
let lastError
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# Layer
|
|
1
|
+
# Layer contracts & interfaces
|
|
2
2
|
|
|
3
3
|
Contracts define the input/output specifications between layers, ensuring consistent communication and easy testing.
|
|
4
4
|
|
|
5
|
-
## API
|
|
5
|
+
## API layer contracts
|
|
6
6
|
|
|
7
7
|
```javascript
|
|
8
8
|
// lib/api/userApi.js
|
|
@@ -73,7 +73,7 @@ exports.userApi = {
|
|
|
73
73
|
}
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
## Service
|
|
76
|
+
## Service layer contracts
|
|
77
77
|
|
|
78
78
|
```javascript
|
|
79
79
|
// lib/services/authService.js
|
|
@@ -123,7 +123,7 @@ exports.AuthService = {
|
|
|
123
123
|
}
|
|
124
124
|
```
|
|
125
125
|
|
|
126
|
-
## Controller
|
|
126
|
+
## Controller contracts
|
|
127
127
|
|
|
128
128
|
Document expected inputs and outputs for each controller:
|
|
129
129
|
|
|
@@ -167,7 +167,7 @@ function init() {
|
|
|
167
167
|
$.cleanup = cleanup
|
|
168
168
|
```
|
|
169
169
|
|
|
170
|
-
## Navigation
|
|
170
|
+
## Navigation service contract
|
|
171
171
|
|
|
172
172
|
```javascript
|
|
173
173
|
// lib/services/navigation.js
|
|
@@ -210,7 +210,7 @@ exports.Navigation = {
|
|
|
210
210
|
}
|
|
211
211
|
```
|
|
212
212
|
|
|
213
|
-
## Helper
|
|
213
|
+
## Helper contracts
|
|
214
214
|
|
|
215
215
|
```javascript
|
|
216
216
|
// lib/helpers/formatters.js
|
|
@@ -242,7 +242,7 @@ exports.Formatters = {
|
|
|
242
242
|
}
|
|
243
243
|
```
|
|
244
244
|
|
|
245
|
-
## Event
|
|
245
|
+
## Event bus contract
|
|
246
246
|
|
|
247
247
|
```javascript
|
|
248
248
|
// lib/services/eventBus.js
|
|
@@ -271,7 +271,7 @@ exports.Events = {
|
|
|
271
271
|
}
|
|
272
272
|
```
|
|
273
273
|
|
|
274
|
-
## Contract
|
|
274
|
+
## Contract enforcement tips
|
|
275
275
|
|
|
276
276
|
1. **Always validate `$.args`** at controller initialization
|
|
277
277
|
2. **Use TypeScript JSDoc** for IDE autocompletion and error detection
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
# Alloy
|
|
1
|
+
# Alloy controller patterns
|
|
2
2
|
|
|
3
|
-
## Titanium
|
|
3
|
+
## Titanium layout rules
|
|
4
4
|
|
|
5
5
|
- Use `layout: 'horizontal'` for left-to-right
|
|
6
6
|
- Use `layout: 'vertical'` for top-to-bottom
|
|
7
|
-
- Omit `layout` for composite (absolute positioning
|
|
7
|
+
- Omit `layout` for composite (absolute positioning, the default)
|
|
8
8
|
- Use margins on children instead of padding on parent
|
|
9
9
|
|
|
10
10
|
> For a complete View + TSS + Controller example, see the Quick Start in SKILL.md.
|
|
11
11
|
|
|
12
|
-
## Animation
|
|
12
|
+
## Animation usage
|
|
13
13
|
|
|
14
14
|
Use `Ti.UI.createAnimation()` for UI transitions.
|
|
15
15
|
|
|
@@ -36,7 +36,7 @@ function hide(callback) {
|
|
|
36
36
|
}
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
## Dynamic
|
|
39
|
+
## Dynamic styling
|
|
40
40
|
|
|
41
41
|
To change styles dynamically, use `applyProperties()` to batch updates.
|
|
42
42
|
|
|
@@ -49,7 +49,7 @@ function setStatus(isActive) {
|
|
|
49
49
|
}
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
## Percentage-
|
|
52
|
+
## Percentage-based layouts
|
|
53
53
|
|
|
54
54
|
Use percentage widths in TSS for responsive column layouts.
|
|
55
55
|
|
|
@@ -66,7 +66,7 @@ Use percentage widths in TSS for responsive column layouts.
|
|
|
66
66
|
"#colRight": { height: 80, width: '33.33%', backgroundColor: '#dbeafe' }
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
## Controller
|
|
69
|
+
## Controller lifecycle patterns
|
|
70
70
|
|
|
71
71
|
Show init, focus, blur, close lifecycle:
|
|
72
72
|
```javascript
|
|
@@ -102,7 +102,7 @@ function cleanup() {
|
|
|
102
102
|
$.cleanup = cleanup
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
## Form
|
|
105
|
+
## Form handling patterns
|
|
106
106
|
|
|
107
107
|
```xml
|
|
108
108
|
<!-- views/user/edit.xml -->
|
|
@@ -206,7 +206,7 @@ function setLoading(isLoading) {
|
|
|
206
206
|
}
|
|
207
207
|
```
|
|
208
208
|
|
|
209
|
-
## Loading
|
|
209
|
+
## Loading state patterns
|
|
210
210
|
|
|
211
211
|
```xml
|
|
212
212
|
<!-- Skeleton loading pattern -->
|
|
@@ -261,7 +261,7 @@ async function loadData() {
|
|
|
261
261
|
}
|
|
262
262
|
```
|
|
263
263
|
|
|
264
|
-
## Modal and
|
|
264
|
+
## Modal and dialog patterns
|
|
265
265
|
|
|
266
266
|
```javascript
|
|
267
267
|
// AlertDialog
|
|
@@ -325,7 +325,7 @@ function openModal(route, params) {
|
|
|
325
325
|
}
|
|
326
326
|
```
|
|
327
327
|
|
|
328
|
-
##
|
|
328
|
+
## Tabgroup pattern
|
|
329
329
|
|
|
330
330
|
```xml
|
|
331
331
|
<!-- views/main.xml -->
|
|
@@ -366,7 +366,7 @@ function updateNotificationBadge(count) {
|
|
|
366
366
|
}
|
|
367
367
|
```
|
|
368
368
|
|
|
369
|
-
##
|
|
369
|
+
## Navigationwindow pattern (iOS)
|
|
370
370
|
|
|
371
371
|
```xml
|
|
372
372
|
<!-- views/index.xml -->
|
|
@@ -403,7 +403,7 @@ function closeWindow(window, animated = true) {
|
|
|
403
403
|
}
|
|
404
404
|
```
|
|
405
405
|
|
|
406
|
-
##
|
|
406
|
+
## Searchbar with ListView
|
|
407
407
|
|
|
408
408
|
```xml
|
|
409
409
|
<!-- views/contacts/list.xml -->
|
|
@@ -501,7 +501,7 @@ function cleanup() {
|
|
|
501
501
|
$.cleanup = cleanup
|
|
502
502
|
```
|
|
503
503
|
|
|
504
|
-
## Pull-to-
|
|
504
|
+
## Pull-to-refresh pattern
|
|
505
505
|
|
|
506
506
|
```xml
|
|
507
507
|
<ListView id="listView">
|