@getcortexlabs/mavis 0.1.0-rc.12.2 → 0.1.0-rc.14

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 (95) hide show
  1. package/README.md +5 -5
  2. package/dist/native/flex-layout.ios.d.ts.map +1 -1
  3. package/dist/native/flex-layout.ios.js +4 -0
  4. package/dist/native/flex-layout.ios.js.map +1 -1
  5. package/dist/native/motion-region.d.ts.map +1 -1
  6. package/dist/native/motion-region.js +1 -0
  7. package/dist/native/motion-region.js.map +1 -1
  8. package/dist/native/motion-surface.d.ts +1 -1
  9. package/dist/native/motion-surface.d.ts.map +1 -1
  10. package/dist/native/motion-surface.js +55 -14
  11. package/dist/native/motion-surface.js.map +1 -1
  12. package/dist/native/moved-shadow.d.ts +5 -0
  13. package/dist/native/moved-shadow.d.ts.map +1 -0
  14. package/dist/native/moved-shadow.js +23 -0
  15. package/dist/native/moved-shadow.js.map +1 -0
  16. package/dist/native/scroll-motion.d.ts +1 -1
  17. package/dist/native/scroll-motion.d.ts.map +1 -1
  18. package/dist/native/scroll-motion.js +55 -16
  19. package/dist/native/scroll-motion.js.map +1 -1
  20. package/dist/native/section-scroll.d.ts +1 -1
  21. package/dist/native/section-scroll.d.ts.map +1 -1
  22. package/dist/native/section-scroll.js +19 -6
  23. package/dist/native/section-scroll.js.map +1 -1
  24. package/dist/native/visual-effects.d.ts.map +1 -1
  25. package/dist/native/visual-effects.js +5 -0
  26. package/dist/native/visual-effects.js.map +1 -1
  27. package/dist/vue/card-input.d.ts +4 -0
  28. package/dist/vue/card-input.d.ts.map +1 -0
  29. package/dist/vue/card-input.js +37 -0
  30. package/dist/vue/card-input.js.map +1 -0
  31. package/dist/vue/components/ChoiceControl.d.ts +1 -1
  32. package/dist/vue/components/DateCalendar.d.ts +1 -1
  33. package/dist/vue/components/MButton.d.ts +6 -6
  34. package/dist/vue/components/MCard.d.ts.map +1 -1
  35. package/dist/vue/components/MCard.js +29 -8
  36. package/dist/vue/components/MCard.js.map +1 -1
  37. package/dist/vue/components/MChip.d.ts +1 -1
  38. package/dist/vue/components/MDatePicker.d.ts +96 -96
  39. package/dist/vue/components/MDatePicker.d.ts.map +1 -1
  40. package/dist/vue/components/MEmptyState.d.ts +1 -1
  41. package/dist/vue/components/MInput.d.ts +4 -4
  42. package/dist/vue/components/MPopover.d.ts +1 -1
  43. package/dist/vue/components/MProgress.d.ts +1 -1
  44. package/dist/vue/components/MRangeSlider.d.ts +2 -2
  45. package/dist/vue/components/MResizablePanels.d.ts +1 -1
  46. package/dist/vue/components/MReveal.d.ts +8 -8
  47. package/dist/vue/components/MSheet.d.ts +4 -4
  48. package/dist/vue/components/MSlider.d.ts +1 -1
  49. package/dist/vue/components/MStack.d.ts +8 -8
  50. package/dist/vue/components/MTimePicker.d.ts +40 -40
  51. package/dist/vue/components/MTimePicker.d.ts.map +1 -1
  52. package/dist/vue/components/MTooltip.d.ts +1 -1
  53. package/dist/vue/components/MVirtualList.d.ts.map +1 -1
  54. package/dist/vue/components/MVirtualList.js +88 -67
  55. package/dist/vue/components/MVirtualList.js.map +1 -1
  56. package/dist/vue/components/advanced.d.ts +34 -34
  57. package/dist/vue/components/configurator.d.ts +33 -33
  58. package/dist/vue/components/creative.d.ts +20 -20
  59. package/dist/vue/components/dashboard.d.ts +12 -12
  60. package/dist/vue/components/dashboard.d.ts.map +1 -1
  61. package/dist/vue/components/dashboard.js +167 -66
  62. package/dist/vue/components/dashboard.js.map +1 -1
  63. package/dist/vue/components/discovery.d.ts +10 -10
  64. package/dist/vue/components/interactive.d.ts +6 -6
  65. package/dist/vue/components/layout.d.ts +27 -16
  66. package/dist/vue/components/layout.d.ts.map +1 -1
  67. package/dist/vue/components/layout.js +3 -0
  68. package/dist/vue/components/layout.js.map +1 -1
  69. package/dist/vue/components/navigation.d.ts +4 -4
  70. package/dist/vue/components/screen-components.d.ts +23 -23
  71. package/dist/vue/components/wayfinding.d.ts +11 -11
  72. package/dist/vue/components/workflows.d.ts +5 -5
  73. package/dist/vue/perspective.d.ts +4 -0
  74. package/dist/vue/perspective.d.ts.map +1 -0
  75. package/dist/vue/perspective.js +3 -0
  76. package/dist/vue/perspective.js.map +1 -0
  77. package/dist/vue/use-motion-surface.d.ts +1 -1
  78. package/dist/vue/use-motion-surface.d.ts.map +1 -1
  79. package/dist/vue/use-motion-surface.js +40 -8
  80. package/dist/vue/use-motion-surface.js.map +1 -1
  81. package/package.json +3 -3
  82. package/src/native/flex-layout.ios.ts +4 -0
  83. package/src/native/motion-region.ts +1 -0
  84. package/src/native/motion-surface.ts +58 -13
  85. package/src/native/moved-shadow.ts +22 -0
  86. package/src/native/scroll-motion.ts +60 -19
  87. package/src/native/section-scroll.ts +16 -6
  88. package/src/native/visual-effects.ts +5 -0
  89. package/src/vue/card-input.ts +44 -0
  90. package/src/vue/components/MCard.ts +35 -9
  91. package/src/vue/components/MVirtualList.ts +104 -78
  92. package/src/vue/components/dashboard.ts +173 -68
  93. package/src/vue/components/layout.ts +3 -0
  94. package/src/vue/perspective.ts +4 -0
  95. package/src/vue/use-motion-surface.ts +39 -8
