@maccesar/titools 2.2.4 → 2.2.9
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/agents/ti-pro.md +17 -17
- package/lib/commands/update.js +6 -14
- package/lib/downloader.js +17 -2
- 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,11 +1,11 @@
|
|
|
1
|
-
# Unit
|
|
1
|
+
# Unit testing guide for Titanium + Alloy
|
|
2
2
|
|
|
3
3
|
> **OPTIONAL - Advanced Topic**
|
|
4
4
|
> This guide covers automated testing, which is OPTIONAL for Titanium/Alloy projects.
|
|
5
5
|
> Testing is useful for teams practicing CI/CD, projects with complex business logic, or refactoring confidence.
|
|
6
6
|
> If you prefer manual testing on device, you can safely skip this guide.
|
|
7
7
|
|
|
8
|
-
## What
|
|
8
|
+
## What can be tested (Without Compiling)
|
|
9
9
|
|
|
10
10
|
**Pure JavaScript Logic:**
|
|
11
11
|
- Services (authService, navigationService, etc.)
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
- Business logic (calculations, data transformations)
|
|
14
14
|
- Models (with mocked database)
|
|
15
15
|
|
|
16
|
-
## What
|
|
16
|
+
## What cannot be easily tested
|
|
17
17
|
|
|
18
18
|
**Requires Compiled App:**
|
|
19
19
|
- Controllers (UI interactions)
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
|
|
24
24
|
---
|
|
25
25
|
|
|
26
|
-
## Testing
|
|
26
|
+
## Testing philosophy
|
|
27
27
|
|
|
28
28
|
**Test behavior, not implementation.** Focus on what the code does from the outside, not how it achieves it internally.
|
|
29
29
|
|
|
30
|
-
## Project
|
|
30
|
+
## Project structure
|
|
31
31
|
|
|
32
32
|
```
|
|
33
33
|
app/
|
|
@@ -52,9 +52,9 @@ app/
|
|
|
52
52
|
│ │ └── setup.js # Test environment setup
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
## Writing
|
|
55
|
+
## Writing testable code
|
|
56
56
|
|
|
57
|
-
### Dependency
|
|
57
|
+
### Dependency injection for testability
|
|
58
58
|
|
|
59
59
|
```javascript
|
|
60
60
|
// BAD: Hard to test - direct dependency
|
|
@@ -86,7 +86,7 @@ describe('getUser', () => {
|
|
|
86
86
|
})
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
## Unit
|
|
89
|
+
## Unit testing services
|
|
90
90
|
|
|
91
91
|
```javascript
|
|
92
92
|
// specs/unit/services/authService.spec.js
|
|
@@ -147,7 +147,7 @@ describe('AuthService', () => {
|
|
|
147
147
|
})
|
|
148
148
|
```
|
|
149
149
|
|
|
150
|
-
## Unit
|
|
150
|
+
## Unit testing helpers
|
|
151
151
|
|
|
152
152
|
```javascript
|
|
153
153
|
// specs/unit/helpers/i18n.spec.js
|
|
@@ -184,7 +184,7 @@ describe('i18n Helper', () => {
|
|
|
184
184
|
})
|
|
185
185
|
```
|
|
186
186
|
|
|
187
|
-
## Integration
|
|
187
|
+
## Integration testing controllers
|
|
188
188
|
|
|
189
189
|
```javascript
|
|
190
190
|
// specs/integration/controllers/login.spec.js
|
|
@@ -270,7 +270,7 @@ describe('Login Controller', () => {
|
|
|
270
270
|
})
|
|
271
271
|
```
|
|
272
272
|
|
|
273
|
-
## Mock
|
|
273
|
+
## Mock factory
|
|
274
274
|
|
|
275
275
|
```javascript
|
|
276
276
|
// lib/testing/mocks.js
|
|
@@ -326,7 +326,7 @@ exports.Mocks = {
|
|
|
326
326
|
}
|
|
327
327
|
```
|
|
328
328
|
|
|
329
|
-
## Test
|
|
329
|
+
## Test helper functions
|
|
330
330
|
|
|
331
331
|
```javascript
|
|
332
332
|
// lib/testing/helpers.js
|
|
@@ -373,7 +373,7 @@ exports.TestHelpers = {
|
|
|
373
373
|
}
|
|
374
374
|
```
|
|
375
375
|
|
|
376
|
-
## Test
|
|
376
|
+
## Test setup configuration
|
|
377
377
|
|
|
378
378
|
```javascript
|
|
379
379
|
// lib/testing/setup.js
|
|
@@ -396,7 +396,7 @@ afterAll(() => {
|
|
|
396
396
|
})
|
|
397
397
|
```
|
|
398
398
|
|
|
399
|
-
## Running
|
|
399
|
+
## Running tests
|
|
400
400
|
|
|
401
401
|
```bash
|
|
402
402
|
# Run specific test suite
|
|
@@ -409,18 +409,18 @@ titanium test --coverage
|
|
|
409
409
|
titanium test --specs app/specs/unit/services/authService.spec.js
|
|
410
410
|
```
|
|
411
411
|
|
|
412
|
-
## Anti-
|
|
412
|
+
## Anti-patterns to avoid
|
|
413
413
|
|
|
414
|
-
| Anti-Pattern
|
|
414
|
+
| Anti-Pattern | Problem | Solution |
|
|
415
415
|
| -------------------------- | ------------------------------ | ------------------------------- |
|
|
416
|
-
| Testing private methods
|
|
417
|
-
| Mocking everything
|
|
418
|
-
| No cleanup in tests
|
|
419
|
-
| Testing XML/TSS
|
|
420
|
-
| Hard dependencies
|
|
421
|
-
| Shared state between tests | Flaky tests
|
|
422
|
-
|
|
423
|
-
## Test
|
|
416
|
+
| Testing private methods | Breaks on refactoring | Test public interface only |
|
|
417
|
+
| Mocking everything | Tests pass, code fails | Mock only external dependencies |
|
|
418
|
+
| No cleanup in tests | Memory leaks, interference | Always cleanup in afterEach |
|
|
419
|
+
| Testing XML/TSS | Fragile, implementation detail | Test rendered behavior instead |
|
|
420
|
+
| Hard dependencies | Untestable code | Use dependency injection |
|
|
421
|
+
| Shared state between tests | Flaky tests | Reset state in beforeEach |
|
|
422
|
+
|
|
423
|
+
## Test checklist
|
|
424
424
|
|
|
425
425
|
Before committing code, verify:
|
|
426
426
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
# Theming &
|
|
1
|
+
# Theming & dark mode
|
|
2
2
|
|
|
3
|
-
## Alloy
|
|
3
|
+
## Alloy theme system
|
|
4
4
|
|
|
5
5
|
Alloy has a built-in theme system via the `app/themes/` folder. Themes override views, styles, and assets without modifying originals.
|
|
6
6
|
|
|
7
|
-
### Theme
|
|
7
|
+
### Theme folder structure
|
|
8
8
|
|
|
9
9
|
```
|
|
10
10
|
app/
|
|
@@ -26,7 +26,7 @@ app/
|
|
|
26
26
|
├── config.json
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
### Activating a
|
|
29
|
+
### Activating a theme
|
|
30
30
|
|
|
31
31
|
Set the theme in `config.json`:
|
|
32
32
|
|
|
@@ -45,7 +45,7 @@ Set the theme in `config.json`:
|
|
|
45
45
|
Alloy themes are applied at **build time**. You cannot switch themes at runtime using this system alone. For runtime switching, use the Dynamic Theming approach below.
|
|
46
46
|
:::
|
|
47
47
|
|
|
48
|
-
### Theme
|
|
48
|
+
### Theme cascade
|
|
49
49
|
|
|
50
50
|
When a theme is active, Alloy merges files in this order:
|
|
51
51
|
1. `app/styles/app.tss` (base)
|
|
@@ -53,15 +53,15 @@ When a theme is active, Alloy merges files in this order:
|
|
|
53
53
|
3. `app/styles/<controller>.tss` (controller-specific)
|
|
54
54
|
4. `app/themes/<theme>/styles/<controller>.tss` (theme + controller override)
|
|
55
55
|
|
|
56
|
-
Theme files **merge** with base files
|
|
56
|
+
Theme files **merge** with base files , you only need to include properties you want to override.
|
|
57
57
|
|
|
58
58
|
---
|
|
59
59
|
|
|
60
|
-
## Dynamic
|
|
60
|
+
## Dynamic theming with Alloy.Globals
|
|
61
61
|
|
|
62
62
|
For runtime theme switching (including Dark Mode), use `Alloy.Globals` as a centralized color palette.
|
|
63
63
|
|
|
64
|
-
### Step 1:
|
|
64
|
+
### Step 1: define color palette
|
|
65
65
|
|
|
66
66
|
```javascript
|
|
67
67
|
// alloy.js
|
|
@@ -98,7 +98,7 @@ Alloy.Globals.theme = themes[savedTheme]
|
|
|
98
98
|
Alloy.Globals.themeName = savedTheme
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
-
### Step 2:
|
|
101
|
+
### Step 2: use in TSS with Alloy.Globals
|
|
102
102
|
|
|
103
103
|
```tss
|
|
104
104
|
/* app.tss - Global base styles using theme colors */
|
|
@@ -134,7 +134,7 @@ Alloy.Globals.themeName = savedTheme
|
|
|
134
134
|
}
|
|
135
135
|
```
|
|
136
136
|
|
|
137
|
-
### Step 3:
|
|
137
|
+
### Step 3: theme switching service
|
|
138
138
|
|
|
139
139
|
```javascript
|
|
140
140
|
// lib/services/themeService.js
|
|
@@ -176,7 +176,7 @@ exports.ThemeService = {
|
|
|
176
176
|
}
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
-
### Step 4:
|
|
179
|
+
### Step 4: respond to theme changes in controllers
|
|
180
180
|
|
|
181
181
|
:::warning Theme change requires UI rebuild
|
|
182
182
|
Since TSS is applied at controller creation time, changing `Alloy.Globals.theme` does NOT retroactively update already-rendered views. You must manually update visible elements or restart the root controller.
|
|
@@ -233,7 +233,7 @@ $.cleanup = cleanup
|
|
|
233
233
|
|
|
234
234
|
---
|
|
235
235
|
|
|
236
|
-
## System
|
|
236
|
+
## System dark mode detection
|
|
237
237
|
|
|
238
238
|
### iOS 13+ / Android 10+
|
|
239
239
|
|
|
@@ -263,7 +263,7 @@ exports.ThemeService = {
|
|
|
263
263
|
}
|
|
264
264
|
```
|
|
265
265
|
|
|
266
|
-
### Semantic
|
|
266
|
+
### Semantic colors (Cross-Platform)
|
|
267
267
|
|
|
268
268
|
Titanium provides a cross-platform semantic colors API for Dark Mode support. Define colors in a `semantic.colors.json` file:
|
|
269
269
|
|
|
@@ -329,7 +329,7 @@ $.container.backgroundColor = 'backgroundColor';
|
|
|
329
329
|
|
|
330
330
|
---
|
|
331
331
|
|
|
332
|
-
## Reusable
|
|
332
|
+
## Reusable style classes pattern
|
|
333
333
|
|
|
334
334
|
Define a library of reusable TSS classes in `app.tss` for consistency across the app:
|
|
335
335
|
|
|
@@ -410,7 +410,7 @@ Define a library of reusable TSS classes in `app.tss` for consistency across the
|
|
|
410
410
|
".mx-lg": { left: 24, right: 24 }
|
|
411
411
|
```
|
|
412
412
|
|
|
413
|
-
### Using
|
|
413
|
+
### Using style classes in views
|
|
414
414
|
|
|
415
415
|
```xml
|
|
416
416
|
<Alloy>
|
|
@@ -5,77 +5,75 @@ argument-hint: "[topic]"
|
|
|
5
5
|
allowed-tools: Read, Grep, Glob, Edit, Write, Bash(node *)
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
# Titanium SDK
|
|
8
|
+
# Titanium SDK guide expert
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Use this skill to keep Titanium projects aligned with TiDev standards for stability, performance, and cross-platform behavior.
|
|
11
11
|
|
|
12
|
-
## Project
|
|
12
|
+
## Project detection
|
|
13
13
|
|
|
14
|
-
:::info
|
|
15
|
-
This skill
|
|
14
|
+
:::info Auto-detects Titanium projects
|
|
15
|
+
This skill auto-detects Titanium projects. No manual command is needed.
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
**Titanium project indicator:**
|
|
17
|
+
Titanium project indicator:
|
|
20
18
|
- `tiapp.xml` file (definitive indicator)
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
20
|
+
Applies to both:
|
|
21
|
+
- Alloy projects (`app/` folder)
|
|
22
|
+
- Classic projects (`Resources/` folder)
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
24
|
+
Behavior:
|
|
25
|
+
- If a Titanium project is detected, provide official Titanium SDK guidance, memory management best practices, and app distribution help.
|
|
26
|
+
- If not detected, say this skill is only for Titanium projects.
|
|
29
27
|
:::
|
|
30
28
|
|
|
31
|
-
## Core
|
|
32
|
-
|
|
33
|
-
1.
|
|
34
|
-
2.
|
|
35
|
-
3.
|
|
36
|
-
4.
|
|
37
|
-
5.
|
|
38
|
-
|
|
39
|
-
## Procedural
|
|
40
|
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
-
|
|
45
|
-
|
|
46
|
-
## Reference
|
|
47
|
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
-
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
-
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
-
|
|
60
|
-
-
|
|
61
|
-
-
|
|
62
|
-
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
|
|
66
|
-
## Related
|
|
29
|
+
## Core workflow
|
|
30
|
+
|
|
31
|
+
1. Validate the project follows a modular pattern (CommonJS or Alloy).
|
|
32
|
+
2. Ensure global listeners are removed and heavy objects are nulled during cleanup.
|
|
33
|
+
3. Cache frequently accessed native properties to reduce bridge crossings.
|
|
34
|
+
4. Use Hyperloop for specialized native functionality and handle casting and threading correctly.
|
|
35
|
+
5. Use transactions for database work and manage image memory footprints.
|
|
36
|
+
|
|
37
|
+
## Procedural rules
|
|
38
|
+
|
|
39
|
+
- Always remove `Ti.App` and `Ti.Geolocation` listeners during controller cleanup.
|
|
40
|
+
- Do not access `Ti.Platform` or `Ti.DisplayCaps` inside loops. Store values in local variables.
|
|
41
|
+
- Concatenate Hyperloop selectors accurately (for example, `addAttribute:value:range:` -> `addAttributeValueRange`).
|
|
42
|
+
- Close resultsets and database handles after every transaction block.
|
|
43
|
+
|
|
44
|
+
## Reference guides
|
|
45
|
+
|
|
46
|
+
- Hello World (references/hello-world.md): project creation, structure, and getting started with Alloy or Classic Titanium.
|
|
47
|
+
- JavaScript Primer (references/javascript-primer.md): JavaScript fundamentals, learning resources, best practices, and ES6+ features.
|
|
48
|
+
- Application Frameworks (references/application-frameworks.md): Alloy vs Classic Titanium, architectural patterns, and framework selection.
|
|
49
|
+
- Coding Best Practices (references/coding-best-practices.md): memory leaks, bridge efficiency, event naming, security, and lazy loading.
|
|
50
|
+
- CommonJS Advanced (references/commonjs-advanced.md): stateful modules, caching, ES6+ support, and antipatterns.
|
|
51
|
+
- Advanced Data & Images (references/advanced-data-and-images.md): SQLite transactions and image memory optimization.
|
|
52
|
+
- Hyperloop Native Access (references/hyperloop-native-access.md): Objective-C/Swift/Java syntax, casting, debugging, XIB/Storyboards.
|
|
53
|
+
- Style & Conventions (references/style-and-conventions.md): naming standards and formatting rules.
|
|
54
|
+
- Reserved Words (references/reserved-words.md): ECMAScript, iOS, and Alloy reserved keywords to avoid.
|
|
55
|
+
- Alloy CLI Reference (references/alloy-cli-advanced.md): extract-i18n, code generation, and build hooks.
|
|
56
|
+
- Alloy Data Mastery (references/alloy-data-mastery.md): sync adapters, data binding, and Backbone collections.
|
|
57
|
+
- Alloy Widgets & Themes (references/alloy-widgets-and-themes.md): widget structure, styling priorities, and theming.
|
|
58
|
+
- Android Manifest (references/android-manifest.md): custom AndroidManifest.xml, permissions, and manifest merge.
|
|
59
|
+
- App Distribution (references/app-distribution.md): Google Play (APK/AAB), App Store (IPA), certificates, provisioning, and deployment.
|
|
60
|
+
- tiapp.xml Configuration (references/tiapp-config.md): complete reference for tiapp.xml and timodule.xml, including all elements, properties, and platform-specific settings.
|
|
61
|
+
- CLI Reference (references/cli-reference.md): Titanium CLI commands, options, tasks, configuration, and build processes.
|
|
62
|
+
- Resources (references/resources.md): community support, modules, sample code, Slack, and learning materials.
|
|
63
|
+
|
|
64
|
+
## Related skills
|
|
67
65
|
|
|
68
66
|
For tasks beyond SDK fundamentals, use these complementary skills:
|
|
69
67
|
|
|
70
|
-
| Task
|
|
71
|
-
|
|
|
72
|
-
| Project architecture, services, patterns | `ti-expert`
|
|
73
|
-
| Native features (location, push, media)
|
|
74
|
-
| Alloy CLI, configuration, debugging
|
|
75
|
-
| UI layouts, ListViews, gestures
|
|
68
|
+
| Task | Use this skill |
|
|
69
|
+
| --- | --- |
|
|
70
|
+
| Project architecture, services, patterns | `ti-expert` |
|
|
71
|
+
| Native features (location, push, media) | `ti-howtos` |
|
|
72
|
+
| Alloy CLI, configuration, debugging | `alloy-howtos` |
|
|
73
|
+
| UI layouts, ListViews, gestures | `ti-ui` |
|
|
76
74
|
|
|
77
|
-
## Response
|
|
75
|
+
## Response format
|
|
78
76
|
|
|
79
|
-
1.
|
|
80
|
-
2.
|
|
81
|
-
3.
|
|
77
|
+
1. Technical recommendation: cite the specific TiDev best practice.
|
|
78
|
+
2. Optimized implementation: provide modern ES6+ code without semicolons.
|
|
79
|
+
3. Rationale: briefly explain the performance or memory impact.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# Advanced
|
|
1
|
+
# Advanced database and image best practices
|
|
2
2
|
|
|
3
|
-
## 1. SQLite
|
|
3
|
+
## 1. SQLite optimization
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
-
|
|
5
|
+
- Close result sets and the database after each operation to avoid locks and memory growth. SQLite allows one writer at a time, and leaving a connection open after `INSERT` or `UPDATE` can trigger `DatabaseObjectNotClosed` on the next write.
|
|
6
|
+
- Use transactions for batch inserts. If any statement fails, SQLite rolls back the entire batch.
|
|
7
7
|
```javascript
|
|
8
8
|
const db = Ti.Database.open('myDatabase');
|
|
9
9
|
db.execute('BEGIN');
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
db.execute('COMMIT');
|
|
14
14
|
db.close();
|
|
15
15
|
```
|
|
16
|
-
-
|
|
17
|
-
-
|
|
16
|
+
- Do not ship large pre-populated databases. Ship a small skeleton and download data on first boot to reduce IPA/APK size. The `Resources` directory is read-only, so installing a database copies it to `applicationDataDirectory`, which creates two copies on the device.
|
|
17
|
+
- Android note: in Android 2.2 and earlier, the installer could not uncompress assets over 1 MB. One workaround was to rename the file with a `.mp3` extension to prevent `aapt` compression.
|
|
18
18
|
|
|
19
|
-
### Database
|
|
19
|
+
### Database version management
|
|
20
20
|
|
|
21
|
-
Store a version number in your database
|
|
21
|
+
Store a version number in your database so you can detect upgrades and run migrations. If you do not have a version table, use `PRAGMA TABLE_INFO` to detect column presence:
|
|
22
22
|
|
|
23
23
|
```javascript
|
|
24
24
|
const addColumn = (dbname, tblName, newFieldName, colSpec) => {
|
|
@@ -41,30 +41,30 @@ const addColumn = (dbname, tblName, newFieldName, colSpec) => {
|
|
|
41
41
|
|
|
42
42
|
---
|
|
43
43
|
|
|
44
|
-
## 2. Image
|
|
44
|
+
## 2. Image format selection
|
|
45
45
|
|
|
46
46
|
Choose the right format for each use case:
|
|
47
47
|
|
|
48
|
-
| Format | Compression | Best
|
|
49
|
-
|
|
|
50
|
-
|
|
|
51
|
-
|
|
|
52
|
-
|
|
|
48
|
+
| Format | Compression | Best for | Avoid for |
|
|
49
|
+
| --- | --- | --- | --- |
|
|
50
|
+
| PNG | Lossless | Icons, text, line art, buttons | Photos (large files) |
|
|
51
|
+
| JPG | Lossy | Photographs | Text, icons, line drawings (artifacts) |
|
|
52
|
+
| GIF | Lossless (256 colors) | Rare cases | Most cases (limited colors, animated GIF not supported everywhere) |
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
For flip-book animations, use `ImageView.images` with an array of PNG or optimized JPG files instead of animated GIFs.
|
|
55
55
|
|
|
56
56
|
---
|
|
57
57
|
|
|
58
|
-
## 3. Image
|
|
58
|
+
## 3. Image memory management
|
|
59
59
|
|
|
60
|
-
-
|
|
60
|
+
- A JPG is small on disk but expands to `width * height * 3 bytes` in RAM. Each pixel uses 24 bits (8 bits per R/G/B channel).
|
|
61
61
|
- Example: `(640 × 480 × 3) / 1024 = 900 KB` in memory for a single image
|
|
62
62
|
- Device RAM available to your app can be as low as 12 MB, shared with your code and the Titanium framework
|
|
63
|
-
-
|
|
64
|
-
- `view.remove(imageView)`
|
|
65
|
-
- `imageView = null`
|
|
66
|
-
-
|
|
67
|
-
-
|
|
63
|
+
- Unloading:
|
|
64
|
+
- `view.remove(imageView)` removes it from the view hierarchy and lets the OS free memory
|
|
65
|
+
- `imageView = null` releases the native proxy object
|
|
66
|
+
- Resizing: resize images to their display dimensions using `imageAsResized` or `imageAsCropped` (both on `Ti.Blob`) before setting the `image` property. Do not display a 1024×768 image on a 640×480 screen.
|
|
67
|
+
- Placeholder: set `defaultImage` on ImageView to show a local placeholder while a remote image downloads:
|
|
68
68
|
```javascript
|
|
69
69
|
const imageView = Ti.UI.createImageView({
|
|
70
70
|
image: 'https://example.com/photo.jpg',
|
|
@@ -76,12 +76,12 @@ Choose the right format for each use case:
|
|
|
76
76
|
|
|
77
77
|
---
|
|
78
78
|
|
|
79
|
-
## 4. Image
|
|
79
|
+
## 4. Image optimization tools
|
|
80
80
|
|
|
81
|
-
Resize and compress images before including them in your app to
|
|
81
|
+
Resize and compress images before including them in your app to reduce IPA/APK size and network usage.
|
|
82
82
|
|
|
83
|
-
| Platform | File
|
|
84
|
-
|
|
|
83
|
+
| Platform | File types | Tool |
|
|
84
|
+
| --- | --- | --- |
|
|
85
85
|
| Mac | PNG, JPG, GIF | ImageOptim |
|
|
86
86
|
| Mac, Windows, Linux | PNG, JPG, GIF | ImageMagick |
|
|
87
87
|
| Windows/DOS | PNG | PNGCrush |
|
|
@@ -89,21 +89,21 @@ Resize and compress images before including them in your app to minimize IPA/APK
|
|
|
89
89
|
|
|
90
90
|
---
|
|
91
91
|
|
|
92
|
-
## 5. Caching
|
|
92
|
+
## 5. Caching remote images
|
|
93
93
|
|
|
94
94
|
Remote images are cached automatically on iOS, Android, and Windows.
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
-
|
|
98
|
-
-
|
|
96
|
+
Platform differences:
|
|
97
|
+
- Android: cache limited to 25 MB, persists for the lifetime of the app (while installed)
|
|
98
|
+
- iOS: cache size not fixed, cleared by iOS when the device needs storage
|
|
99
99
|
|
|
100
100
|
To manually clean the cache, delete files in `applicationCacheDirectory`.
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
Android 6+ requirement: call `Ti.Filesystem.requestStoragePermissions()` before loading remote images.
|
|
103
103
|
|
|
104
|
-
### Manual
|
|
104
|
+
### Manual caching utility
|
|
105
105
|
|
|
106
|
-
For critical assets, cache manually in `applicationDataDirectory` for
|
|
106
|
+
For critical assets, cache manually in `applicationDataDirectory` for more predictable behavior:
|
|
107
107
|
|
|
108
108
|
```javascript
|
|
109
109
|
const CacheUtils = {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Custom AndroidManifest.xml
|
|
2
2
|
|
|
3
|
-
For most Android manifest settings, use `tiapp.xml`. Only create a custom manifest when
|
|
3
|
+
For most Android manifest settings, use `tiapp.xml`. Only create a custom manifest when you really need it.
|
|
4
4
|
|
|
5
|
-
## Preferred
|
|
5
|
+
## Preferred method: tiapp.xml
|
|
6
6
|
|
|
7
7
|
Add manifest entries in `tiapp.xml` inside the `<android>` section:
|
|
8
8
|
|
|
@@ -30,13 +30,13 @@ Add manifest entries in `tiapp.xml` inside the `<android>` section:
|
|
|
30
30
|
</android>
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
## How
|
|
33
|
+
## How merging works
|
|
34
34
|
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
35
|
+
- Most elements are replaced by your entry.
|
|
36
|
+
- The `<application>` element is merged additively by attribute.
|
|
37
|
+
- Activities and services are added to existing ones.
|
|
38
38
|
|
|
39
|
-
## Custom
|
|
39
|
+
## Custom manifest (rare cases)
|
|
40
40
|
|
|
41
41
|
If you need full control, create `platform/android/AndroidManifest.xml`:
|
|
42
42
|
|
|
@@ -49,26 +49,26 @@ MyApp/
|
|
|
49
49
|
└── tiapp.xml
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
Warning: you must maintain this file manually through SDK updates.
|
|
53
53
|
|
|
54
|
-
## Common
|
|
54
|
+
## Common use cases
|
|
55
55
|
|
|
56
|
-
### Camera
|
|
56
|
+
### Camera permission
|
|
57
57
|
```xml
|
|
58
58
|
<uses-permission android:name="android.permission.CAMERA" />
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
### Hardware
|
|
61
|
+
### Hardware requirements
|
|
62
62
|
```xml
|
|
63
63
|
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
### Launch
|
|
66
|
+
### Launch mode
|
|
67
67
|
```xml
|
|
68
68
|
<application android:launchMode="singleTask" />
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
### Deep
|
|
71
|
+
### Deep links
|
|
72
72
|
```xml
|
|
73
73
|
<intent-filter>
|
|
74
74
|
<action android:name="android.intent.action.VIEW" />
|
|
@@ -86,9 +86,9 @@ ti build -p android
|
|
|
86
86
|
# Check: build/android/AndroidManifest.xml.gen
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
## Enable
|
|
89
|
+
## Enable manifest merge (CLI 7.0+)
|
|
90
90
|
|
|
91
|
-
If
|
|
91
|
+
If you use a custom manifest, enable merge in `tiapp.xml`:
|
|
92
92
|
|
|
93
93
|
```bash
|
|
94
94
|
ti config android.mergeCustomAndroidManifest true
|