@rafaelaugusto/jolt 0.1.0-beta.12 → 0.1.0-beta.13

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.
Files changed (103) hide show
  1. package/README.md +4 -1
  2. package/dist/animate.d.ts +6 -4
  3. package/dist/animate.d.ts.map +1 -1
  4. package/dist/animate.js +3 -1
  5. package/dist/animate.js.map +1 -1
  6. package/dist/drag.js +3 -3
  7. package/dist/drag.js.map +1 -1
  8. package/dist/driver/android.d.ts.map +1 -1
  9. package/dist/driver/android.js +2 -0
  10. package/dist/driver/android.js.map +1 -1
  11. package/dist/driver/frame.d.ts +3 -0
  12. package/dist/driver/frame.d.ts.map +1 -0
  13. package/dist/driver/frame.js +7 -0
  14. package/dist/driver/frame.js.map +1 -0
  15. package/dist/driver/index.d.ts +2 -0
  16. package/dist/driver/index.d.ts.map +1 -1
  17. package/dist/driver/index.js.map +1 -1
  18. package/dist/driver/ios.d.ts.map +1 -1
  19. package/dist/driver/ios.js +2 -0
  20. package/dist/driver/ios.js.map +1 -1
  21. package/dist/engine.d.ts +2 -1
  22. package/dist/engine.d.ts.map +1 -1
  23. package/dist/engine.js +23 -2
  24. package/dist/engine.js.map +1 -1
  25. package/dist/image-effect.d.ts +1 -0
  26. package/dist/image-effect.d.ts.map +1 -1
  27. package/dist/image-effect.js +10 -2
  28. package/dist/image-effect.js.map +1 -1
  29. package/dist/index.d.ts +5 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +2 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/motion-scope.d.ts +2 -1
  34. package/dist/motion-scope.d.ts.map +1 -1
  35. package/dist/motion-scope.js +4 -1
  36. package/dist/motion-scope.js.map +1 -1
  37. package/dist/motion-value.d.ts +45 -8
  38. package/dist/motion-value.d.ts.map +1 -1
  39. package/dist/motion-value.js +289 -91
  40. package/dist/motion-value.js.map +1 -1
  41. package/dist/native/index.d.ts +6 -0
  42. package/dist/native/index.d.ts.map +1 -0
  43. package/dist/native/index.js +3 -0
  44. package/dist/native/index.js.map +1 -0
  45. package/dist/native-properties.d.ts +28 -0
  46. package/dist/native-properties.d.ts.map +1 -0
  47. package/dist/native-properties.js +154 -0
  48. package/dist/native-properties.js.map +1 -0
  49. package/dist/native-property-driver.d.ts +19 -0
  50. package/dist/native-property-driver.d.ts.map +1 -0
  51. package/dist/native-property-driver.js +69 -0
  52. package/dist/native-property-driver.js.map +1 -0
  53. package/dist/native-property.d.ts +35 -0
  54. package/dist/native-property.d.ts.map +1 -0
  55. package/dist/native-property.js +277 -0
  56. package/dist/native-property.js.map +1 -0
  57. package/dist/playback-group.d.ts.map +1 -1
  58. package/dist/playback-group.js +17 -1
  59. package/dist/playback-group.js.map +1 -1
  60. package/dist/playback.d.ts +15 -0
  61. package/dist/playback.d.ts.map +1 -1
  62. package/dist/playback.js +23 -0
  63. package/dist/playback.js.map +1 -1
  64. package/dist/sequence.d.ts +24 -0
  65. package/dist/sequence.d.ts.map +1 -1
  66. package/dist/sequence.js +181 -19
  67. package/dist/sequence.js.map +1 -1
  68. package/dist/timed-animation.d.ts +38 -0
  69. package/dist/timed-animation.d.ts.map +1 -0
  70. package/dist/timed-animation.js +177 -0
  71. package/dist/timed-animation.js.map +1 -0
  72. package/dist/value-observers.d.ts +19 -0
  73. package/dist/value-observers.d.ts.map +1 -0
  74. package/dist/value-observers.js +111 -0
  75. package/dist/value-observers.js.map +1 -0
  76. package/dist/value-track.d.ts +13 -0
  77. package/dist/value-track.d.ts.map +1 -0
  78. package/dist/value-track.js +59 -0
  79. package/dist/value-track.js.map +1 -0
  80. package/package.json +6 -2
  81. package/src/android-plugin.d.ts +37 -0
  82. package/src/animate.ts +13 -7
  83. package/src/drag.ts +3 -3
  84. package/src/driver/android.ts +2 -0
  85. package/src/driver/frame.ts +10 -0
  86. package/src/driver/index.ts +2 -0
  87. package/src/driver/ios.ts +2 -0
  88. package/src/engine.ts +23 -2
  89. package/src/image-effect.ts +10 -2
  90. package/src/index.ts +5 -0
  91. package/src/ios-plugin.d.ts +33 -0
  92. package/src/motion-scope.ts +5 -1
  93. package/src/motion-value.ts +331 -99
  94. package/src/native/index.ts +16 -0
  95. package/src/native-properties.ts +188 -0
  96. package/src/native-property-driver.ts +123 -0
  97. package/src/native-property.ts +353 -0
  98. package/src/playback-group.ts +17 -1
  99. package/src/playback.ts +41 -0
  100. package/src/sequence.ts +209 -20
  101. package/src/timed-animation.ts +192 -0
  102. package/src/value-observers.ts +133 -0
  103. package/src/value-track.ts +71 -0
