@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,48 +1,48 @@
|
|
|
1
1
|
# Extending Titanium
|
|
2
2
|
|
|
3
|
-
## 1. Module
|
|
3
|
+
## 1. Module architecture (core concepts)
|
|
4
4
|
|
|
5
5
|
Titanium modules are based on a native class hierarchy that communicates with JavaScript:
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
7
|
+
- Proxy: base class that binds native code with JS and maintains object state
|
|
8
|
+
- Module: special Proxy that defines a namespace (for example, `Ti.UI`). Only one per project is allowed.
|
|
9
|
+
- ViewProxy: Proxy specialized in rendering views; manages the native view lifecycle
|
|
10
|
+
- View: the actual visual representation (for example, a `UIButton` or an Android `UIView`)
|
|
11
11
|
|
|
12
|
-
### Proxy-
|
|
13
|
-
The `ViewProxy`
|
|
12
|
+
### Proxy-view relationship
|
|
13
|
+
The `ViewProxy` keeps properties in JS even if the native view does not exist yet. When the view is added to the hierarchy, the Proxy creates the native `View` and applies all accumulated properties.
|
|
14
14
|
|
|
15
|
-
### Threading
|
|
16
|
-
- JavaScript in Titanium is
|
|
15
|
+
### Threading considerations
|
|
16
|
+
- JavaScript in Titanium is single-threaded. All JS callbacks run on the JS runtime thread.
|
|
17
17
|
- Native modules can use background threads for heavy work, but UI operations must happen on the main/UI thread.
|
|
18
|
-
- On iOS, each Window with a `url` property gets its own
|
|
18
|
+
- On iOS, each Window with a `url` property gets its own JS context and thread. Avoid this pattern.
|
|
19
19
|
- Use `@Kroll.method(runOnUiThread=true)` (Android) to ensure a method runs on the UI thread.
|
|
20
20
|
|
|
21
|
-
### Key Android Kroll
|
|
22
|
-
- `@Kroll.method`
|
|
23
|
-
- `@Kroll.getProperty` / `@Kroll.setProperty`
|
|
24
|
-
- `@Kroll.onAppCreate`
|
|
25
|
-
- `propertyAccessors`
|
|
21
|
+
### Key Android Kroll annotations
|
|
22
|
+
- `@Kroll.method` - expose a Java method to JavaScript
|
|
23
|
+
- `@Kroll.getProperty` / `@Kroll.setProperty` - expose getter/setter properties
|
|
24
|
+
- `@Kroll.onAppCreate` - annotate a static method to run when the app process starts
|
|
25
|
+
- `propertyAccessors` in `@Kroll.proxy` - auto-generate getter/setter methods
|
|
26
26
|
|
|
27
|
-
## 2. Module
|
|
27
|
+
## 2. Module debugging in Xcode (iOS)
|
|
28
28
|
|
|
29
|
-
You can debug
|
|
29
|
+
You can debug a native module directly within a Titanium project:
|
|
30
30
|
|
|
31
|
-
1. Open the generated Xcode project
|
|
31
|
+
1. Open the generated Xcode project at `build/iphone/<App>.xcodeproj`.
|
|
32
32
|
2. Drag the module project (`.xcodeproj`) into the app project in Xcode.
|
|
33
|
-
3. In the app, go to
|
|
34
|
-
4. In
|
|
33
|
+
3. In the app, go to Build Phases → Dependencies and add the module.
|
|
34
|
+
4. In Link Binary With Libraries, add the module's `.a` library or framework.
|
|
35
35
|
5. Set a breakpoint in your native code and launch the app from Xcode.
|
|
36
36
|
|
|
37
37
|
## 3. Upgrading to SDK 9.0.0+ (Android)
|
|
38
38
|
|
|
39
|
-
Titanium 9.0.0 introduced major changes
|
|
39
|
+
Titanium 9.0.0 introduced major Android changes:
|
|
40
40
|
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
41
|
+
- AndroidX: legacy support libraries are no longer supported. Migrate Java/Kotlin code to AndroidX.
|
|
42
|
+
- Gradle: modules now use Gradle for dependencies. Create `android/build.gradle` instead of copying `.jar` files into `lib/`.
|
|
43
|
+
- Architectures: include `arm64-v8a` and `x86_64` in the manifest.
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
Example module `build.gradle`:
|
|
46
46
|
```gradle
|
|
47
47
|
dependencies {
|
|
48
48
|
implementation 'com.google.android.material:material:1.1.0'
|
|
@@ -57,16 +57,16 @@ Hyperloop provides direct JavaScript access to native iOS and Android APIs witho
|
|
|
57
57
|
|
|
58
58
|
### Prerequisites
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
For iOS:
|
|
61
61
|
- Requires `ti.hyperloop` module in `tiapp.xml`
|
|
62
|
-
- Only works with Classic Titanium
|
|
62
|
+
- Only works with Classic Titanium projects (not Alloy initially, now supported)
|
|
63
63
|
- iOS 7+ deployment target
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
For Android:
|
|
66
66
|
- Requires `ti.hyperloop` module in `tiapp.xml`
|
|
67
|
-
- Android 4.0+ (API
|
|
67
|
+
- Android 4.0+ (API level 14+)
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
Enable in `tiapp.xml`:
|
|
70
70
|
```xml
|
|
71
71
|
<modules>
|
|
72
72
|
<module platform="iphone">ti.hyperloop</module>
|
|
@@ -74,18 +74,18 @@ Hyperloop provides direct JavaScript access to native iOS and Android APIs witho
|
|
|
74
74
|
</modules>
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
### Hyperloop
|
|
77
|
+
### Hyperloop basics
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
Pattern for accessing native APIs:
|
|
80
80
|
```javascript
|
|
81
81
|
const NativeClass = require('path.to.NativeClass');
|
|
82
82
|
const instance = new NativeClass();
|
|
83
83
|
instance.methodName();
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
### iOS Hyperloop
|
|
86
|
+
### iOS Hyperloop examples
|
|
87
87
|
|
|
88
|
-
#### Access iOS
|
|
88
|
+
#### Access iOS frameworks
|
|
89
89
|
|
|
90
90
|
```javascript
|
|
91
91
|
// Access Foundation framework
|
|
@@ -99,7 +99,7 @@ Ti.API.info(`Length: ${str.length()}`);
|
|
|
99
99
|
// Mutable string
|
|
100
100
|
const mutable = NSMutableString.alloc().initWithString('Hello');
|
|
101
101
|
mutable.appendString(' Hyperloop');
|
|
102
|
-
Ti.API.info(mutable);
|
|
102
|
+
Ti.API.info(mutable); // "Hello Hyperloop"
|
|
103
103
|
```
|
|
104
104
|
|
|
105
105
|
#### Access UIKit
|
|
@@ -117,7 +117,7 @@ controller.view().setBackgroundColor(
|
|
|
117
117
|
);
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
-
#### Make
|
|
120
|
+
#### Make native HTTP request
|
|
121
121
|
|
|
122
122
|
```javascript
|
|
123
123
|
const NSURL = require('Foundation/NSURL');
|
|
@@ -144,19 +144,19 @@ task.resume();
|
|
|
144
144
|
var CBCentralManager = require('CoreBluetooth/CBCentralManager');
|
|
145
145
|
|
|
146
146
|
var central = CBCentralManager.alloc().initWithDelegateQueueOptions(
|
|
147
|
-
null,
|
|
148
|
-
null
|
|
147
|
+
null, // delegate
|
|
148
|
+
null // queue
|
|
149
149
|
);
|
|
150
150
|
|
|
151
151
|
// Check Bluetooth state
|
|
152
152
|
var state = central.state();
|
|
153
|
-
if (state === 5) {
|
|
153
|
+
if (state === 5) { // CBCentralManagerStatePoweredOn
|
|
154
154
|
// Start scanning
|
|
155
155
|
central.scanForPeripheralsWithServicesOptions(null, null);
|
|
156
156
|
}
|
|
157
157
|
```
|
|
158
158
|
|
|
159
|
-
#### Access AVFoundation (
|
|
159
|
+
#### Access AVFoundation (camera/video)
|
|
160
160
|
|
|
161
161
|
```javascript
|
|
162
162
|
var AVCaptureDevice = require('AVFoundation/AVCaptureDevice');
|
|
@@ -167,7 +167,7 @@ var backCamera = null;
|
|
|
167
167
|
|
|
168
168
|
for (var i = 0; i < devices.count(); i++) {
|
|
169
169
|
var device = devices.objectAtIndex(i);
|
|
170
|
-
if (device.position() === 1) {
|
|
170
|
+
if (device.position() === 1) { // AVCaptureDevicePositionBack
|
|
171
171
|
backCamera = device;
|
|
172
172
|
break;
|
|
173
173
|
}
|
|
@@ -176,12 +176,12 @@ for (var i = 0; i < devices.count(); i++) {
|
|
|
176
176
|
// Configure camera
|
|
177
177
|
if (backCamera) {
|
|
178
178
|
backCamera.lockForConfiguration(null);
|
|
179
|
-
backCamera.setFlashMode(1);
|
|
179
|
+
backCamera.setFlashMode(1); // AVCaptureFlashModeOn
|
|
180
180
|
backCamera.unlockForConfiguration();
|
|
181
181
|
}
|
|
182
182
|
```
|
|
183
183
|
|
|
184
|
-
#### Access Address Book (
|
|
184
|
+
#### Access Address Book (contacts)
|
|
185
185
|
|
|
186
186
|
```javascript
|
|
187
187
|
var ABAddressBook = require('AddressBook/ABAddressBook');
|
|
@@ -191,12 +191,12 @@ var people = addressBook.people();
|
|
|
191
191
|
|
|
192
192
|
for (var i = 0; i < people.count(); i++) {
|
|
193
193
|
var person = people.objectAtIndex(i);
|
|
194
|
-
var firstName = person.valueForProperty(0);
|
|
194
|
+
var firstName = person.valueForProperty(0); // kABPersonFirstNameProperty
|
|
195
195
|
Ti.API.info('Contact: ' + firstName);
|
|
196
196
|
}
|
|
197
197
|
```
|
|
198
198
|
|
|
199
|
-
#### Access CoreLocation (
|
|
199
|
+
#### Access CoreLocation (enhanced)
|
|
200
200
|
|
|
201
201
|
```javascript
|
|
202
202
|
var CLLocationManager = require('CoreLocation/CLLocationManager');
|
|
@@ -204,13 +204,13 @@ var CLLocation = require('CoreLocation/CLLocation');
|
|
|
204
204
|
|
|
205
205
|
var locationManager = CLLocationManager.alloc().init();
|
|
206
206
|
locationManager.setDelegate(null);
|
|
207
|
-
locationManager.setDesiredAccuracy(3);
|
|
207
|
+
locationManager.setDesiredAccuracy(3); // kCLLocationAccuracyBest
|
|
208
208
|
locationManager.startUpdatingLocation();
|
|
209
209
|
```
|
|
210
210
|
|
|
211
|
-
### Android Hyperloop
|
|
211
|
+
### Android Hyperloop examples
|
|
212
212
|
|
|
213
|
-
#### Access Android
|
|
213
|
+
#### Access Android frameworks
|
|
214
214
|
|
|
215
215
|
```javascript
|
|
216
216
|
const Context = require('android.content.Context');
|
|
@@ -228,7 +228,7 @@ Toast.makeText(
|
|
|
228
228
|
).show();
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
-
#### Access
|
|
231
|
+
#### Access vibrator
|
|
232
232
|
|
|
233
233
|
```javascript
|
|
234
234
|
const Vibrator = require('android.os.Vibrator');
|
|
@@ -301,14 +301,14 @@ for (let i = 0; i < packages.size(); i++) {
|
|
|
301
301
|
}
|
|
302
302
|
```
|
|
303
303
|
|
|
304
|
-
### Hyperloop
|
|
304
|
+
### Hyperloop best practices
|
|
305
305
|
|
|
306
|
-
1.
|
|
307
|
-
2.
|
|
308
|
-
3.
|
|
309
|
-
4.
|
|
310
|
-
5.
|
|
311
|
-
6.
|
|
306
|
+
1. Check platform availability. Use `Ti.Platform.osname` to branch code.
|
|
307
|
+
2. Handle errors. Native calls can throw exceptions.
|
|
308
|
+
3. Memory management: be aware of native object lifecycles.
|
|
309
|
+
4. Test thoroughly. Native APIs have platform-specific behaviors.
|
|
310
|
+
5. Document requirements. Note platform versions and permissions needed.
|
|
311
|
+
6. Use try/catch. Wrap native calls for safety.
|
|
312
312
|
|
|
313
313
|
```javascript
|
|
314
314
|
try {
|
|
@@ -320,9 +320,9 @@ try {
|
|
|
320
320
|
}
|
|
321
321
|
```
|
|
322
322
|
|
|
323
|
-
## 3. Native
|
|
323
|
+
## 3. Native module development
|
|
324
324
|
|
|
325
|
-
### When to
|
|
325
|
+
### When to create native modules
|
|
326
326
|
|
|
327
327
|
Create a native module when you need to:
|
|
328
328
|
- Reuse native code across multiple Titanium apps
|
|
@@ -330,11 +330,11 @@ Create a native module when you need to:
|
|
|
330
330
|
- Implement complex native functionality not suitable for Hyperloop
|
|
331
331
|
- Maintain a stable API regardless of native SDK changes
|
|
332
332
|
|
|
333
|
-
### Android
|
|
333
|
+
### Android module development
|
|
334
334
|
|
|
335
|
-
#### Quick
|
|
335
|
+
#### Quick start
|
|
336
336
|
|
|
337
|
-
1.
|
|
337
|
+
1. Create module structure:
|
|
338
338
|
```
|
|
339
339
|
com.example.mymodule/
|
|
340
340
|
├── src/
|
|
@@ -349,7 +349,7 @@ com.example.mymodule/
|
|
|
349
349
|
└── LICENSE
|
|
350
350
|
```
|
|
351
351
|
|
|
352
|
-
2.
|
|
352
|
+
2. Module Java class:
|
|
353
353
|
|
|
354
354
|
```java
|
|
355
355
|
package com.example.mymodule;
|
|
@@ -381,7 +381,7 @@ public class ExampleModule extends KrollModule {
|
|
|
381
381
|
}
|
|
382
382
|
```
|
|
383
383
|
|
|
384
|
-
3.
|
|
384
|
+
3. `timodule.xml`:
|
|
385
385
|
```xml
|
|
386
386
|
<module>
|
|
387
387
|
<description>My Example Module</description>
|
|
@@ -391,7 +391,7 @@ public class ExampleModule extends KrollModule {
|
|
|
391
391
|
</module>
|
|
392
392
|
```
|
|
393
393
|
|
|
394
|
-
4.
|
|
394
|
+
4. Build and package:
|
|
395
395
|
```bash
|
|
396
396
|
ant clean
|
|
397
397
|
ant package
|
|
@@ -401,14 +401,14 @@ ant package
|
|
|
401
401
|
|
|
402
402
|
```javascript
|
|
403
403
|
const myModule = require('com.example.mymodule');
|
|
404
|
-
Ti.API.info(myModule.helloWorld());
|
|
405
|
-
Ti.API.info(myModule.add(5, 3));
|
|
406
|
-
Ti.API.info(myModule.version);
|
|
404
|
+
Ti.API.info(myModule.helloWorld()); // "Hello from native module!"
|
|
405
|
+
Ti.API.info(myModule.add(5, 3)); // 8
|
|
406
|
+
Ti.API.info(myModule.version); // "1.0.0"
|
|
407
407
|
```
|
|
408
408
|
|
|
409
|
-
#### Common Android
|
|
409
|
+
#### Common Android module patterns
|
|
410
410
|
|
|
411
|
-
|
|
411
|
+
Accessing Android APIs:
|
|
412
412
|
|
|
413
413
|
```java
|
|
414
414
|
import android.content.Context;
|
|
@@ -421,7 +421,7 @@ public boolean isGPSEnabled() {
|
|
|
421
421
|
}
|
|
422
422
|
```
|
|
423
423
|
|
|
424
|
-
|
|
424
|
+
Firing events to JavaScript:
|
|
425
425
|
|
|
426
426
|
```java
|
|
427
427
|
import org.appcelerator.kroll.KrollDict;
|
|
@@ -434,7 +434,7 @@ public void triggerEvent() {
|
|
|
434
434
|
}
|
|
435
435
|
```
|
|
436
436
|
|
|
437
|
-
|
|
437
|
+
Receiving events from JavaScript:
|
|
438
438
|
|
|
439
439
|
```java
|
|
440
440
|
@Kroll.method
|
|
@@ -443,17 +443,17 @@ public void startService() {
|
|
|
443
443
|
}
|
|
444
444
|
```
|
|
445
445
|
|
|
446
|
-
### iOS
|
|
446
|
+
### iOS module development
|
|
447
447
|
|
|
448
|
-
#### Quick
|
|
448
|
+
#### Quick start
|
|
449
449
|
|
|
450
|
-
1.
|
|
450
|
+
1. Create module with template:
|
|
451
451
|
```bash
|
|
452
452
|
# Use Titanium CLI
|
|
453
453
|
titanium create --type module --id com.example.mymodule --name MyModule --platform ios
|
|
454
454
|
```
|
|
455
455
|
|
|
456
|
-
2.
|
|
456
|
+
2. Module structure:
|
|
457
457
|
```
|
|
458
458
|
com.example.mymodule/
|
|
459
459
|
├── Classes/
|
|
@@ -469,7 +469,7 @@ com.example.mymodule/
|
|
|
469
469
|
└── LICENSE
|
|
470
470
|
```
|
|
471
471
|
|
|
472
|
-
3.
|
|
472
|
+
3. Module implementation (`ComExampleMymoduleModule.m`):
|
|
473
473
|
|
|
474
474
|
```objc
|
|
475
475
|
#import "ComExampleMymoduleModule.h"
|
|
@@ -520,7 +520,7 @@ com.example.mymodule/
|
|
|
520
520
|
@end
|
|
521
521
|
```
|
|
522
522
|
|
|
523
|
-
4.
|
|
523
|
+
4. `timodule.xml`:
|
|
524
524
|
```xml
|
|
525
525
|
<module>
|
|
526
526
|
<description>My Example Module</description>
|
|
@@ -530,23 +530,23 @@ com.example.mymodule/
|
|
|
530
530
|
</module>
|
|
531
531
|
```
|
|
532
532
|
|
|
533
|
-
5.
|
|
533
|
+
5. Build and package:
|
|
534
534
|
```bash
|
|
535
535
|
./build.py
|
|
536
536
|
```
|
|
537
537
|
|
|
538
|
-
6.
|
|
538
|
+
6. Use in Titanium app:
|
|
539
539
|
|
|
540
540
|
```javascript
|
|
541
541
|
const myModule = require('com.example.mymodule');
|
|
542
|
-
Ti.API.info(myModule.helloWorld());
|
|
543
|
-
Ti.API.info(myModule.add(5, {with: 3})); // 8
|
|
544
|
-
Ti.API.info(myModule.version);
|
|
542
|
+
Ti.API.info(myModule.helloWorld()); // "Hello from native module!"
|
|
543
|
+
Ti.API.info(myModule.add(5, { with: 3 })); // 8
|
|
544
|
+
Ti.API.info(myModule.version); // "1.0.0"
|
|
545
545
|
```
|
|
546
546
|
|
|
547
|
-
#### Common iOS
|
|
547
|
+
#### Common iOS module patterns
|
|
548
548
|
|
|
549
|
-
|
|
549
|
+
Accessing iOS frameworks:
|
|
550
550
|
|
|
551
551
|
```objc
|
|
552
552
|
#import <CoreLocation/CoreLocation.h>
|
|
@@ -558,7 +558,7 @@ Ti.API.info(myModule.version); // "1.0.0"
|
|
|
558
558
|
}
|
|
559
559
|
```
|
|
560
560
|
|
|
561
|
-
|
|
561
|
+
Firing events to JavaScript:
|
|
562
562
|
|
|
563
563
|
```objc
|
|
564
564
|
- (void)locationUpdated:(CLLocation*)location {
|
|
@@ -570,7 +570,7 @@ Ti.API.info(myModule.version); // "1.0.0"
|
|
|
570
570
|
}
|
|
571
571
|
```
|
|
572
572
|
|
|
573
|
-
|
|
573
|
+
View proxies (custom UI components):
|
|
574
574
|
|
|
575
575
|
```objc
|
|
576
576
|
@interface MyViewProxy : TiViewProxy {
|
|
@@ -587,11 +587,11 @@ Ti.API.info(myModule.version); // "1.0.0"
|
|
|
587
587
|
@end
|
|
588
588
|
```
|
|
589
589
|
|
|
590
|
-
### Module
|
|
590
|
+
### Module distribution
|
|
591
591
|
|
|
592
592
|
#### Packaging
|
|
593
593
|
|
|
594
|
-
Both platforms create a `.zip` file
|
|
594
|
+
Both platforms create a `.zip` file for distribution:
|
|
595
595
|
|
|
596
596
|
```bash
|
|
597
597
|
# For iOS
|
|
@@ -601,13 +601,13 @@ Both platforms create a `.zip` file that can be distributed:
|
|
|
601
601
|
ant dist
|
|
602
602
|
```
|
|
603
603
|
|
|
604
|
-
#### Installing
|
|
604
|
+
#### Installing module
|
|
605
605
|
|
|
606
|
-
1.
|
|
607
|
-
2.
|
|
608
|
-
3.
|
|
606
|
+
1. Local installation: extract to `/Library/Application Support/Titanium/modules/`
|
|
607
|
+
2. Global installation: use `gittio` or `npm` for publishing
|
|
608
|
+
3. Project-specific: place in the app's `modules/` directory
|
|
609
609
|
|
|
610
|
-
#### Module
|
|
610
|
+
#### Module configuration in tiapp.xml
|
|
611
611
|
|
|
612
612
|
```xml
|
|
613
613
|
<modules>
|
|
@@ -616,17 +616,17 @@ ant dist
|
|
|
616
616
|
</modules>
|
|
617
617
|
```
|
|
618
618
|
|
|
619
|
-
## 4. Choosing
|
|
619
|
+
## 4. Choosing between Hyperloop and native modules
|
|
620
620
|
|
|
621
|
-
### Use Hyperloop
|
|
621
|
+
### Use Hyperloop when
|
|
622
622
|
|
|
623
623
|
- Prototyping native API access
|
|
624
624
|
- App-specific native functionality (not reusable)
|
|
625
625
|
- One-off native API calls
|
|
626
626
|
- Quick integration with platform features
|
|
627
|
-
-
|
|
627
|
+
- You do not need to distribute code
|
|
628
628
|
|
|
629
|
-
### Use
|
|
629
|
+
### Use native modules when
|
|
630
630
|
|
|
631
631
|
- Creating reusable components
|
|
632
632
|
- Distributing to other developers
|
|
@@ -635,29 +635,29 @@ ant dist
|
|
|
635
635
|
- Performance-critical code paths
|
|
636
636
|
- Custom UI components
|
|
637
637
|
|
|
638
|
-
## 5. Finding and
|
|
638
|
+
## 5. Finding and using third-party modules
|
|
639
639
|
|
|
640
|
-
### Ti_slack
|
|
640
|
+
### Ti_slack marketplace
|
|
641
641
|
|
|
642
642
|
Search for existing modules at:
|
|
643
643
|
- https://fromzerotoapp.com/modules/
|
|
644
644
|
- https://github.com/search?q=titanium+module
|
|
645
645
|
|
|
646
|
-
### Popular
|
|
646
|
+
### Popular third-party modules
|
|
647
647
|
|
|
648
|
-
-
|
|
649
|
-
-
|
|
650
|
-
-
|
|
651
|
-
-
|
|
652
|
-
-
|
|
653
|
-
-
|
|
654
|
-
-
|
|
648
|
+
- ti.map - Enhanced mapping (Google Maps, Apple Maps)
|
|
649
|
+
- ti.paint - Drawing/signature capture
|
|
650
|
+
- ti.barcode - Barcode/QR scanning
|
|
651
|
+
- ti.admob - AdMob integration
|
|
652
|
+
- ti.facebook - Facebook SDK
|
|
653
|
+
- ti.googleplus - Google+ SDK
|
|
654
|
+
- ti.oauth2 - OAuth 2.0 client
|
|
655
655
|
|
|
656
|
-
### Using
|
|
656
|
+
### Using third-party modules
|
|
657
657
|
|
|
658
|
-
1.
|
|
659
|
-
2.
|
|
660
|
-
3.
|
|
658
|
+
1. Download module zip
|
|
659
|
+
2. Extract to modules directory
|
|
660
|
+
3. Add to `tiapp.xml`:
|
|
661
661
|
|
|
662
662
|
```xml
|
|
663
663
|
<modules>
|
|
@@ -666,19 +666,19 @@ Search for existing modules at:
|
|
|
666
666
|
</modules>
|
|
667
667
|
```
|
|
668
668
|
|
|
669
|
-
4.
|
|
669
|
+
4. Require in code:
|
|
670
670
|
|
|
671
671
|
```javascript
|
|
672
672
|
const Mapbox = require('com.mapbox.map');
|
|
673
673
|
```
|
|
674
674
|
|
|
675
|
-
## Best
|
|
675
|
+
## Best practices summary
|
|
676
676
|
|
|
677
|
-
1.
|
|
678
|
-
2.
|
|
679
|
-
3.
|
|
680
|
-
4.
|
|
681
|
-
5.
|
|
682
|
-
6.
|
|
683
|
-
7.
|
|
684
|
-
8.
|
|
677
|
+
1. Try built-in APIs first; Titanium may already have what you need.
|
|
678
|
+
2. Prefer Hyperloop for simple cases; less overhead.
|
|
679
|
+
3. Create modules for reusable code; better distribution.
|
|
680
|
+
4. Handle platform differences; branch code appropriately.
|
|
681
|
+
5. Document dependencies; note SDK versions and requirements.
|
|
682
|
+
6. Test on real devices; simulators may not support all features.
|
|
683
|
+
7. Version your modules; use semantic versioning for compatibility.
|
|
684
|
+
8. Provide examples; help users understand usage patterns.
|