@maccesar/titools 2.2.3 → 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 +28 -27
- package/lib/commands/update.js +80 -101
- 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,36 +1,40 @@
|
|
|
1
|
-
# Coding
|
|
1
|
+
# Coding best practices
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Titanium apps are easiest to maintain when they use a single-context, modular pattern with clear structure and organized resources.
|
|
4
4
|
|
|
5
|
-
## 1. Scope
|
|
6
|
-
- **Avoid Global Scope**: Global variables are not automatically garbage collected and can cause naming conflicts.
|
|
7
|
-
- **Always use `let` or `const`**: (Original guide says `var`, but modernization rules apply). Omitting declarations places variables in the global scope.
|
|
5
|
+
## 1. Scope management
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
-
|
|
7
|
+
- Avoid global scope. Global variables are not automatically garbage collected and can create naming conflicts.
|
|
8
|
+
- Always use `let` or `const`. The original guide uses `var`, but modern code should not. Omitting declarations places variables in global scope.
|
|
9
|
+
|
|
10
|
+
## 2. Memory leak prevention
|
|
11
|
+
|
|
12
|
+
- Listeners on `Ti.App`, `Ti.Geolocation`, and similar globals can leak memory if they reference local objects and are not removed.
|
|
11
13
|
```javascript
|
|
12
|
-
//
|
|
14
|
+
// Anti-pattern
|
|
13
15
|
Ti.App.addEventListener('data:sync', (e) => {
|
|
14
16
|
localView.text = e.text // localView is now leaked
|
|
15
17
|
})
|
|
16
18
|
```
|
|
17
|
-
-
|
|
19
|
+
- Rule: global events should only handle global objects. Always `removeEventListener` during cleanup.
|
|
20
|
+
|
|
21
|
+
## 3. Event naming conventions
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
- **No Spaces in Event Names**: Using spaces in custom event names causes issues with Backbone.js and other libraries that use spaces as delimiters.
|
|
23
|
+
- Do not use spaces in event names. Spaces can cause issues with Backbone.js and other libraries that split event names on spaces.
|
|
21
24
|
```javascript
|
|
22
|
-
//
|
|
25
|
+
// Wrong - may fire multiple times
|
|
23
26
|
Ti.App.fireEvent('my event')
|
|
24
27
|
|
|
25
|
-
//
|
|
28
|
+
// Correct - use colon or underscore
|
|
26
29
|
Ti.App.fireEvent('my:event')
|
|
27
30
|
Ti.App.fireEvent('my_event')
|
|
28
31
|
```
|
|
29
32
|
|
|
30
33
|
## 4. Performance
|
|
31
|
-
- **Defer Script Loading**: Evaluate JavaScript only when needed. Don't `require` modules at startup if they are only for specific screens.
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
- Defer script loading. Only `require` modules when you need them.
|
|
36
|
+
|
|
37
|
+
Lazy script loading example:
|
|
34
38
|
```javascript
|
|
35
39
|
// must be loaded at launch
|
|
36
40
|
const WindowOne = require('ui/WindowOne').WindowOne;
|
|
@@ -52,15 +56,16 @@ win1.addEventListener('click', () => {
|
|
|
52
56
|
});
|
|
53
57
|
```
|
|
54
58
|
|
|
55
|
-
-
|
|
56
|
-
-
|
|
59
|
+
- Bridge efficiency: minimize requests for device properties like `Ti.Platform.osname`. Store them in a local variable.
|
|
60
|
+
- Avoid extending the `Ti` namespace. `Ti` objects are proxies to native components. Properties set on them may not reach the native object, arrays return copies, and persistence across SDK versions is not guaranteed. Use modules instead.
|
|
61
|
+
|
|
62
|
+
## 5. App architecture recommendations
|
|
57
63
|
|
|
58
|
-
|
|
64
|
+
### Modular components with CommonJS (recommended)
|
|
59
65
|
|
|
60
|
-
|
|
61
|
-
Titanium's primary recommended architecture. Discrete and independent building blocks that eliminate global variables. See `commonjs-advanced.md` for detailed module patterns and path resolution.
|
|
66
|
+
Titanium's primary recommended architecture. It uses discrete modules and avoids globals. See `commonjs-advanced.md` for module patterns and path resolution.
|
|
62
67
|
|
|
63
|
-
|
|
68
|
+
MyModule.js:
|
|
64
69
|
```javascript
|
|
65
70
|
// Private variable
|
|
66
71
|
const defaultMessage = "Hello world";
|
|
@@ -74,14 +79,15 @@ exports.helloWorld = () => {
|
|
|
74
79
|
}
|
|
75
80
|
```
|
|
76
81
|
|
|
77
|
-
|
|
82
|
+
app.js:
|
|
78
83
|
```javascript
|
|
79
84
|
const myModule = require('/MyModule');
|
|
80
85
|
myModule.sayHello('User');
|
|
81
86
|
```
|
|
82
87
|
|
|
83
|
-
### Custom
|
|
84
|
-
|
|
88
|
+
### Custom objects as components
|
|
89
|
+
|
|
90
|
+
Popular for rapid deployment. It uses a namespace hierarchy. This pattern is less efficient than CommonJS modules, and object references can persist after they are no longer needed.
|
|
85
91
|
|
|
86
92
|
```javascript
|
|
87
93
|
const myapp = {};
|
|
@@ -94,19 +100,22 @@ const myapp = {};
|
|
|
94
100
|
})();
|
|
95
101
|
```
|
|
96
102
|
|
|
97
|
-
### Classical-based
|
|
98
|
-
|
|
103
|
+
### Classical-based patterns
|
|
104
|
+
|
|
105
|
+
Not recommended. JavaScript is not class-based in the same way, and this approach adds overhead during rapid prototyping.
|
|
99
106
|
|
|
100
|
-
## 6. Security
|
|
101
|
-
|
|
107
|
+
## 6. Security best practices
|
|
108
|
+
|
|
109
|
+
- Do not store sensitive data in non-JS files. JavaScript files are minified and obfuscated, but images, JSON, SQLite databases, and other non-JS files are packaged as-is. APK and IPA files are ZIP files that can be extracted.
|
|
102
110
|
```javascript
|
|
103
|
-
//
|
|
111
|
+
// Wrong - API keys visible in app/assets/config.json
|
|
104
112
|
const config = require('assets/config.json')
|
|
105
113
|
|
|
106
|
-
//
|
|
114
|
+
// Correct - store in code or use secure storage
|
|
107
115
|
const API_KEY = Ti.App.Properties.getString('api_key')
|
|
108
116
|
```
|
|
109
117
|
|
|
110
|
-
## 7. Multiplatform
|
|
111
|
-
|
|
112
|
-
-
|
|
118
|
+
## 7. Multiplatform strategies
|
|
119
|
+
|
|
120
|
+
- Code branching: use for small differences.
|
|
121
|
+
- Platform files: use `.ios.js` or `.android.js` for major logic differences so code stays readable.
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
# CommonJS
|
|
1
|
+
# CommonJS advanced patterns
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
For more on CommonJS in Titanium, see the official CommonJS Modules guide in the Titanium SDK documentation.
|
|
4
4
|
|
|
5
5
|
## Definitions
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
7
|
+
- Module: any CommonJS-compliant module used in a Titanium SDK application. This can be a JavaScript file bundled with the app or a native extension that exposes a JavaScript API.
|
|
8
|
+
- Resources: the Resources directory of a Titanium application, where source code lives before the build system processes it. In Alloy, CommonJS modules live in `app/lib`.
|
|
9
|
+
- `exports`: a free variable within a module. Add properties to expose a public API.
|
|
10
|
+
- `module.exports`: an object you can replace to define the module's public API.
|
|
11
11
|
|
|
12
|
-
## 1. Stateful
|
|
12
|
+
## 1. Stateful modules (singleton pattern)
|
|
13
13
|
|
|
14
|
-
Modules in Titanium are created once per JavaScript context and
|
|
14
|
+
Modules in Titanium are created once per JavaScript context and reused on subsequent `require()` calls. This makes them useful for shared state.
|
|
15
|
+
|
|
16
|
+
### Example: stateful counter module
|
|
15
17
|
|
|
16
|
-
### Example: Stateful Counter Module
|
|
17
18
|
```javascript
|
|
18
19
|
// app/lib/counter.js
|
|
19
20
|
let _count = 0
|
|
@@ -31,14 +32,13 @@ exports.reset = () => {
|
|
|
31
32
|
}
|
|
32
33
|
```
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
Usage: multiple controllers that require this module share the same `_count` state.
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
A module is created once **per Titanium JavaScript context**. Additional contexts create new module instances.
|
|
37
|
+
A module is created once per Titanium JavaScript context. Additional contexts create new module instances.
|
|
38
38
|
|
|
39
|
-
## 2. Native/
|
|
39
|
+
## 2. Native/compiled modules
|
|
40
40
|
|
|
41
|
-
When `require()` is called, Titanium
|
|
41
|
+
When `require()` is called, Titanium checks for a native/compiled module before it looks for a JavaScript module. Native modules take priority.
|
|
42
42
|
|
|
43
43
|
Native modules are identified by a single string and configured in `tiapp.xml`:
|
|
44
44
|
|
|
@@ -52,18 +52,18 @@ Native modules are identified by a single string and configured in `tiapp.xml`:
|
|
|
52
52
|
const paypal = require('ti.paypal')
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
Titanium loads `ti.paypal` as a native module and will
|
|
55
|
+
Titanium loads `ti.paypal` as a native module and will not look for a JavaScript file in Resources. If no native module matches, it falls back to JavaScript module resolution.
|
|
56
56
|
|
|
57
|
-
## 3. Module
|
|
57
|
+
## 3. Module path resolution
|
|
58
58
|
|
|
59
|
-
The string passed to `require()` is treated as a path to a JavaScript file,
|
|
59
|
+
The string passed to `require()` is treated as a path to a JavaScript file, without the `.js` extension.
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
61
|
+
Resolution rules:
|
|
62
|
+
- No prefix (`require('app/lib/myModule')`): resolved relative to the `Resources` directory (or `app/lib` in Alloy)
|
|
63
|
+
- `/` prefix (`require('/app/lib/myModule')`): also resolved relative to the `Resources` directory
|
|
64
|
+
- `./` or `../` prefix (`require('./widgets/SomeView')`): resolved relative to the current module file
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
Example with relative paths:
|
|
67
67
|
|
|
68
68
|
Given these files:
|
|
69
69
|
- `Resources/app/ui/SomeCustomView.js`
|
|
@@ -76,24 +76,24 @@ const myModule = require('../lib/myModule')
|
|
|
76
76
|
const SomeOtherCustomView = require('./widgets/SomeOtherCustomView')
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
The `.js` extension is
|
|
79
|
+
The `.js` extension is omitted in `require()` calls.
|
|
80
80
|
|
|
81
|
-
## 4. Caching
|
|
81
|
+
## 4. Caching behavior
|
|
82
82
|
|
|
83
|
-
Titanium caches the object returned by `require()` and
|
|
83
|
+
Titanium caches the object returned by `require()` and returns the same reference without re-evaluating the code.
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
If you need code evaluated multiple times, export a function that creates what you need instead.
|
|
86
86
|
|
|
87
87
|
```javascript
|
|
88
|
-
// Good
|
|
88
|
+
// Good: factory pattern
|
|
89
89
|
exports.createView = (args) => {
|
|
90
90
|
return Ti.UI.createView(args)
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
// Bad
|
|
93
|
+
// Bad: expecting re-evaluation
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
## 5. ES6+
|
|
96
|
+
## 5. ES6+ support (SDK 7.1.0+)
|
|
97
97
|
|
|
98
98
|
Since Titanium SDK 7.1.0, you can use ES6+ module syntax. Code is transpiled to ES5 for all platforms.
|
|
99
99
|
|
|
@@ -114,9 +114,10 @@ import MyClass from 'MyClass'
|
|
|
114
114
|
const instance = new MyClass('World')
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
-
## 6. Module
|
|
117
|
+
## 6. Module composition patterns
|
|
118
|
+
|
|
119
|
+
### Exports object pattern
|
|
118
120
|
|
|
119
|
-
### Exports Object Pattern
|
|
120
121
|
```javascript
|
|
121
122
|
exports.sayHello = (name) => {
|
|
122
123
|
Ti.API.info(`Hello ${name}`)
|
|
@@ -125,7 +126,8 @@ exports.sayHello = (name) => {
|
|
|
125
126
|
exports.version = 1.4
|
|
126
127
|
```
|
|
127
128
|
|
|
128
|
-
### Constructor
|
|
129
|
+
### Constructor pattern (`module.exports`)
|
|
130
|
+
|
|
129
131
|
```javascript
|
|
130
132
|
class Person {
|
|
131
133
|
constructor(firstName, lastName) {
|
|
@@ -141,7 +143,8 @@ class Person {
|
|
|
141
143
|
module.exports = Person
|
|
142
144
|
```
|
|
143
145
|
|
|
144
|
-
### Utility
|
|
146
|
+
### Utility library pattern
|
|
147
|
+
|
|
145
148
|
```javascript
|
|
146
149
|
// app/lib/logger.js
|
|
147
150
|
exports.info = (str) => {
|
|
@@ -153,15 +156,15 @@ exports.debug = (str) => {
|
|
|
153
156
|
}
|
|
154
157
|
```
|
|
155
158
|
|
|
156
|
-
|
|
159
|
+
Usage:
|
|
157
160
|
```javascript
|
|
158
161
|
const logger = require('logger')
|
|
159
162
|
logger.info('some log statement with a timestamp')
|
|
160
163
|
```
|
|
161
164
|
|
|
162
|
-
## 7. Inter-
|
|
165
|
+
## 7. Inter-module state sharing
|
|
163
166
|
|
|
164
|
-
When a module assigns a primitive value to `exports`, the consumer gets a
|
|
167
|
+
When a module assigns a primitive value to `exports`, the consumer gets a copy, not a live reference. Changes to the internal variable are not reflected in the exported property.
|
|
165
168
|
|
|
166
169
|
```javascript
|
|
167
170
|
// app/lib/statefulModule.js
|
|
@@ -175,43 +178,46 @@ exports.getPointStep = () => {
|
|
|
175
178
|
return _stepVal
|
|
176
179
|
}
|
|
177
180
|
|
|
178
|
-
exports.stepVal = _stepVal // This is a
|
|
181
|
+
exports.stepVal = _stepVal // This is a copy of _stepVal (value: 5)
|
|
179
182
|
```
|
|
180
183
|
|
|
181
184
|
```javascript
|
|
182
185
|
const stateful = require('statefulModule')
|
|
183
186
|
stateful.setPointStep(10)
|
|
184
187
|
Ti.API.info(stateful.getPointStep()) // 10 - correct, uses getter
|
|
185
|
-
Ti.API.info(stateful.stepVal) // 5 - still the original copy
|
|
188
|
+
Ti.API.info(stateful.stepVal) // 5 - still the original copy
|
|
186
189
|
```
|
|
187
190
|
|
|
188
|
-
|
|
191
|
+
Rule: use getter/setter functions for stateful values. Direct property exports of primitives are snapshots at module load time.
|
|
189
192
|
|
|
190
|
-
## 8. Antipatterns to
|
|
193
|
+
## 8. Antipatterns to avoid
|
|
194
|
+
|
|
195
|
+
### Do not assign directly to `exports`
|
|
191
196
|
|
|
192
|
-
### Don't Assign Directly to exports
|
|
193
197
|
```javascript
|
|
194
|
-
//
|
|
198
|
+
// Wrong
|
|
195
199
|
function Person() {}
|
|
196
200
|
exports = Person
|
|
197
201
|
|
|
198
|
-
//
|
|
202
|
+
// Correct
|
|
199
203
|
module.exports = Person
|
|
200
204
|
```
|
|
201
205
|
|
|
202
|
-
###
|
|
206
|
+
### Do not mix `module.exports` and `exports.*`
|
|
207
|
+
|
|
203
208
|
```javascript
|
|
204
|
-
//
|
|
209
|
+
// Discouraged
|
|
205
210
|
module.exports = Person
|
|
206
211
|
exports.foo = 'bar'
|
|
207
212
|
|
|
208
|
-
//
|
|
213
|
+
// Use one consistently
|
|
209
214
|
```
|
|
210
215
|
|
|
211
|
-
###
|
|
212
|
-
|
|
216
|
+
### Avoid globals across modules
|
|
217
|
+
|
|
218
|
+
Any data a module needs should be passed during construction or initialization. Avoid globals shared across modules.
|
|
213
219
|
|
|
214
|
-
## 9. Security and
|
|
220
|
+
## 9. Security and scope
|
|
215
221
|
|
|
216
222
|
All modules have private scope. Variables declared within the module are private unless added to `exports`.
|
|
217
223
|
|
|
@@ -224,8 +230,8 @@ exports.publicMethod = () => {
|
|
|
224
230
|
}
|
|
225
231
|
```
|
|
226
232
|
|
|
227
|
-
## 10. Node.js
|
|
233
|
+
## 10. Node.js compatibility
|
|
228
234
|
|
|
229
235
|
Titanium supports Node.js module patterns and `require()` resolution. Node.js modules can often be used directly.
|
|
230
236
|
|
|
231
|
-
For
|
|
237
|
+
For details, refer to the official Titanium Node.js guide.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# Hello
|
|
1
|
+
# Hello world: project creation
|
|
2
2
|
|
|
3
3
|
Quick guide to creating your first Titanium project.
|
|
4
4
|
|
|
5
|
-
## Creating a
|
|
5
|
+
## Creating a new project
|
|
6
6
|
|
|
7
7
|
### Using CLI
|
|
8
8
|
|
|
@@ -10,39 +10,39 @@ Quick guide to creating your first Titanium project.
|
|
|
10
10
|
ti create -t app --id <APP_ID> -n <APP_NAME> -p <PLATFORMS> -d <WORKSPACE>
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Example:
|
|
14
14
|
```bash
|
|
15
15
|
ti create -t app --id com.example.hello -n HelloWorld -p android,ios -d ~/Projects
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
### Using Studio/VS Code
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
File > New > Mobile App Project
|
|
21
21
|
|
|
22
|
-
Choose template:
|
|
23
|
-
-
|
|
24
|
-
-
|
|
22
|
+
Choose a template:
|
|
23
|
+
- Alloy: MVC framework (recommended)
|
|
24
|
+
- Classic: no framework
|
|
25
25
|
|
|
26
|
-
## Project
|
|
26
|
+
## Project fields
|
|
27
27
|
|
|
28
|
-
| Field
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
33
|
-
|
|
|
34
|
-
|
|
|
28
|
+
| Field | Description | Rules |
|
|
29
|
+
| --- | --- | --- |
|
|
30
|
+
| Project name | App name shown to users | - |
|
|
31
|
+
| App ID | Reverse domain notation | `com.company.appname` |
|
|
32
|
+
| Company URL | Your website | - |
|
|
33
|
+
| SDK Version | Titanium SDK to use | Use latest |
|
|
34
|
+
| Deployment Targets | Platforms to support | android, ios, ipad, iphone |
|
|
35
35
|
|
|
36
|
-
### App ID
|
|
36
|
+
### App ID naming guidelines
|
|
37
37
|
|
|
38
|
-
- Use Java
|
|
38
|
+
- Use Java package style: `com.yourdomain.yourappname`
|
|
39
39
|
- No spaces or special characters
|
|
40
40
|
- All lowercase (Android issues with uppercase)
|
|
41
41
|
- No Java keywords (`case`, `package`, etc.)
|
|
42
42
|
- Cannot change after publishing
|
|
43
|
-
-
|
|
43
|
+
- On iOS, the App ID must match the Bundle Identifier. On Android, it becomes the Application Package Name.
|
|
44
44
|
|
|
45
|
-
## Project
|
|
45
|
+
## Project structure
|
|
46
46
|
|
|
47
47
|
```
|
|
48
48
|
MyApp/
|
|
@@ -64,40 +64,40 @@ MyApp/
|
|
|
64
64
|
└── app.js # Bootstrap file loaded first when app launches
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
## Running
|
|
67
|
+
## Running your app
|
|
68
68
|
|
|
69
|
-
### iOS
|
|
69
|
+
### iOS simulator
|
|
70
70
|
```bash
|
|
71
71
|
ti build -p ios -C "iPhone 15"
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
### Android
|
|
74
|
+
### Android emulator
|
|
75
75
|
```bash
|
|
76
76
|
ti build -p android -C "Pixel_4_API_34"
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
### Physical
|
|
79
|
+
### Physical device
|
|
80
80
|
```bash
|
|
81
81
|
ti build -p ios -T device
|
|
82
82
|
ti build -p android -T device
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
## Simulator vs
|
|
85
|
+
## Simulator vs emulator
|
|
86
86
|
|
|
87
|
-
-
|
|
88
|
-
-
|
|
87
|
+
- iOS simulator: simulates the environment within an iOS device. It is a macOS executable that runs your cross-compiled code.
|
|
88
|
+
- Android emulator: provides a virtual hardware environment that runs the Android OS and platform components.
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
Neither environment is a perfect representation of a physical device. Always test on real hardware before publishing.
|
|
91
91
|
|
|
92
|
-
## How Titanium
|
|
92
|
+
## How Titanium works (under the covers)
|
|
93
93
|
|
|
94
|
-
1.
|
|
95
|
-
2.
|
|
96
|
-
3.
|
|
97
|
-
4.
|
|
94
|
+
1. Pre-compile: JavaScript is minified and statically analyzed to build a dependency hierarchy of Titanium APIs used.
|
|
95
|
+
2. Stub generation: a front-end compiler creates native stub files, native project files, and platform-specific code needed for compilation.
|
|
96
|
+
3. Native build: Titanium calls platform-specific compilers (for example, `xcodebuild` for iOS and Gradle for Android) to build the native app.
|
|
97
|
+
4. Encryption: JavaScript code is encrypted when building for production (release) or for device. Original code is not retrievable in human-readable form.
|
|
98
98
|
|
|
99
|
-
## Best
|
|
99
|
+
## Best practices
|
|
100
100
|
|
|
101
|
-
1.
|
|
102
|
-
2.
|
|
103
|
-
3.
|
|
101
|
+
1. Test on physical devices. The simulator/emulator is not a perfect proxy.
|
|
102
|
+
2. Use Alloy for new projects for better structure and maintainability.
|
|
103
|
+
3. Keep the App ID consistent. Match Bundle ID (iOS) and Package ID (Android).
|