package/src/engine.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import {
2
2
  createClock,
3
+ registerPlayback,
3
4
  validateProgress,
4
5
  type PlaybackAnimation,
5
6
  type PlaybackClock,
6
7
  type PlaybackCommand,
7
8
  } from './playback.js'
8
- import type { View } from '@nativescript/core'
9
+ import { Application, type View } from '@nativescript/core'
9
10
  import { getDriver } from './driver/index.js'
10
11
  import { playHaptics, type HapticOptions } from './haptics.js'
11
12
  import { readValue, writeValue, type Property } from './properties.js'
@@ -109,7 +110,9 @@ export class ViewAnimation implements PlaybackAnimation {
109
110
  private readyListener: (() => void) | undefined
110
111
  private readonly endless: boolean
111
112
  private readonly timingListeners = new Set<() => void>()
113
+ private readonly playbackChanged: () => void
112
114
  private timingChanged() {
115
+ this.playbackChanged()
113
116
  for (const callback of [...this.timingListeners]) callback()
114
117
  }
115
118
 
@@ -142,6 +145,7 @@ export class ViewAnimation implements PlaybackAnimation {
142
145
  if (this.settled) return
143
146
  if (!this.started) {
144
147
  this.pendingProgress = value
148
+ this.timingChanged()
145
149
  return
146
150
  }
147
151
  this.seekTime(this.duration * value)
@@ -280,7 +284,12 @@ export class ViewAnimation implements PlaybackAnimation {
280
284
  getDriver().stop(this.view, handle)
281
285
  this.playEntry(entry, elapsed)
282
286
  }
283
- private unloaded = () => this.stop()
287
+ private unloaded = () => {
288
+ // NativeScript unloads the root view when iOS enters the background.
289
+ // An explicitly paused owner can resume after that temporary unload.
290
+ if (this._paused && Application.suspended) return
291
+ this.stop()
292
+ }
284
293
 
285
294
  constructor(
286
295
  readonly view: View,
@@ -295,6 +304,18 @@ export class ViewAnimation implements PlaybackAnimation {
295
304
  !Number.isFinite(plan.transition.curve.duration)),
296
305
  )
297
306
  this.finished = new Promise((resolve) => (this.resolve = resolve))
307
+ this.playbackChanged = registerPlayback(this, () => ({
308
+ position: this.pendingProgress,
309
+ time:
310
+ this.pendingProgress === undefined
311
+ ? this.time()
312
+ : this.pendingProgress * this.duration,
313
+ duration: this.duration,
314
+ paused: this._paused,
315
+ ready: this.ready,
316
+ settled: this.settled,
317
+ completed: this.settled && this.complete,
318
+ }))
298
319
  setArrival(this, new Promise<void>((resolve) => (this.arrive = resolve)))
299
320
  setArrivalTiming(this, {
300
321
  read: () => ({
@@ -43,6 +43,7 @@ export interface ImageEffectDiagnostics {
43
43
  export interface ImageEffect extends Animation {
44
44
  readonly effect: ImageEffectName
45
45
  readonly paused: boolean
46
+ readonly duration: number
46
47
  /** Finite progress; distortion rejects seeking because it follows native touch input. */
47
48
  progress: number
48
49
  readonly diagnostics: Readonly<ImageEffectDiagnostics>
@@ -157,7 +158,7 @@ class Effect implements ImageEffect {
157
158
  for (const event of ['loaded', 'layoutChanged']) image.on(event, this.schedule)
158
159
  for (const event of ['imageSourceChange', 'stretchChange'])
159
160
  image.on(event, this.changed)
160
- image.on('unloaded', this.stop)
161
+ image.on('unloaded', this.unloaded)
161
162
  image.style.on('visibilityChange', this.visible)
162
163
  for (const event of surfaceChanges) image.style.on(event, this.changed)
163
164
  Application.on(Application.suspendEvent, this.suspend)
@@ -178,6 +179,9 @@ class Effect implements ImageEffect {
178
179
  get paused() {
179
180
  return this.userPaused
180
181
  }
182
+ get duration() {
183
+ return this.effect === 'distortion' ? Infinity : this.options.duration
184
+ }
181
185
  get progress() {
182
186
  return this.renderer?.progress ?? this.position
183
187
  }
@@ -240,7 +244,7 @@ class Effect implements ImageEffect {
240
244
  for (const event of ['loaded', 'layoutChanged']) this.image.off(event, this.schedule)
241
245
  for (const event of ['imageSourceChange', 'stretchChange'])
242
246
  this.image.off(event, this.changed)
243
- this.image.off('unloaded', this.stop)
247
+ this.image.off('unloaded', this.unloaded)
244
248
  this.image.style.off('visibilityChange', this.visible)
245
249
  for (const event of surfaceChanges) this.image.style.off(event, this.changed)
246
250
  Application.off(Application.suspendEvent, this.suspend)
@@ -272,6 +276,10 @@ class Effect implements ImageEffect {
272
276
  this.suspended = true
273
277
  this.renderer?.pause()
274
278
  }
279
+ private unloaded = () => {
280
+ if (Application.suspended && this.userPaused) return
281
+ this.stop()
282
+ }
275
283
  private resume = () => {
276
284
  this.suspended = false
277
285
  this.schedule()
package/src/index.ts CHANGED
@@ -1,3 +1,6 @@
1
+ export { timeline } from './sequence.js'
2
+ export type { TimelineAnimation, TimelineStep, PlayableAnimation } from './sequence.js'
3
+ export { playbackProgress } from './motion-value.js'
1
4
  export { animate, decay, set, stop } from './animate.js'
2
5
  export { bind, motionValue, scrollValue } from './motion-value.js'
3
6
  export type {
@@ -7,7 +10,9 @@ export type {
7
10
  MapOptions,
8
11
  MotionValue,
9
12
  ScrollValue,
13
+ ValueAnimationOptions,
10
14
  } from './motion-value.js'
15
+ export type { SubscribeOptions, ValueListener } from './value-observers.js'
11
16
  export { sequence } from './sequence.js'
12
17
  export type { Step, SequenceOptions, SequencePosition } from './sequence.js'
13
18
  export { press } from './press.js'
@@ -79,3 +79,36 @@ declare class JoltPhotoZoom extends NSObject {
79
79
  layout(): void
80
80
  stop(): void
81
81
  }
82
+
83
+ declare class JoltPropertySink extends NSObject {
84
+ static scalarTargetKeyPath(target: NSObject, keyPath: string): JoltPropertySink
85
+ readonly dimensions: number
86
+ readonly alive: boolean
87
+ readonly compiled: boolean
88
+ read(): NSArray<number>
89
+ write(values: NSArray<number>): void
90
+ dispose(): void
91
+ }
92
+ declare class JoltPropertyPlayer extends NSObject {
93
+ static startSinkTimesValuesFinalValueDurationDelayRepeatReverseCompletion(
94
+ sink: JoltPropertySink,
95
+ times: NSArray<number>,
96
+ values: NSArray<number>,
97
+ finalValue: NSArray<number>,
98
+ duration: number,
99
+ delay: number,
100
+ repeat: number,
101
+ reverse: boolean,
102
+ completion: (completed: boolean) => void,
103
+ ): JoltPropertyPlayer
104
+ readonly elapsed: number
105
+ readonly frames: number
106
+ static activeCount(): number
107
+ controlPaused(time: number, paused: boolean): void
108
+ cancel(): void
109
+ }
110
+ declare class JoltReferenceProperties extends NSObject {
111
+ static mapCoordinate(target: NSObject): JoltPropertySink
112
+ static mapCamera(target: NSObject): JoltPropertySink
113
+ static scenePose(target: NSObject): JoltPropertySink
114
+ }
@@ -4,7 +4,7 @@ import { drag } from './drag.js'
4
4
  import { gradient } from './gradient.js'
5
5
  import { animateLayout, type LayoutOptions } from './layout.js'
6
6
  import type { SpringName } from './transition.js'
7
- import { sequence } from './sequence.js'
7
+ import { sequence, timeline } from './sequence.js'
8
8
  import {
9
9
  motionStates,
10
10
  type MotionState,
@@ -38,6 +38,7 @@ export interface MotionScope {
38
38
  animate: typeof animate
39
39
  decay: typeof decay
40
40
  sequence: typeof sequence
41
+ timeline: typeof timeline
41
42
  press: typeof press
42
43
  drag: typeof drag
43
44
  /** Removed with the scope; suspending it stops a gradient animation where it is. */
@@ -197,6 +198,9 @@ export function motionScope(): MotionScope {
197
198
  decay(...args) {
198
199
  return startOwned(() => decay(...args))
199
200
  },
201
+ timeline(...args) {
202
+ return startOwned(() => timeline(...args))
203
+ },
200
204
  sequence(...args) {
201
205
  return startOwned(() => sequence(...args))
202
206
  },