@@ -1,8 +1,11 @@
1
- import { onBeforeUnmount, watch } from 'nativescript-vue';
1
+ import { Utils, isAndroid } from '@nativescript/core';
2
+ import { inject, onBeforeUnmount, watch } from 'nativescript-vue';
2
3
  import { animate, set, onReducedMotion } from '@rafaelaugusto/jolt';
3
- import { bindMotionSurface, } from '@getcortexlabs/mavis-core/experimental';
4
+ import { bindMotionSurface, motionChannels, motionKeyframes, } from '@getcortexlabs/mavis-core/experimental';
4
5
  import { nativeContinuousSurface } from '../native/motion-surface.js';
5
6
  import { nativeMotionOwner } from '../native/motion-owner.js';
7
+ import { perspectiveKey } from './perspective.js';
8
+ import { takeShadow } from '../native/moved-shadow.js';
6
9
  export function useMotionSurface(surface, enabled = () => true, plainText = () => false, afterLayout = false) {
7
10
  let view;
8
11
  let unbind;
@@ -11,6 +14,21 @@ export function useMotionSurface(surface, enabled = () => true, plainText = () =
11
14
  const active = new Map();
12
15
  let layoutView;
13
16
  let layoutQueued = false;
17
+ const perspective = inject(perspectiveKey, undefined);
18
+ let flat;
19
+ const project = () => {
20
+ const depth = perspective?.();
21
+ if (flat && (depth === undefined || flat.view !== view)) {
22
+ flat.view.perspective = flat.perspective;
23
+ flat = undefined;
24
+ }
25
+ if (!view || depth === undefined || !unbind)
26
+ return;
27
+ flat ??= { view, perspective: view.perspective };
28
+ // Core multiplies by the density for Android's camera distance, whose unit is not the
29
+ // CSS distance. This is the factor that draws the same projection as iOS and the Web.
30
+ view.perspective = isAndroid ? depth * Utils.layout.getDisplayDensity() * Math.sqrt(5) : depth;
31
+ };
14
32
  const clearLayout = () => {
15
33
  layoutView?.off('layoutChanged', laidOut);
16
34
  layoutView = undefined;
@@ -24,6 +42,7 @@ export function useMotionSurface(surface, enabled = () => true, plainText = () =
24
42
  for (const handle of active.keys())
25
43
  handle.stop();
26
44
  active.clear();
45
+ project();
27
46
  };
28
47
  const bind = () => {
29
48
  release();
@@ -47,30 +66,41 @@ export function useMotionSurface(surface, enabled = () => true, plainText = () =
47
66
  unbind = bindMotionSurface(reference, nativeMotionOwner({
48
67
  ...continuous.adapter,
49
68
  animate(values, options) {
50
- continuous?.interrupt(Object.keys(values));
51
- const handle = animate(target, values, options);
69
+ continuous?.interrupt(motionChannels(values));
70
+ const handle = animate(target, motionKeyframes(values), options);
71
+ takeShadow(target, values);
52
72
  active.set(handle, values);
53
73
  void handle.finished.then(() => active.delete(handle));
54
74
  return handle;
55
75
  },
56
76
  set: (values) => {
57
77
  continuous?.interrupt(Object.keys(values));
58
- return animate(target, values, { duration: 0 });
78
+ const handle = animate(target, values, { duration: 0 });
79
+ takeShadow(target, values);
80
+ return handle;
59
81
  },
60
82
  }, target));
83
+ project();
61
84
  offPreference = onReducedMotion((reduced) => {
62
85
  if (!reduced)
63
86
  return;
64
- // Set only spatial channels: opacity can keep its existing timeline.
87
+ // Set only spatial channels: opacity and shadow paint can keep their timelines.
65
88
  const values = {};
66
- for (const frames of active.values())
89
+ for (const frames of active.values()) {
90
+ if (frames.path)
91
+ Object.assign(values, {
92
+ x: frames.path.end.x,
93
+ y: frames.path.end.y,
94
+ ...(frames.orient ? { rotate: frames.path.end.rotate } : {}),
95
+ });
67
96
  for (const [property, value] of Object.entries(frames)) {
68
- if (property === 'opacity')
97
+ if (property === 'opacity' || property.startsWith('shadow'))
69
98
  continue;
70
99
  const final = Array.isArray(value) ? value.at(-1) : value;
71
100
  if (typeof final === 'number')
72
101
  values[property] = final;
73
102
  }
103
+ }
74
104
  if (Object.keys(values).length)
75
105
  set(target, values);
76
106
  });
@@ -91,6 +121,8 @@ export function useMotionSurface(surface, enabled = () => true, plainText = () =
91
121
  view = undefined;
92
122
  };
93
123
  watch(surface, bind, { flush: 'post' });
124
+ if (perspective)
125
+ watch(perspective, project, { flush: 'post' });
94
126
  watch(enabled, () => continuous?.refresh(), { flush: 'sync' });
95
127
  onBeforeUnmount(unloaded);
96
128
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"use-motion-surface.js","sourceRoot":"","sources":["../../src/vue/use-motion-surface.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACnE,OAAO,EACL,iBAAiB,GAGlB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAE7D,MAAM,UAAU,gBAAgB,CAC9B,OAAwC,EACxC,UAAyB,GAAG,EAAE,CAAC,IAAI,EACnC,YAA2B,GAAG,EAAE,CAAC,KAAK,EACtC,WAAW,GAAG,KAAK;IAEnB,IAAI,IAAsB,CAAA;IAC1B,IAAI,MAAgC,CAAA;IACpC,IAAI,aAAuC,CAAA;IAC3C,IAAI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D,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,IAAI,YAAY;YAAE,OAAM;QACxB,YAAY,GAAG,IAAI,CAAA;QACnB,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;YAC/B,YAAY,GAAG,KAAK,CAAA;YACpB,IAAI,IAAI;gBAAE,IAAI,EAAE,CAAA;QAClB,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;IACD,MAAM,QAAQ,GAAG,GAAG,EAAE;QACpB,WAAW,EAAE,CAAA;QACb,OAAO,EAAE,CAAA;QACT,IAAI,GAAG,SAAS,CAAA;IAClB,CAAC,CAAA;IACD,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;IACvC,IAAI,WAAW;QAAE,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;IAC/D,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;IAC9D,eAAe,CAAC,QAAQ,CAAC,CAAA;IACzB,OAAO;QACL,gBAAgB,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE,gBAAgB,EAAE,IAAI,IAAI;QAC9D,QAAQ,CAAC,KAAgB;YACvB,IAAI,GAAG,KAAK,CAAC,MAAc,CAAA;YAC3B,IAAI,EAAE,CAAA;QACR,CAAC;QACD,UAAU,EAAE,QAAQ;KACrB,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getcortexlabs/mavis",
3
- "version": "0.1.0-rc.12.2",
3
+ "version": "0.1.0-rc.14",
4
4
  "description": "Mavis UI foundations for NativeScript, with a Vue integration.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@nativescript/core": "^9.1.3",
46
- "@rafaelaugusto/jolt": "^0.1.0-rc.12.1",
46
+ "@rafaelaugusto/jolt": "^0.1.0-rc.15",
47
47
  "nativescript-vue": "^3.1.3"
48
48
  },
49
49
  "peerDependenciesMeta": {
@@ -52,7 +52,7 @@
52
52
  }
53
53
  },
54
54
  "dependencies": {
55
- "@getcortexlabs/mavis-core": "0.1.0-rc.12.2"
55
+ "@getcortexlabs/mavis-core": "0.1.0-rc.14"
56
56
  },
57
57
  "nativescript": {
58
58
  "platforms": {
@@ -222,5 +222,9 @@ export class MavisFlexLayout extends FlexboxLayout {
222
222
  ? layout.makeMeasureSpec(child.effectiveHeight, layout.EXACTLY)
223
223
  : layout.makeMeasureSpec(available, mode),
224
224
  )
225
+ // Core applies min/max constraints before our width-aware remeasurement. Its
226
+ // Flexbox onMeasure does not enforce its own minimum, so measuring a nested
227
+ // row again can collapse a 44-point link to its label's intrinsic height.
228
+ base._checkSizeConstraints.call(this, child)
225
229
  }
226
230
  }
@@ -204,6 +204,7 @@ export function attachNativeMotionRegion(reference: MotionRegion, target: View)
204
204
  : ([resolveChild(step[0]), step[1], step[2]] as const),
205
205
  )
206
206
  const adapter: MotionRegionAdapter = {
207
+ // Jolt captures before native unload, then waits for layout; rebuilt RC.15 classes own exits.
207
208
  animateLayout: (change, { transition, ...options }) =>
208
209
  animateLayout(target, change, { ...transition, ...options }),
209
210
  ...nativePlatformMotion(target, resolveChild, scope),
@@ -14,7 +14,9 @@ import {
14
14
  set,
15
15
  stop,
16
16
  drag,
17
+ pointerFollow,
17
18
  type DerivedValue,
19
+ type PointerOptions,
18
20
  } from '@rafaelaugusto/jolt'
19
21
  import type {
20
22
  MotionSurfaceAdapter,
@@ -46,6 +48,8 @@ export function nativeContinuousSurface(
46
48
  | 'drag'
47
49
  | 'map'
48
50
  | 'mapColor'
51
+ | 'scalar'
52
+ | 'readVelocity'
49
53
  | 'refresh'
50
54
  | 'scrollLinked'
51
55
  | 'scrollSection'
@@ -96,18 +100,42 @@ export function nativeContinuousSurface(
96
100
  },
97
101
  pointerFollow(region, options) {
98
102
  assertNativeRegion(region, target)
99
- const x = adapter.motionValue!(options.rest?.x ?? 0)
100
- const y = adapter.motionValue!(options.rest?.y ?? 0)
103
+ // Jolt owns the hover listener, its geometry, suspension and the views' load state.
104
+ // Ordinary touch is not hover, so scrolling, taps and focus stay with the app.
105
+ const pointer = pointerFollow(nativeRegionTarget(region), {
106
+ ...options,
107
+ disabled: options.disabled || !enabled(),
108
+ } as PointerOptions)
109
+ let disabled = options.disabled ?? false
110
+ const refresh = () => pointer.update({ disabled: disabled || !enabled() })
111
+ refreshes.add(refresh)
112
+ // The pointer owns its values; wrappers are borrowed by Mavis bindings.
113
+ const wrap = (source: DerivedValue) => {
114
+ const value = { get: () => source.get(), dispose() {} }
115
+ sources.set(value, source)
116
+ return value
117
+ }
101
118
  return {
102
- x,
103
- y,
104
- execution: 'static',
105
- active: false,
106
- update() {},
107
- refresh() {},
119
+ x: wrap(pointer.x),
120
+ y: wrap(pointer.y),
121
+ presence: wrap(pointer.presence),
122
+ get execution() {
123
+ return pointer.available ? ('hover' as const) : ('static' as const)
124
+ },
125
+ get available() {
126
+ return pointer.available
127
+ },
128
+ get active() {
129
+ return pointer.active
130
+ },
131
+ update(state) {
132
+ disabled = state.disabled
133
+ refresh()
134
+ },
135
+ refresh: () => pointer.refresh(),
108
136
  dispose() {
109
- x.dispose()
110
- y.dispose()
137
+ refreshes.delete(refresh)
138
+ pointer.dispose()
111
139
  },
112
140
  }
113
141
  },
@@ -151,10 +179,27 @@ export function nativeContinuousSurface(
151
179
  refresh: () => target.requestLayout(),
152
180
  map(source, input, output, options) {
153
181
  const mapped = sources.get(source)!.to(input, output, options)
154
- const value = { get: () => mapped.get(), dispose() {} }
182
+ const value = { get: () => mapped.get(), dispose: () => mapped.dispose() }
155
183
  sources.set(value, mapped)
156
184
  return value
157
185
  },
186
+ scalar(source, operation, operand, maximum) {
187
+ const input = sources.get(source)!
188
+ let result: DerivedValue
189
+ if (operation === 'clamp') result = input.clamp(operand as number, maximum!)
190
+ else if (
191
+ operation === 'abs' ||
192
+ operation === 'sin' ||
193
+ operation === 'cos' ||
194
+ operation === 'velocity'
195
+ )
196
+ result = input[operation]()
197
+ else result = input[operation](typeof operand === 'number' ? operand : sources.get(operand!)!)
198
+ const value = { get: () => result.get(), dispose: () => result.dispose() }
199
+ sources.set(value, result)
200
+ return value
201
+ },
202
+ readVelocity: (source) => sources.get(source)!.getVelocity(),
158
203
  mapColor(source, input, output) {
159
204
  const mapped = sources.get(source)!.to(input, output)
160
205
  const value = { get: () => mapped.get().hex, dispose() {} }
@@ -173,7 +218,7 @@ export function nativeContinuousSurface(
173
218
  },
174
219
  playbackProgress(handle) {
175
220
  const progress = playbackProgress(handle as Parameters<typeof playbackProgress>[0])
176
- const value = { get: () => progress.get(), dispose() {} }
221
+ const value = { get: () => progress.get(), dispose: () => progress.dispose() }
177
222
  sources.set(value, progress)
178
223
  return value
179
224
  },
@@ -186,7 +231,7 @@ export function nativeContinuousSurface(
186
231
  const value: MotionValueAdapter = {
187
232
  get: () => source.get(),
188
233
  set: (value) => set(source, value),
189
- dispose: () => stop(source),
234
+ dispose: () => source.dispose(),
190
235
  }
191
236
  sources.set(value, source)
192
237
  return value
@@ -0,0 +1,22 @@
1
+ import type { View } from '@nativescript/core'
2
+
3
+ // The shadow the component declared when application motion took it, and the last one rendered.
4
+ const moved = new WeakMap<View, unknown>()
5
+ const declared = new WeakMap<View, unknown>()
6
+
7
+ export function takeShadow(view: View, values: object) {
8
+ if (!moved.has(view) && Object.keys(values).some((key) => key.startsWith('shadow')))
9
+ moved.set(view, declared.get(view))
10
+ }
11
+ /** A rerender keeps the shadow the application animated until the component declares another. */
12
+ export function keepShadow(view: View | undefined, shadow: string | undefined): unknown {
13
+ if (!view) return shadow
14
+ let kept: unknown = shadow
15
+ if (moved.has(view)) {
16
+ const current = (view as View & { boxShadow?: unknown }).boxShadow
17
+ if (moved.get(view) !== shadow) moved.delete(view)
18
+ else if (current) kept = current
19
+ }
20
+ declared.set(view, shadow)
21
+ return kept
22
+ }
@@ -1,5 +1,11 @@
1
1
  import type { EventData, ScrollView, View } from '@nativescript/core'
2
- import { bind, scrollValue, onReducedMotion, reducedMotion } from '@rafaelaugusto/jolt'
2
+ import {
3
+ bind,
4
+ scrollValue,
5
+ onReducedMotion,
6
+ reducedMotion,
7
+ type DerivedValue,
8
+ } from '@rafaelaugusto/jolt'
3
9
  import {
4
10
  bindMotionScrollSource,
5
11
  type MotionScrollAdapter,
@@ -33,7 +39,9 @@ export function nativeScrollMotion(
33
39
  ) {
34
40
  const source = sources.get(adapter)
35
41
  if (!source) throw new TypeError('Use a scrolling MScreen in this renderer.')
36
- const offset = scrollValue(source)
42
+ const offset = scrollValue(source, {
43
+ execution: options.execution === 'scheduler' ? 'javascript' : 'auto',
44
+ })
37
45
  const active = new Map<string, readonly number[]>()
38
46
  for (const [key, values] of Object.entries(frames)) {
39
47
  if (key === 'scale') {
@@ -42,21 +50,45 @@ export function nativeScrollMotion(
42
50
  } else active.set(key, values)
43
51
  }
44
52
  const bindings = new Map<string, () => void>()
53
+ let bounded: DerivedValue | undefined
45
54
  let disposed = false
46
55
  let maximum = -1
47
56
  let content: View | undefined
57
+ const clearBindings = () => {
58
+ for (const release of bindings.values()) release()
59
+ bindings.clear()
60
+ bounded?.dispose()
61
+ bounded = undefined
62
+ }
48
63
  const apply = () => {
49
64
  if (disposed) return
50
- const bounded = offset.to([0, Math.max(1, maximum)], [0, Math.max(0, maximum)])
51
- for (const [key, output] of active) {
52
- bindings.get(key)?.()
53
- const input = output.map(
54
- (_, index) =>
55
- options.range[0] + (index * (options.range[1] - options.range[0])) / (output.length - 1),
56
- )
57
- const values =
58
- reducedMotion() && key !== 'opacity' ? output.map(() => output.at(-1)!) : output
59
- bindings.set(key, bind(target, { [key]: bounded.to(input, values) }))
65
+ clearBindings()
66
+ bounded = offset.to([0, Math.max(1, maximum)], [0, Math.max(0, maximum)])
67
+ try {
68
+ for (const [key, output] of active) {
69
+ const input = output.map(
70
+ (_, index) =>
71
+ options.range[0] +
72
+ (index * (options.range[1] - options.range[0])) / (output.length - 1),
73
+ )
74
+ const values =
75
+ reducedMotion() && key !== 'opacity' ? output.map(() => output.at(-1)!) : output
76
+ const mapped = bounded.to(input, values)
77
+ let release: () => void
78
+ try {
79
+ release = bind(target, { [key]: mapped })
80
+ } catch (error) {
81
+ mapped.dispose()
82
+ throw error
83
+ }
84
+ bindings.set(key, () => {
85
+ release()
86
+ mapped.dispose()
87
+ })
88
+ }
89
+ } catch (error) {
90
+ clearBindings()
91
+ throw error
60
92
  }
61
93
  }
62
94
  const refresh = () => {
@@ -71,16 +103,18 @@ export function nativeScrollMotion(
71
103
  }
72
104
  if (changed) apply()
73
105
  // Re-read the actual bounded offset without a Vue update or an additional clock.
74
- offset.ref(null)
75
- offset.ref(source)
106
+ offset.refresh()
76
107
  }
77
108
  const layout = (_event: EventData) => refresh()
78
109
  source.on('layoutChanged', layout)
79
110
  const offReduced = onReducedMotion(apply)
80
- refresh()
81
- return {
111
+ const control = {
82
112
  get execution() {
83
- return disposed || !active.size ? ('released' as const) : ('native' as const)
113
+ return disposed || !active.size
114
+ ? ('released' as const)
115
+ : offset.execution === 'native'
116
+ ? ('native' as const)
117
+ : ('scheduler' as const)
84
118
  },
85
119
  refresh,
86
120
  interrupt(properties: readonly string[]) {
@@ -90,6 +124,7 @@ export function nativeScrollMotion(
90
124
  bindings.get(key)?.()
91
125
  bindings.delete(key)
92
126
  }
127
+ if (!active.size) control.dispose()
93
128
  },
94
129
  dispose() {
95
130
  if (disposed) return
@@ -97,10 +132,16 @@ export function nativeScrollMotion(
97
132
  source.off('layoutChanged', layout)
98
133
  content?.off('layoutChanged', layout)
99
134
  offReduced()
100
- for (const release of bindings.values()) release()
101
- bindings.clear()
135
+ clearBindings()
102
136
  active.clear()
103
137
  offset.dispose()
104
138
  },
105
139
  }
140
+ try {
141
+ refresh()
142
+ } catch (error) {
143
+ control.dispose()
144
+ throw error
145
+ }
146
+ return control
106
147
  }
@@ -21,6 +21,12 @@ export function nativeSectionScroll(
21
21
  let link: ReturnType<typeof nativeScrollMotion> | undefined
22
22
  let previous = '',
23
23
  disposed = false
24
+ const active = new Map(Object.entries(frames))
25
+ if (active.has('scale')) {
26
+ if (!active.has('scaleX')) active.set('scaleX', active.get('scale')!)
27
+ if (!active.has('scaleY')) active.set('scaleY', active.get('scale')!)
28
+ active.delete('scale')
29
+ }
24
30
  const observed = new Set<View>()
25
31
  const refresh = () => {
26
32
  if (disposed) return
@@ -40,14 +46,14 @@ export function nativeSectionScroll(
40
46
  }
41
47
  const values = measured.settled
42
48
  ? Object.fromEntries(
43
- Object.entries(frames).map(([property, values]) => [
44
- property,
45
- [values.at(-1)!, values.at(-1)!],
46
- ]),
49
+ [...active].map(([property, values]) => [property, [values.at(-1)!, values.at(-1)!]]),
47
50
  )
48
- : frames
51
+ : Object.fromEntries(active)
49
52
  link?.dispose()
50
- link = nativeScrollMotion(adapter, target, values, { range: measured.range })
53
+ link = nativeScrollMotion(adapter, target, values, {
54
+ range: measured.range,
55
+ execution: options.execution,
56
+ })
51
57
  previous = key
52
58
  }
53
59
  for (let view: View | undefined = section; view; view = view.parent as View | undefined) {
@@ -74,7 +80,11 @@ export function nativeSectionScroll(
74
80
  },
75
81
  refresh,
76
82
  interrupt(properties: readonly string[]) {
83
+ for (const property of properties)
84
+ for (const key of property === 'scale' ? ['scaleX', 'scaleY'] : [property])
85
+ active.delete(key)
77
86
  link?.interrupt(properties)
87
+ if (!active.size) dispose()
78
88
  },
79
89
  dispose,
80
90
  }
@@ -40,6 +40,11 @@ export function nativeVisualEffects(
40
40
  return isIOS && target instanceof Image && Boolean(target.ios?.image?.symbolImage)
41
41
  if (effect === 'image') return target instanceof Image
42
42
  if (effect === 'liquid') return isIOS && target instanceof Image
43
+ if (effect === 'shadow') {
44
+ // Android draws CSS shadows from a cached shape and elevation is a different model.
45
+ const shadows = (target as View & { boxShadow?: unknown }).boxShadow
46
+ return isIOS && Array.isArray(shadows) && shadows.length === 1 && !shadows[0]?.inset
47
+ }
43
48
  return (
44
49
  ['gradient', 'particles', 'confetti', 'blur', 'shape', 'keyboard'].includes(effect) || isIOS
45
50
  )
@@ -0,0 +1,44 @@
1
+ import type { TapGestureEventData, View } from '@nativescript/core'
2
+
3
+ /** A child's native control owns its hit; blank space still belongs to the card. */
4
+ export function ownsCardTap(event?: Partial<TapGestureEventData>): boolean {
5
+ const card = (event?.object ?? event?.view) as View | undefined
6
+ if (!card || !event?.getX || !event.getY) return true
7
+ const x = event.getX(),
8
+ y = event.getY()
9
+ if (!Number.isFinite(x) || !Number.isFinite(y)) return true
10
+ const containsControl = (view: View): boolean => {
11
+ if (view.visibility !== undefined && view.visibility !== 'visible') return false
12
+ if (
13
+ /^(MavisButton|Button|TextField|TextView|SearchBar|Switch|Slider|DatePicker|TimePicker|ListPicker|SegmentedBar|WebView)$/.test(
14
+ view.typeName,
15
+ ) ||
16
+ ['button', 'link', 'checkbox', 'radio', 'switch', 'slider', 'combobox', 'tab'].includes(
17
+ view.accessibilityRole,
18
+ )
19
+ ) {
20
+ const origin = view.getLocationRelativeTo(card)
21
+ const size = view.getActualSize()
22
+ if (
23
+ origin &&
24
+ x >= origin.x &&
25
+ y >= origin.y &&
26
+ x <= origin.x + size.width &&
27
+ y <= origin.y + size.height
28
+ )
29
+ return true
30
+ }
31
+ let found = false
32
+ view.eachChildView?.((child) => {
33
+ found = containsControl(child)
34
+ return !found
35
+ })
36
+ return found
37
+ }
38
+ let found = false
39
+ card.eachChildView?.((child) => {
40
+ found = containsControl(child)
41
+ return !found
42
+ })
43
+ return !found
44
+ }
@@ -1,7 +1,8 @@
1
1
  import { nativeDestination, navigateNative } from '../navigation.js'
2
+ import { ownsCardTap } from '../card-input.js'
2
3
  import { resolveSpace, resolveRadius, shadowStyle } from '@getcortexlabs/mavis-core'
3
4
  import { ActionChildren } from '../accessibility.js'
4
- import { defineComponent, h, mergeProps } from 'nativescript-vue'
5
+ import { defineComponent, getCurrentInstance, h, mergeProps } from 'nativescript-vue'
5
6
  import {
6
7
  useButtonAction,
7
8
  cardProps,
@@ -12,6 +13,8 @@ import {
12
13
  import { MColumn } from './layout.js'
13
14
  import { usePressFeedback } from '../use-press.js'
14
15
  import { useMotionSurface } from '../use-motion-surface.js'
16
+ import { keepShadow } from '../../native/moved-shadow.js'
17
+ import type { EventData, TapGestureEventData, View } from '@nativescript/core'
15
18
 
16
19
  export const MCard = defineComponent({
17
20
  name: 'MCard',
@@ -22,12 +25,15 @@ export const MCard = defineComponent({
22
25
  useButtonAction(() => props.interactive || props.href !== undefined)
23
26
  const { theme } = useMavisTheme()
24
27
  const navigation = useNavigationOptions(props)
28
+ const instance = getCurrentInstance()
25
29
  const enabled = () => (props.interactive || props.href !== undefined) && !props.disabled
26
30
  const lifecycle = usePressFeedback(enabled, theme)
27
31
  const { allowsActivation, ...surface } = useMotionSurface(
28
32
  () => props.motionSurface,
29
33
  () => !props.disabled,
30
34
  )
35
+ let view: View | undefined
36
+ let shadow: string | undefined
31
37
  return () => {
32
38
  const {
33
39
  interactive: action,
@@ -41,20 +47,28 @@ export const MCard = defineComponent({
41
47
  ...layout
42
48
  } = props
43
49
  const interactive = action || href !== undefined
50
+ // A labelled card with no action wired is read as one element, like a labelled action.
51
+ // An explicit accessible attribute decides otherwise.
52
+ const summary =
53
+ !interactive &&
54
+ (attrs.accessible === undefined
55
+ ? Boolean(props.accessibilityLabel) && !instance?.vnode.props?.onClick
56
+ : attrs.accessible !== false && attrs.accessible !== 'false')
44
57
  if (href !== undefined) nativeDestination(navigation())
45
58
  const tokens = theme.value.components.card
46
59
  layout.padding ??= tokens.padding
47
60
  layout.radius ??= tokens.radius
61
+ shadow =
62
+ (elevation ?? tokens.elevation) === 'none'
63
+ ? undefined
64
+ : shadowStyle(theme.value.elevation[elevation ?? tokens.elevation], 'native')
48
65
  return h(
49
66
  MColumn,
50
67
  mergeProps(
51
68
  layout,
52
69
  {
53
70
  style: {
54
- boxShadow:
55
- (elevation ?? tokens.elevation) === 'none'
56
- ? undefined
57
- : shadowStyle(theme.value.elevation[elevation ?? tokens.elevation], 'native'),
71
+ boxShadow: keepShadow(view, shadow),
58
72
  backgroundColor: props.backgroundColor ?? theme.value.colors.surface,
59
73
  borderColor: theme.value.colors.border,
60
74
  borderWidth: 1,
@@ -65,12 +79,20 @@ export const MCard = defineComponent({
65
79
  lifecycle,
66
80
  surface,
67
81
  {
68
- accessible: interactive,
82
+ onLoaded: (event: EventData) => {
83
+ view = event.object as View
84
+ // The first render ran before the view existed: record what it declared.
85
+ keepShadow(view, shadow)
86
+ },
87
+ onUnloaded: () => {
88
+ view = undefined
89
+ },
90
+ accessible: interactive || summary,
69
91
  accessibilityRole: href !== undefined ? 'link' : interactive ? 'button' : '',
70
92
  accessibilityState: interactive && disabled ? 'disabled' : '',
71
93
  onTap: interactive
72
- ? () => {
73
- if (enabled() && allowsActivation()) {
94
+ ? (event?: TapGestureEventData) => {
95
+ if (enabled() && allowsActivation() && ownsCardTap(event)) {
74
96
  emit('click')
75
97
  if (href !== undefined)
76
98
  void navigateNative(navigation()).catch((error) => emit('error', error))
@@ -81,7 +103,11 @@ export const MCard = defineComponent({
81
103
  ),
82
104
  {
83
105
  default: () =>
84
- h(ActionChildren, { hidden: interactive && Boolean(props.accessibilityLabel) }, slots),
106
+ h(
107
+ ActionChildren,
108
+ { hidden: (interactive || summary) && Boolean(props.accessibilityLabel) },
109
+ slots,
110
+ ),
85
111
  },
86
112
  )
87
113
  }