@maccesar/titools 5.3.0 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +1 -1
- package/README.md +31 -60
- package/agents/ti-pro.md +3 -1
- package/commands/ti-audit.md +6 -4
- package/docs/examples.md +9 -0
- package/docs/knowledge-index.md +2 -1
- package/lib/config.js +1 -0
- package/package.json +1 -1
- package/skills/alloy-guides/SKILL.md +18 -179
- package/skills/alloy-guides/references/CLI_TASKS.md +17 -216
- package/skills/alloy-guides/references/CONCEPTS.md +27 -162
- package/skills/alloy-guides/references/CONTROLLERS.md +38 -236
- package/skills/alloy-guides/references/MODELS.md +47 -723
- package/skills/alloy-guides/references/MODELS_ADVANCED.md +21 -482
- package/skills/alloy-guides/references/VIEWS_DYNAMIC.md +12 -222
- package/skills/alloy-guides/references/VIEWS_STYLES.md +39 -358
- package/skills/alloy-guides/references/VIEWS_XML.md +36 -552
- package/skills/alloy-guides/references/WIDGETS.md +49 -127
- package/skills/alloy-howtos/SKILL.md +14 -169
- package/skills/alloy-howtos/references/best_practices.md +9 -113
- package/skills/alloy-howtos/references/cli_reference.md +18 -223
- package/skills/alloy-howtos/references/config_files.md +50 -133
- package/skills/alloy-howtos/references/debugging_troubleshooting.md +19 -63
- package/skills/alloy-howtos/references/samples.md +21 -138
- package/skills/ti-api/SKILL.md +10 -2
- package/skills/ti-api/references/api-android.md +36 -2
- package/skills/ti-api/references/api-app-platform.md +39 -3
- package/skills/ti-api/references/api-core.md +50 -18
- package/skills/ti-api/references/api-data-network.md +49 -35
- package/skills/ti-api/references/api-media.md +45 -27
- package/skills/ti-api/references/api-services.md +39 -9
- package/skills/ti-api/references/api-ui-android.md +33 -13
- package/skills/ti-api/references/api-ui-extras.md +41 -15
- package/skills/ti-api/references/api-ui-ios-animator.md +42 -26
- package/skills/ti-api/references/api-ui-ios.md +74 -2
- package/skills/ti-api/references/api-ui-lists.md +32 -16
- package/skills/ti-api/references/api-ui-text-input.md +34 -17
- package/skills/ti-api/references/api-ui-views.md +27 -1
- package/skills/ti-api/references/api-ui-windows-navigation.md +32 -18
- package/skills/ti-api/references/api-xml-global.md +66 -16
- package/skills/ti-create-release/SKILL.md +98 -0
- package/skills/ti-create-release/references/module-discovery.md +69 -0
- package/skills/ti-expert/references/adaptive-layouts.md +1 -1
- package/skills/ti-guides/SKILL.md +37 -76
- package/skills/ti-guides/references/advanced-data-and-images.md +122 -126
- package/skills/ti-guides/references/android-manifest.md +24 -83
- package/skills/ti-guides/references/app-distribution.md +31 -377
- package/skills/ti-guides/references/application-frameworks.md +127 -335
- package/skills/ti-guides/references/cli-reference.md +184 -633
- package/skills/ti-guides/references/commonjs-advanced.md +81 -231
- package/skills/ti-guides/references/compatibility-matrix.md +36 -75
- package/skills/ti-guides/references/hello-world.md +95 -70
- package/skills/ti-guides/references/hyperloop-native-access.md +52 -448
- package/skills/ti-guides/references/resources.md +174 -142
- package/skills/ti-guides/references/sdk-release-notes.md +28 -71
- package/skills/ti-guides/references/tiapp-config.md +222 -598
- package/skills/ti-howtos/SKILL.md +23 -123
- package/skills/ti-howtos/references/cross-platform-development.md +119 -324
- package/skills/ti-howtos/references/debugging-profiling.md +77 -445
- package/skills/ti-howtos/references/extending-titanium.md +199 -673
- package/skills/ti-howtos/references/local-data-sources.md +87 -300
- package/skills/ti-howtos/references/location-and-maps.md +86 -213
- package/skills/ti-howtos/references/media-apis.md +103 -223
- package/skills/ti-howtos/references/notification-services.md +86 -506
- package/skills/ti-howtos/references/remote-data-sources.md +97 -316
- package/skills/ti-howtos/references/using-modules.md +77 -133
- package/skills/ti-ui/SKILL.md +28 -143
- package/skills/ti-ui/references/icons-and-splash-screens.md +74 -403
- package/skills/ti-ui/references/layouts-and-positioning.md +175 -402
- package/skills/ti-ui/references/listviews-and-performance.md +100 -703
- package/skills/ti-ui/references/platform-conventions.md +180 -0
- package/skills/ti-ui/references/user-interface.md +43 -0
- package/skills/alloy-guides/references/VIEWS_WITHOUT_CONTROLLERS.md +0 -102
- package/skills/alloy-howtos/references/custom_tags.md +0 -148
- package/skills/ti-guides/references/coding-best-practices.md +0 -149
- package/skills/ti-guides/references/javascript-primer.md +0 -414
- package/skills/ti-guides/references/reserved-words.md +0 -36
- package/skills/ti-guides/references/style-and-conventions.md +0 -103
- package/skills/ti-howtos/references/android-platform-deep-dives.md +0 -624
- package/skills/ti-howtos/references/automation-fastlane-appium.md +0 -96
- package/skills/ti-howtos/references/buffer-codec-streams.md +0 -162
- package/skills/ti-howtos/references/google-maps-v2.md +0 -172
- package/skills/ti-howtos/references/ios-map-kit.md +0 -149
- package/skills/ti-howtos/references/ios-platform-deep-dives.md +0 -611
- package/skills/ti-howtos/references/tutorials.md +0 -565
- package/skills/ti-howtos/references/web-content-integration.md +0 -287
- package/skills/ti-howtos/references/webpack-build-pipeline.md +0 -124
- package/skills/ti-ui/references/accessibility-deep-dive.md +0 -288
- package/skills/ti-ui/references/animation-and-matrices.md +0 -569
- package/skills/ti-ui/references/application-structures.md +0 -626
- package/skills/ti-ui/references/custom-fonts-styling.md +0 -549
- package/skills/ti-ui/references/event-handling.md +0 -401
- package/skills/ti-ui/references/gestures.md +0 -448
- package/skills/ti-ui/references/orientation.md +0 -374
- package/skills/ti-ui/references/platform-ui-android.md +0 -727
- package/skills/ti-ui/references/platform-ui-ios.md +0 -576
- package/skills/ti-ui/references/scrolling-views.md +0 -288
- package/skills/ti-ui/references/tableviews.md +0 -542
|
@@ -1,569 +0,0 @@
|
|
|
1
|
-
# Animation, matrices, and transitions
|
|
2
|
-
|
|
3
|
-
<!-- TOC-START -->
|
|
4
|
-
## Contents
|
|
5
|
-
|
|
6
|
-
- [1. Overview](#1-overview)
|
|
7
|
-
- [2. Basic animations](#2-basic-animations)
|
|
8
|
-
- [3. 2D matrix animations](#3-2d-matrix-animations)
|
|
9
|
-
- [4. 3D matrix animations (iOS only)](#4-3d-matrix-animations-ios-only)
|
|
10
|
-
- [5. iOS transitions](#5-ios-transitions)
|
|
11
|
-
- [6. Dynamic animations (iOS only)](#6-dynamic-animations-ios-only)
|
|
12
|
-
- [7. Animation events](#7-animation-events)
|
|
13
|
-
- [8. Common animation patterns](#8-common-animation-patterns)
|
|
14
|
-
- [9. Performance considerations](#9-performance-considerations)
|
|
15
|
-
- [10. Platform differences](#10-platform-differences)
|
|
16
|
-
- [Best practices](#best-practices)
|
|
17
|
-
|
|
18
|
-
<!-- TOC-END -->
|
|
19
|
-
|
|
20
|
-
## 1. Overview
|
|
21
|
-
|
|
22
|
-
Animations make state changes easier to read and can help an interface feel responsive. Use them with restraint. Titanium includes:
|
|
23
|
-
- Basic property animations (opacity, position, color, etc.)
|
|
24
|
-
- 2D matrix transforms (scale, rotate, translate) for iOS and Android
|
|
25
|
-
- 3D matrix transforms (x, y, z space) for iOS only
|
|
26
|
-
- iOS transitions (flip, curl, etc.)
|
|
27
|
-
- Dynamic, physics-based animations for iOS only
|
|
28
|
-
|
|
29
|
-
## 2. Basic animations
|
|
30
|
-
|
|
31
|
-
### Property animation syntax
|
|
32
|
-
|
|
33
|
-
```javascript
|
|
34
|
-
// Method 1: Direct object
|
|
35
|
-
view.animate({
|
|
36
|
-
opacity: 0,
|
|
37
|
-
duration: 2000
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Method 2: Animation object (reusable)
|
|
41
|
-
const fadeOut = Ti.UI.createAnimation({
|
|
42
|
-
opacity: 0,
|
|
43
|
-
duration: 2000
|
|
44
|
-
});
|
|
45
|
-
view.animate(fadeOut);
|
|
46
|
-
|
|
47
|
-
// Method 3: With callback
|
|
48
|
-
view.animate({
|
|
49
|
-
opacity: 0,
|
|
50
|
-
duration: 2000
|
|
51
|
-
}, () => {
|
|
52
|
-
Ti.API.info('Animation complete');
|
|
53
|
-
// Optional: reverse animation
|
|
54
|
-
view.animate({
|
|
55
|
-
opacity: 1,
|
|
56
|
-
duration: 2000
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### Animation properties
|
|
62
|
-
|
|
63
|
-
| Property | Description | Default |
|
|
64
|
-
| -------------------------------- | ------------------------- | ----------------------------------- |
|
|
65
|
-
| `duration` | Duration in milliseconds | 0 |
|
|
66
|
-
| `delay` | Delay before starting | 0 |
|
|
67
|
-
| `curve` | Easing function | `Ti.UI.ANIMATION_CURVE_EASE_IN_OUT` |
|
|
68
|
-
| `autoreverse` | Return to original state | `false` |
|
|
69
|
-
| `repeat` | Number of times to repeat | 0 |
|
|
70
|
-
| `opacity` | Target opacity (0-1) | - |
|
|
71
|
-
| `top`, `left`, `bottom`, `right` | Position values | - |
|
|
72
|
-
| `width`, `height` | Size values | - |
|
|
73
|
-
| `backgroundColor` | Target color | - |
|
|
74
|
-
| `transform` | Matrix transformation | - |
|
|
75
|
-
| `view` | View for transition | - |
|
|
76
|
-
| `transition` | Transition type (iOS) | - |
|
|
77
|
-
|
|
78
|
-
### Animation curves (easing)
|
|
79
|
-
|
|
80
|
-
```javascript
|
|
81
|
-
// Available curves
|
|
82
|
-
Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
|
|
83
|
-
Ti.UI.ANIMATION_CURVE_EASE_IN
|
|
84
|
-
Ti.UI.ANIMATION_CURVE_EASE_OUT
|
|
85
|
-
Ti.UI.ANIMATION_CURVE_LINEAR
|
|
86
|
-
Ti.UI.ANIMATION_CURVE_SPRING // iOS only
|
|
87
|
-
|
|
88
|
-
// Example
|
|
89
|
-
view.animate({
|
|
90
|
-
left: 100,
|
|
91
|
-
duration: 1000,
|
|
92
|
-
curve: Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
|
|
93
|
-
});
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### Reversing animation
|
|
97
|
-
|
|
98
|
-
```javascript
|
|
99
|
-
// Use autoreverse for simple reversal
|
|
100
|
-
view.animate({
|
|
101
|
-
opacity: 0,
|
|
102
|
-
duration: 2000,
|
|
103
|
-
autoreverse: true
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
// Or manual reversal with callback
|
|
107
|
-
view.animate({
|
|
108
|
-
opacity: 0,
|
|
109
|
-
duration: 2000
|
|
110
|
-
}, () => {
|
|
111
|
-
view.animate({
|
|
112
|
-
opacity: 1,
|
|
113
|
-
duration: 2000
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### Repeating animation
|
|
119
|
-
|
|
120
|
-
```javascript
|
|
121
|
-
// Repeat 3 times
|
|
122
|
-
view.animate({
|
|
123
|
-
opacity: 0,
|
|
124
|
-
duration: 500,
|
|
125
|
-
repeat: 3
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// Infinite loop (with autoreverse)
|
|
129
|
-
view.animate({
|
|
130
|
-
opacity: 0,
|
|
131
|
-
duration: 500,
|
|
132
|
-
autoreverse: true,
|
|
133
|
-
repeat: Number.MAX_VALUE // Infinite
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
// Stop animation
|
|
137
|
-
view.animate({ opacity: view.opacity, duration: 0 });
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
## 3. 2D matrix animations
|
|
141
|
-
|
|
142
|
-
2D matrices work on both iOS and Android. They transform the x and y plane with scale, rotate, translate, and skew.
|
|
143
|
-
|
|
144
|
-
### Basic 2D transform
|
|
145
|
-
|
|
146
|
-
```javascript
|
|
147
|
-
// Create matrix
|
|
148
|
-
let matrix2d = Ti.UI.create2DMatrix();
|
|
149
|
-
|
|
150
|
-
// Apply transformations
|
|
151
|
-
matrix2d = matrix2d.rotate(20); // Rotate 20 degrees
|
|
152
|
-
matrix2d = matrix2d.scale(1.5); // Scale 1.5x
|
|
153
|
-
matrix2d = matrix2d.translate(50, 50); // Move 50px right, 50px down
|
|
154
|
-
|
|
155
|
-
// Apply animation
|
|
156
|
-
view.animate({
|
|
157
|
-
transform: matrix2d,
|
|
158
|
-
duration: 2000,
|
|
159
|
-
autoreverse: true,
|
|
160
|
-
repeat: 3
|
|
161
|
-
});
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### 2D matrix methods
|
|
165
|
-
|
|
166
|
-
| Method | Description |
|
|
167
|
-
| ------------------- | ------------------------- |
|
|
168
|
-
| `rotate(degrees)` | Rotate clockwise |
|
|
169
|
-
| `scale(sx, sy)` | Scale (sy defaults to sx) |
|
|
170
|
-
| `translate(dx, dy)` | Move by delta |
|
|
171
|
-
| `skew(x, y)` | Skew or shear |
|
|
172
|
-
| `invert()` | Invert matrix |
|
|
173
|
-
| `multiply(matrix)` | Multiply matrices |
|
|
174
|
-
| `length` | Get matrix length |
|
|
175
|
-
|
|
176
|
-
### Sequential transformations
|
|
177
|
-
|
|
178
|
-
Order matters.
|
|
179
|
-
|
|
180
|
-
```javascript
|
|
181
|
-
// Rotate THEN scale
|
|
182
|
-
const matrix1 = Ti.UI.create2DMatrix()
|
|
183
|
-
.rotate(45)
|
|
184
|
-
.scale(2);
|
|
185
|
-
|
|
186
|
-
// Scale THEN rotate (different result)
|
|
187
|
-
const matrix2 = Ti.UI.create2DMatrix()
|
|
188
|
-
.scale(2)
|
|
189
|
-
.rotate(45);
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### Identity (reset) transform
|
|
193
|
-
|
|
194
|
-
```javascript
|
|
195
|
-
// Reset to original state
|
|
196
|
-
const identity = Ti.UI.create2DMatrix();
|
|
197
|
-
view.animate({
|
|
198
|
-
transform: identity,
|
|
199
|
-
duration: 500
|
|
200
|
-
});
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
## 4. 3D matrix animations (iOS only)
|
|
204
|
-
|
|
205
|
-
3D matrices work in x, y, and z space on iOS only.
|
|
206
|
-
|
|
207
|
-
### Basic 3D transform
|
|
208
|
-
|
|
209
|
-
```javascript
|
|
210
|
-
let matrix3d = Ti.UI.create3DMatrix();
|
|
211
|
-
|
|
212
|
-
// Rotate around axis vector (x, y, z)
|
|
213
|
-
matrix3d = matrix3d.rotate(180, 1, 1, 0); // 180 degrees around diagonal
|
|
214
|
-
|
|
215
|
-
// Scale in 3 dimensions
|
|
216
|
-
matrix3d = matrix3d.scale(2, 2, 2);
|
|
217
|
-
|
|
218
|
-
// Apply animation
|
|
219
|
-
view.animate({
|
|
220
|
-
transform: matrix3d,
|
|
221
|
-
duration: 2000,
|
|
222
|
-
autoreverse: true
|
|
223
|
-
});
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
### 3D matrix methods
|
|
227
|
-
|
|
228
|
-
| Method | Description |
|
|
229
|
-
| -------------------------- | -------------------- |
|
|
230
|
-
| `rotate(degrees, x, y, z)` | Rotate around vector |
|
|
231
|
-
| `scale(sx, sy, sz)` | Scale in 3D |
|
|
232
|
-
| `translate(dx, dy, dz)` | Move in 3D |
|
|
233
|
-
| `invert()` | Invert matrix |
|
|
234
|
-
| `multiply(matrix)` | Multiply matrices |
|
|
235
|
-
| `perspective(p)` | Set perspective |
|
|
236
|
-
|
|
237
|
-
### Flip card effect
|
|
238
|
-
|
|
239
|
-
```javascript
|
|
240
|
-
const frontView = Ti.UI.createView({
|
|
241
|
-
backgroundColor: 'red',
|
|
242
|
-
width: 200, height: 200
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
const backView = Ti.UI.createView({
|
|
246
|
-
backgroundColor: 'blue',
|
|
247
|
-
width: 200, height: 200
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
let isFlipped = false;
|
|
251
|
-
|
|
252
|
-
frontView.addEventListener('click', () => {
|
|
253
|
-
const matrix = Ti.UI.create3DMatrix().rotate(180, 0, 1, 0);
|
|
254
|
-
|
|
255
|
-
if (!isFlipped) {
|
|
256
|
-
frontView.animate({
|
|
257
|
-
transform: matrix,
|
|
258
|
-
duration: 500,
|
|
259
|
-
visible: false
|
|
260
|
-
});
|
|
261
|
-
backView.transform = matrix;
|
|
262
|
-
backView.animate({
|
|
263
|
-
transform: Ti.UI.create3DMatrix(),
|
|
264
|
-
duration: 500,
|
|
265
|
-
visible: true
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
isFlipped = !isFlipped;
|
|
269
|
-
});
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
## 5. iOS transitions
|
|
273
|
-
|
|
274
|
-
Transitions are built-in animations for switching between views and windows.
|
|
275
|
-
|
|
276
|
-
### Transition constants
|
|
277
|
-
|
|
278
|
-
```javascript
|
|
279
|
-
Ti.UI.iPhone.AnimationStyle.CURL_UP
|
|
280
|
-
Ti.UI.iPhone.AnimationStyle.CURL_DOWN
|
|
281
|
-
Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT
|
|
282
|
-
Ti.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT
|
|
283
|
-
Ti.UI.iPhone.AnimationStyle.NONE
|
|
284
|
-
Ti.UI.iPhone.AnimationStyle.OPAQUE_FADE // Fade with black (not transparent)
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
### View transition
|
|
288
|
-
|
|
289
|
-
```javascript
|
|
290
|
-
const container = Ti.UI.createView({ width: 300, height: 300 });
|
|
291
|
-
const box1 = Ti.UI.createView({ backgroundColor: 'red' });
|
|
292
|
-
const box2 = Ti.UI.createView({ backgroundColor: 'blue' });
|
|
293
|
-
container.add(box1);
|
|
294
|
-
|
|
295
|
-
let selectedIndex = 0;
|
|
296
|
-
|
|
297
|
-
container.addEventListener('click', () => {
|
|
298
|
-
if (selectedIndex % 2 === 0) {
|
|
299
|
-
container.animate({
|
|
300
|
-
view: box2,
|
|
301
|
-
transition: Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT
|
|
302
|
-
});
|
|
303
|
-
} else {
|
|
304
|
-
container.animate({
|
|
305
|
-
view: box1,
|
|
306
|
-
transition: Ti.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
selectedIndex++;
|
|
310
|
-
});
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
### Window transition (NavigationWindow)
|
|
314
|
-
|
|
315
|
-
```javascript
|
|
316
|
-
const navWindow = Ti.UI.createNavigationWindow({
|
|
317
|
-
window: Ti.UI.createWindow({ backgroundColor: 'white' })
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
const win1 = Ti.UI.createWindow({
|
|
321
|
-
title: 'Window 1',
|
|
322
|
-
backgroundColor: 'red',
|
|
323
|
-
transitionAnimation: Ti.UI.iOS.createTransitionAnimation({
|
|
324
|
-
hide: Ti.UI.createAnimation({
|
|
325
|
-
transform: Ti.UI.create3DMatrix().translate(-300, 0, 0),
|
|
326
|
-
duration: 500
|
|
327
|
-
}),
|
|
328
|
-
show: Ti.UI.createAnimation({
|
|
329
|
-
transform: Ti.UI.create3DMatrix(),
|
|
330
|
-
duration: 500
|
|
331
|
-
})
|
|
332
|
-
})
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
navWindow.openWindow(win1);
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
## 6. Dynamic animations (iOS only)
|
|
339
|
-
|
|
340
|
-
Physics-based animations use `Ti.UI.iOS.Animator`.
|
|
341
|
-
|
|
342
|
-
### Gravity animation
|
|
343
|
-
|
|
344
|
-
```javascript
|
|
345
|
-
const animator = Ti.UI.iOS.createAnimator({
|
|
346
|
-
referenceView: containerView
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
// Add gravity behavior
|
|
350
|
-
const gravity = Ti.UI.iOS.createGravityBehavior({
|
|
351
|
-
gravityDirection: { x: 0.0, y: 1.0 } // Downward
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
// Add items to gravity
|
|
355
|
-
gravity.addItem(animatedView);
|
|
356
|
-
animator.addBehavior(gravity);
|
|
357
|
-
|
|
358
|
-
// Add collision boundaries
|
|
359
|
-
const collision = Ti.UI.iOS.createCollisionBehavior({
|
|
360
|
-
collisionMode: Ti.UI.iOS.COLLISION_MODE_BOUNDARY,
|
|
361
|
-
boundary: containerView.toImage()
|
|
362
|
-
});
|
|
363
|
-
collision.addItem(animatedView);
|
|
364
|
-
animator.addBehavior(collision);
|
|
365
|
-
|
|
366
|
-
animator.startAnimator();
|
|
367
|
-
```
|
|
368
|
-
|
|
369
|
-
### Attachment (spring) behavior
|
|
370
|
-
|
|
371
|
-
```javascript
|
|
372
|
-
const attachment = Ti.UI.iOS.createAttachmentBehavior({
|
|
373
|
-
items: [view1, view2],
|
|
374
|
-
anchorPoint: { x: 150, y: 150 },
|
|
375
|
-
frequency: 1.0, // Oscillations per second
|
|
376
|
-
damping: 0.1, // Bounciness (0 = none, 1 = no bounce)
|
|
377
|
-
length: 100 // Distance between items
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
animator.addBehavior(attachment);
|
|
381
|
-
animator.startAnimator();
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
### Push behavior
|
|
385
|
-
|
|
386
|
-
```javascript
|
|
387
|
-
const push = Ti.UI.iOS.createPushBehavior({
|
|
388
|
-
pushDirection: { x: 1.0, y: 0.0 }, // Rightward
|
|
389
|
-
mode: Ti.UI.iOS.PUSH_MODE_INSTANTANEOUS,
|
|
390
|
-
pushMagnitude: 5.0
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
push.addItem(viewToPush);
|
|
394
|
-
animator.addBehavior(push);
|
|
395
|
-
```
|
|
396
|
-
|
|
397
|
-
## 7. Animation events
|
|
398
|
-
|
|
399
|
-
### Animation lifecycle
|
|
400
|
-
|
|
401
|
-
```javascript
|
|
402
|
-
const animation = Ti.UI.createAnimation({
|
|
403
|
-
opacity: 0,
|
|
404
|
-
duration: 2000
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
// 'start' event
|
|
408
|
-
animation.addEventListener('start', (e) => {
|
|
409
|
-
Ti.API.info('Animation started');
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
// 'complete' event
|
|
413
|
-
animation.addEventListener('complete', (e) => {
|
|
414
|
-
Ti.API.info(`Animation complete. Was canceled: ${e.cancelled}`);
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
view.animate(animation);
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
### Stopping animations
|
|
421
|
-
|
|
422
|
-
```javascript
|
|
423
|
-
// Method 1: Overwrite with new animation (duration: 0)
|
|
424
|
-
view.animate({
|
|
425
|
-
opacity: view.opacity,
|
|
426
|
-
duration: 0,
|
|
427
|
-
curve: Ti.UI.ANIMATION_CURVE_LINEAR
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
// Method 2: Remove from parent
|
|
431
|
-
parent.remove(view);
|
|
432
|
-
|
|
433
|
-
// Method 3: Set visible to false
|
|
434
|
-
view.visible = false;
|
|
435
|
-
```
|
|
436
|
-
|
|
437
|
-
## 8. Common animation patterns
|
|
438
|
-
|
|
439
|
-
### Fade in and out
|
|
440
|
-
|
|
441
|
-
```javascript
|
|
442
|
-
function fadeIn(view, duration, callback) {
|
|
443
|
-
view.opacity = 0;
|
|
444
|
-
view.animate({ opacity: 1, duration: duration }, callback);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
function fadeOut(view, duration, callback) {
|
|
448
|
-
view.animate({ opacity: 0, duration: duration }, function() {
|
|
449
|
-
view.visible = false;
|
|
450
|
-
if (callback) callback();
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
```
|
|
454
|
-
|
|
455
|
-
### Slide in
|
|
456
|
-
|
|
457
|
-
```javascript
|
|
458
|
-
function slideInFromRight(view, duration) {
|
|
459
|
-
view.left = Ti.Platform.displayCaps.platformWidth; // Start off-screen
|
|
460
|
-
view.animate({
|
|
461
|
-
left: 0,
|
|
462
|
-
duration: duration,
|
|
463
|
-
curve: Ti.UI.ANIMATION_CURVE_EASE_OUT
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
```
|
|
467
|
-
|
|
468
|
-
### Pulse animation
|
|
469
|
-
|
|
470
|
-
```javascript
|
|
471
|
-
function pulse(view) {
|
|
472
|
-
view.animate({
|
|
473
|
-
transform: Ti.UI.create2DMatrix().scale(1.1),
|
|
474
|
-
duration: 150,
|
|
475
|
-
autoreverse: true,
|
|
476
|
-
curve: Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
|
|
477
|
-
}, function() {
|
|
478
|
-
// Optional: repeat
|
|
479
|
-
// pulse(view);
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
```
|
|
483
|
-
|
|
484
|
-
### Shake animation
|
|
485
|
-
|
|
486
|
-
```javascript
|
|
487
|
-
function shake(view) {
|
|
488
|
-
const shake = Ti.UI.createAnimation({
|
|
489
|
-
transform: Ti.UI.create2DMatrix().translate(10, 0),
|
|
490
|
-
duration: 50,
|
|
491
|
-
autoreverse: true,
|
|
492
|
-
repeat: 5
|
|
493
|
-
});
|
|
494
|
-
view.animate(shake);
|
|
495
|
-
}
|
|
496
|
-
```
|
|
497
|
-
|
|
498
|
-
### Bounce in
|
|
499
|
-
|
|
500
|
-
```javascript
|
|
501
|
-
function bounceIn(view) {
|
|
502
|
-
view.transform = Ti.UI.create2DMatrix().scale(0);
|
|
503
|
-
view.animate({
|
|
504
|
-
transform: Ti.UI.create2DMatrix().scale(1.2),
|
|
505
|
-
duration: 300,
|
|
506
|
-
curve: Ti.UI.ANIMATION_CURVE_EASE_OUT
|
|
507
|
-
}, function() {
|
|
508
|
-
view.animate({
|
|
509
|
-
transform: Ti.UI.create2DMatrix().scale(1.0),
|
|
510
|
-
duration: 200,
|
|
511
|
-
curve: Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
|
|
512
|
-
});
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
```
|
|
516
|
-
|
|
517
|
-
## 9. Performance considerations
|
|
518
|
-
|
|
519
|
-
Do:
|
|
520
|
-
- Use hardware-accelerated properties (opacity, transform).
|
|
521
|
-
- Animate `transform` instead of `top` or `left` when possible.
|
|
522
|
-
- Use `autoreverse` for simple back-and-forth.
|
|
523
|
-
- Cache animation objects for reuse.
|
|
524
|
-
- Stop unused animations.
|
|
525
|
-
|
|
526
|
-
Don't:
|
|
527
|
-
- Animate `width` or `height` since it triggers layout recalculation.
|
|
528
|
-
- Animate too many views at once.
|
|
529
|
-
- Use JavaScript loops for animation.
|
|
530
|
-
- Animate properties that trigger reflow.
|
|
531
|
-
|
|
532
|
-
### Bad vs good
|
|
533
|
-
|
|
534
|
-
```javascript
|
|
535
|
-
// BAD - Triggers layout
|
|
536
|
-
view.animate({
|
|
537
|
-
left: view.left + 100,
|
|
538
|
-
top: view.top + 100,
|
|
539
|
-
duration: 500
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
// GOOD - Hardware accelerated
|
|
543
|
-
view.animate({
|
|
544
|
-
transform: Ti.UI.create2DMatrix().translate(100, 100),
|
|
545
|
-
duration: 500
|
|
546
|
-
});
|
|
547
|
-
```
|
|
548
|
-
|
|
549
|
-
## 10. Platform differences
|
|
550
|
-
|
|
551
|
-
### iOS vs Android
|
|
552
|
-
|
|
553
|
-
| Feature | iOS | Android |
|
|
554
|
-
| ------------------ | ------------ | ----------------- |
|
|
555
|
-
| 2D matrix | Full support | Full support |
|
|
556
|
-
| 3D matrix | Full support | Not supported |
|
|
557
|
-
| Transitions | Full support | Not supported |
|
|
558
|
-
| Dynamic animations | Full support | Not supported |
|
|
559
|
-
| Curves | +SPRING | Basic curves only |
|
|
560
|
-
| Color animation | RGBA full | Basic colors |
|
|
561
|
-
|
|
562
|
-
## Best practices
|
|
563
|
-
|
|
564
|
-
1. Keep animations simple. The more complex they get, the harder they are to debug.
|
|
565
|
-
2. Test on devices. Simulator performance is not the same.
|
|
566
|
-
3. Consider accessibility. Respect the `reduceMotion` setting.
|
|
567
|
-
4. Use sensible duration. 200 to 300 ms for subtle motion, about 500 ms for noticeable.
|
|
568
|
-
5. Avoid long animation chains. Prefer a callback instead of deep nesting.
|
|
569
|
-
6. Clean up. Remove event listeners on animation completion.
|