@getcortexlabs/mavis 0.1.0-rc.13 → 0.1.0-rc.15

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 (190) hide show
  1. package/README.md +7 -5
  2. package/dist/components/bindings.d.ts +14 -0
  3. package/dist/components/bindings.d.ts.map +1 -0
  4. package/dist/components/bindings.js +21 -0
  5. package/dist/components/bindings.js.map +1 -0
  6. package/dist/components/contracts.d.ts +28 -0
  7. package/dist/components/contracts.d.ts.map +1 -0
  8. package/dist/components/contracts.js +27 -0
  9. package/dist/components/contracts.js.map +1 -0
  10. package/dist/components/controller.d.ts +56 -0
  11. package/dist/components/controller.d.ts.map +1 -0
  12. package/dist/components/controller.js +508 -0
  13. package/dist/components/controller.js.map +1 -0
  14. package/dist/components/index.d.ts +53 -0
  15. package/dist/components/index.d.ts.map +1 -0
  16. package/dist/components/index.js +95 -0
  17. package/dist/components/index.js.map +1 -0
  18. package/dist/components/style.d.ts +52 -0
  19. package/dist/components/style.d.ts.map +1 -0
  20. package/dist/components/style.js +68 -0
  21. package/dist/components/style.js.map +1 -0
  22. package/dist/components/theme.d.ts +12 -0
  23. package/dist/components/theme.d.ts.map +1 -0
  24. package/dist/components/theme.js +29 -0
  25. package/dist/components/theme.js.map +1 -0
  26. package/dist/native/box.ios.d.ts +1 -0
  27. package/dist/native/box.ios.d.ts.map +1 -1
  28. package/dist/native/box.ios.js +21 -1
  29. package/dist/native/box.ios.js.map +1 -1
  30. package/dist/native/flex-layout.ios.d.ts.map +1 -1
  31. package/dist/native/flex-layout.ios.js +4 -0
  32. package/dist/native/flex-layout.ios.js.map +1 -1
  33. package/dist/native/motion-binding.d.ts +11 -0
  34. package/dist/native/motion-binding.d.ts.map +1 -0
  35. package/dist/native/motion-binding.js +132 -0
  36. package/dist/native/motion-binding.js.map +1 -0
  37. package/dist/native/motion-region.d.ts.map +1 -1
  38. package/dist/native/motion-region.js +1 -0
  39. package/dist/native/motion-region.js.map +1 -1
  40. package/dist/native/motion-surface.d.ts +1 -1
  41. package/dist/native/motion-surface.d.ts.map +1 -1
  42. package/dist/native/motion-surface.js +40 -8
  43. package/dist/native/motion-surface.js.map +1 -1
  44. package/dist/native/navigation.d.ts +4 -0
  45. package/dist/native/navigation.d.ts.map +1 -0
  46. package/dist/native/navigation.js +16 -0
  47. package/dist/native/navigation.js.map +1 -0
  48. package/dist/native/pointer-availability.d.ts +7 -0
  49. package/dist/native/pointer-availability.d.ts.map +1 -0
  50. package/dist/native/pointer-availability.js +43 -0
  51. package/dist/native/pointer-availability.js.map +1 -0
  52. package/dist/native/scroll-motion.d.ts +1 -1
  53. package/dist/native/scroll-motion.d.ts.map +1 -1
  54. package/dist/native/scroll-motion.js +55 -16
  55. package/dist/native/scroll-motion.js.map +1 -1
  56. package/dist/native/section-scroll.d.ts +1 -1
  57. package/dist/native/section-scroll.d.ts.map +1 -1
  58. package/dist/native/section-scroll.js +19 -6
  59. package/dist/native/section-scroll.js.map +1 -1
  60. package/dist/vue/card-input.d.ts +4 -0
  61. package/dist/vue/card-input.d.ts.map +1 -0
  62. package/dist/vue/card-input.js +37 -0
  63. package/dist/vue/card-input.js.map +1 -0
  64. package/dist/vue/components/ChoiceControl.d.ts +3 -3
  65. package/dist/vue/components/LoadingDecoration.d.ts +5 -5
  66. package/dist/vue/components/MAccordion.d.ts +3 -3
  67. package/dist/vue/components/MAlert.d.ts +4 -4
  68. package/dist/vue/components/MAvatar.d.ts +4 -4
  69. package/dist/vue/components/MBadge.d.ts +3 -3
  70. package/dist/vue/components/MButton.d.ts +20 -20
  71. package/dist/vue/components/MCard.d.ts +11 -11
  72. package/dist/vue/components/MCard.d.ts.map +1 -1
  73. package/dist/vue/components/MCard.js +3 -2
  74. package/dist/vue/components/MCard.js.map +1 -1
  75. package/dist/vue/components/MCheckbox.d.ts +3 -3
  76. package/dist/vue/components/MChip.d.ts +4 -4
  77. package/dist/vue/components/MCombobox.d.ts +5 -5
  78. package/dist/vue/components/MDatePicker.d.ts +96 -96
  79. package/dist/vue/components/MDatePicker.d.ts.map +1 -1
  80. package/dist/vue/components/MDialog.d.ts +3 -3
  81. package/dist/vue/components/MEmptyState.d.ts +3 -3
  82. package/dist/vue/components/MGrid.d.ts +7 -7
  83. package/dist/vue/components/MGrid.d.ts.map +1 -1
  84. package/dist/vue/components/MGrid.js +5 -1
  85. package/dist/vue/components/MGrid.js.map +1 -1
  86. package/dist/vue/components/MIcon.d.ts +2 -2
  87. package/dist/vue/components/MImage.d.ts +7 -7
  88. package/dist/vue/components/MImageCompare.d.ts +1 -1
  89. package/dist/vue/components/MInput.d.ts +22 -22
  90. package/dist/vue/components/MLink.d.ts +5 -5
  91. package/dist/vue/components/MListItem.d.ts +5 -5
  92. package/dist/vue/components/MPinInput.d.ts +1 -1
  93. package/dist/vue/components/MPopover.d.ts +3 -3
  94. package/dist/vue/components/MProgress.d.ts +5 -5
  95. package/dist/vue/components/MRadioGroup.d.ts +3 -3
  96. package/dist/vue/components/MRangeSlider.d.ts +1 -1
  97. package/dist/vue/components/MResizablePanels.d.ts +3 -3
  98. package/dist/vue/components/MReveal.d.ts +17 -17
  99. package/dist/vue/components/MScreen.d.ts +3 -3
  100. package/dist/vue/components/MScreen.d.ts.map +1 -1
  101. package/dist/vue/components/MScreen.js +11 -1
  102. package/dist/vue/components/MScreen.js.map +1 -1
  103. package/dist/vue/components/MSegmentedControl.d.ts +3 -3
  104. package/dist/vue/components/MSelect.d.ts +4 -4
  105. package/dist/vue/components/MSheet.d.ts +7 -7
  106. package/dist/vue/components/MSkeleton.d.ts +3 -3
  107. package/dist/vue/components/MSlider.d.ts +1 -1
  108. package/dist/vue/components/MStack.d.ts +19 -19
  109. package/dist/vue/components/MStack.d.ts.map +1 -1
  110. package/dist/vue/components/MStack.js +12 -2
  111. package/dist/vue/components/MStack.js.map +1 -1
  112. package/dist/vue/components/MSwitch.d.ts +3 -3
  113. package/dist/vue/components/MTabs.d.ts +3 -3
  114. package/dist/vue/components/MText.d.ts +8 -8
  115. package/dist/vue/components/MText.d.ts.map +1 -1
  116. package/dist/vue/components/MText.js +4 -1
  117. package/dist/vue/components/MText.js.map +1 -1
  118. package/dist/vue/components/MTimePicker.d.ts +40 -40
  119. package/dist/vue/components/MTimePicker.d.ts.map +1 -1
  120. package/dist/vue/components/MTooltip.d.ts +2 -2
  121. package/dist/vue/components/MVirtualList.d.ts.map +1 -1
  122. package/dist/vue/components/MVirtualList.js +88 -67
  123. package/dist/vue/components/MVirtualList.js.map +1 -1
  124. package/dist/vue/components/advanced.d.ts +34 -34
  125. package/dist/vue/components/configurator.d.ts +33 -33
  126. package/dist/vue/components/creative.d.ts +20 -20
  127. package/dist/vue/components/dashboard.d.ts +12 -12
  128. package/dist/vue/components/dashboard.d.ts.map +1 -1
  129. package/dist/vue/components/dashboard.js +185 -69
  130. package/dist/vue/components/dashboard.js.map +1 -1
  131. package/dist/vue/components/discovery.d.ts +10 -10
  132. package/dist/vue/components/interactive.d.ts +6 -6
  133. package/dist/vue/components/layout.d.ts +45 -45
  134. package/dist/vue/components/layout.d.ts.map +1 -1
  135. package/dist/vue/components/layout.js +8 -2
  136. package/dist/vue/components/layout.js.map +1 -1
  137. package/dist/vue/components/navigation.d.ts +4 -4
  138. package/dist/vue/components/screen-components.d.ts +23 -23
  139. package/dist/vue/components/screen-components.d.ts.map +1 -1
  140. package/dist/vue/components/screen-components.js +15 -0
  141. package/dist/vue/components/screen-components.js.map +1 -1
  142. package/dist/vue/components/wayfinding.d.ts +11 -11
  143. package/dist/vue/components/workflows.d.ts +5 -5
  144. package/dist/vue/layout-context.d.ts +4 -0
  145. package/dist/vue/layout-context.d.ts.map +1 -0
  146. package/dist/vue/layout-context.js +3 -0
  147. package/dist/vue/layout-context.js.map +1 -0
  148. package/dist/vue/navigation.d.ts +1 -3
  149. package/dist/vue/navigation.d.ts.map +1 -1
  150. package/dist/vue/navigation.js +1 -15
  151. package/dist/vue/navigation.js.map +1 -1
  152. package/dist/vue/screen-overlay.d.ts +9 -0
  153. package/dist/vue/screen-overlay.d.ts.map +1 -0
  154. package/dist/vue/screen-overlay.js +17 -0
  155. package/dist/vue/screen-overlay.js.map +1 -0
  156. package/dist/vue/use-motion-surface.d.ts +2 -3
  157. package/dist/vue/use-motion-surface.d.ts.map +1 -1
  158. package/dist/vue/use-motion-surface.js +9 -134
  159. package/dist/vue/use-motion-surface.js.map +1 -1
  160. package/package.json +8 -4
  161. package/platforms/android/java/com/mavis/ui/Box.java +31 -0
  162. package/src/components/bindings.ts +32 -0
  163. package/src/components/contracts.ts +60 -0
  164. package/src/components/controller.ts +542 -0
  165. package/src/components/index.ts +136 -0
  166. package/src/components/style.ts +84 -0
  167. package/src/components/theme.ts +25 -0
  168. package/src/native/box.ios.ts +31 -1
  169. package/src/native/flex-layout.ios.ts +4 -0
  170. package/src/native/motion-binding.ts +143 -0
  171. package/src/native/motion-region.ts +1 -0
  172. package/src/native/motion-surface.ts +41 -8
  173. package/src/native/navigation.ts +15 -0
  174. package/src/native/pointer-availability.ts +44 -0
  175. package/src/native/scroll-motion.ts +60 -19
  176. package/src/native/section-scroll.ts +16 -6
  177. package/src/vue/card-input.ts +44 -0
  178. package/src/vue/components/MCard.ts +4 -3
  179. package/src/vue/components/MGrid.ts +10 -1
  180. package/src/vue/components/MScreen.ts +12 -1
  181. package/src/vue/components/MStack.ts +17 -2
  182. package/src/vue/components/MText.ts +4 -1
  183. package/src/vue/components/MVirtualList.ts +104 -78
  184. package/src/vue/components/dashboard.ts +192 -69
  185. package/src/vue/components/layout.ts +8 -0
  186. package/src/vue/components/screen-components.ts +14 -0
  187. package/src/vue/layout-context.ts +4 -0
  188. package/src/vue/navigation.ts +1 -15
  189. package/src/vue/screen-overlay.ts +20 -0
  190. package/src/vue/use-motion-surface.ts +10 -137
@@ -4,6 +4,7 @@ import {
4
4
  inject,
5
5
  markRaw,
6
6
  mergeProps,
7
+ nextTick,
7
8
  onBeforeUnmount,
8
9
  onDeactivated,
9
10
  onScopeDispose,
@@ -11,12 +12,14 @@ import {
11
12
  } from 'nativescript-vue'
12
13
  import {
13
14
  Application,
15
+ isAndroid,
14
16
  type View,
15
17
  type EventData,
16
- type PanGestureEventData,
18
+ type LayoutBase,
19
+ type TouchGestureEventData,
17
20
  } from '@nativescript/core'
18
21
  import { notifyAccessibilityLayout } from '../../native/accessibility-layout'
19
- import { reducedMotion, onReducedMotion } from '@rafaelaugusto/jolt'
22
+ import { dropZones, reducedMotion, onReducedMotion, type DropZones } from '@rafaelaugusto/jolt'
20
23
  import {
21
24
  createDashboardShape,
22
25
  createDonutChart,
@@ -28,6 +31,8 @@ import {
28
31
  kanbanRegistryKey,
29
32
  kanbanZoneProps,
30
33
  kanbanDragProps,
34
+ useLayoutShrink,
35
+ type KanbanRegistry,
31
36
  } from '@getcortexlabs/mavis-core/vue'
32
37
  import { createMotionSurface } from '@getcortexlabs/mavis-core/experimental'
33
38
  import { MBox, MColumn, MRow } from './layout.js'
@@ -86,29 +91,53 @@ const Environment = defineComponent({
86
91
  })
87
92
  function rect(view?: View) {
88
93
  if (!view?.isLoaded) return
89
- const p = view.getLocationOnScreen(),
94
+ const p = view.getLocationInWindow(),
90
95
  size = view.getActualSize()
91
96
  return p ? { ...p, ...size } : undefined
92
97
  }
98
+ // A dragged card leaves its column: nothing between the card and the board may clip it.
99
+ // On Android a clipped source counts as hidden and Jolt cancels the drag.
100
+ function unclip(source: View, columns: readonly View[]) {
101
+ const show = (view: View) => {
102
+ if (isAndroid) {
103
+ const group = view.android as { setClipChildren?(clip: boolean): void } & {
104
+ setClipToPadding?(clip: boolean): void
105
+ }
106
+ group?.setClipChildren?.(false)
107
+ group?.setClipToPadding?.(false)
108
+ } else (view as LayoutBase).clipToBounds = false
109
+ }
110
+ for (let view = source.parent as View | undefined; view; view = view.parent as View | undefined) {
111
+ show(view)
112
+ if (columns.includes(view)) {
113
+ if (view.parent) show(view.parent as View)
114
+ break
115
+ }
116
+ }
117
+ }
93
118
  const Zone = defineComponent({
94
119
  inheritAttrs: false,
95
120
  props: kanbanZoneProps,
96
121
  setup(props, { attrs, slots }) {
97
- const registry = inject(kanbanRegistryKey)!
98
- let view: View | undefined
99
- onBeforeUnmount(() => registry.zones.delete(props.column))
122
+ const shrink = useLayoutShrink()
123
+ const registry = inject(kanbanRegistryKey)! as KanbanRegistry<View>
124
+ const leave = () => {
125
+ if (registry.zones.delete(props.column)) registry.revision.value++
126
+ }
127
+ onBeforeUnmount(leave)
100
128
  return () =>
101
129
  h(
102
130
  'GridLayout',
103
131
  mergeProps(attrs, {
132
+ // Match the Web's equal zero-basis columns only in the horizontal stack.
133
+ width: shrink.value ? 0 : 'auto',
134
+ flexShrink: shrink.value,
135
+ style: { zIndex: props.raised ? 20 : 0 },
104
136
  onLoaded: (e: EventData) => {
105
- view = e.object as View
106
- registry.zones.set(props.column, () => rect(view))
107
- },
108
- onUnloaded: () => {
109
- view = undefined
110
- registry.zones.delete(props.column)
137
+ registry.zones.set(props.column, e.object as View)
138
+ registry.revision.value++
111
139
  },
140
+ onUnloaded: leave,
112
141
  }),
113
142
  slots.default?.(),
114
143
  )
@@ -118,39 +147,131 @@ const Drag = defineComponent({
118
147
  inheritAttrs: false,
119
148
  props: kanbanDragProps,
120
149
  setup(props, { attrs, slots }) {
121
- const registry = inject(kanbanRegistryKey)!,
150
+ const registry = inject(kanbanRegistryKey)! as KanbanRegistry<View>,
122
151
  surface = markRaw(createMotionSurface())
123
152
  let view: View | undefined,
124
- anchor: ReturnType<typeof rect>,
125
- dragging = false
126
- function end(commit = false) {
127
- const was = dragging
128
- dragging = false
129
- if (surface.available) {
130
- if (props.animated && !commit)
131
- surface.animate({ x: 0, y: 0, scale: 1 }, { type: 'spring', duration: 280, bounce: 0.12 })
132
- else surface.set({ x: 0, y: 0, scale: 1 })
133
- }
153
+ source: View | undefined,
154
+ grip: View | undefined,
155
+ zones: DropZones | undefined,
156
+ live = false,
157
+ queued = false,
158
+ disposed = false
159
+ function settle() {
160
+ live = false
161
+ Application.off(Application.suspendEvent, cancel)
134
162
  if (view) view.style.zIndex = 0
135
- if (was) registry.finish(commit)
136
163
  }
137
- const cancel = () => end(false)
164
+ // Jolt can end a drag on its own (a cancelled touch, a source that went out of sight) and
165
+ // leaves the card where it was; once the touch is over the board brings it back.
166
+ const touched = (e: TouchGestureEventData) => {
167
+ if (e.action !== 'up' && e.action !== 'cancel') return
168
+ setTimeout(() => {
169
+ if (live && !zones?.dragging) cancel()
170
+ })
171
+ }
172
+ function rest(animated: boolean) {
173
+ if (!surface.available) return
174
+ if (animated && props.animated)
175
+ surface.animate({ x: 0, y: 0, scale: 1 }, { type: 'spring', duration: 280, bounce: 0.12 })
176
+ else surface.set({ x: 0, y: 0, scale: 1 })
177
+ }
178
+ function cancel() {
179
+ end(true)
180
+ }
181
+ function cancelImmediately() {
182
+ end(false)
183
+ }
184
+ function end(animated: boolean) {
185
+ const was = live
186
+ settle()
187
+ zones?.cancel()
188
+ if (!was) return
189
+ rest(animated)
190
+ registry.finish(props.cardId)
191
+ }
192
+ function release() {
193
+ zones?.dispose()
194
+ zones = undefined
195
+ }
196
+ function attach() {
197
+ if (live) return
198
+ release()
199
+ if (props.disabled || !source?.isLoaded || !grip?.isLoaded) return
200
+ const targets = registry.targets(props.cardId).filter(({ target }) => target.isLoaded)
201
+ if (!targets.length) return
202
+ unclip(
203
+ source,
204
+ targets.map(({ target }) => target),
205
+ )
206
+ zones = dropZones(source, {
207
+ targets,
208
+ drag: { handle: grip, snap: [0] },
209
+ onMove({ id, bounds }) {
210
+ if (!live) {
211
+ if (!registry.begin(props.cardId, cancel)) {
212
+ zones?.cancel()
213
+ return
214
+ }
215
+ live = true
216
+ Application.on(Application.suspendEvent, cancel)
217
+ if (view) view.style.zIndex = 20
218
+ if (surface.available) surface.set({ scale: 1.02 })
219
+ }
220
+ registry.move(id, bounds)
221
+ },
222
+ onLeave: () => registry.leave(),
223
+ onDrop() {
224
+ settle()
225
+ rest(false)
226
+ registry.drop()
227
+ },
228
+ onReject() {
229
+ settle()
230
+ registry.finish(props.cardId)
231
+ if (!surface.available) return
232
+ if (props.animated)
233
+ surface.animate({ scale: 1 }, { type: 'spring', duration: 280, bounce: 0.12 })
234
+ else
235
+ void Promise.resolve().then(() => {
236
+ zones?.cancel()
237
+ rest(false)
238
+ })
239
+ },
240
+ })
241
+ }
242
+ // Views load parent first, so the columns and the card's own views arrive over one tick.
243
+ function schedule() {
244
+ if (queued || disposed) return
245
+ queued = true
246
+ void nextTick(() => {
247
+ queued = false
248
+ if (!disposed) attach()
249
+ })
250
+ }
251
+ function unload() {
252
+ cancelImmediately()
253
+ release()
254
+ }
138
255
  onBeforeUnmount(() => {
139
- cancel()
256
+ disposed = true
257
+ unload()
140
258
  registry.cards.delete(props.cardId)
141
259
  registry.focus.delete(props.cardId)
142
260
  })
143
- onDeactivated(cancel)
144
- onScopeDispose(surface.use(() => cancel))
145
- watch(
146
- () => props.disabled,
147
- (value) => {
148
- if (value) cancel()
149
- },
261
+ onDeactivated(cancelImmediately)
262
+ onScopeDispose(
263
+ surface.use(() => {
264
+ // A retained native view can reconnect after its return animation was
265
+ // stopped by unload. Start each presentation at the controlled position.
266
+ rest(false)
267
+ return cancelImmediately
268
+ }),
150
269
  )
270
+ watch(() => [registry.revision.value, props.disabled], schedule)
271
+ // A plain GridLayout would take the column's whole height on iOS; a box keeps the card's own.
151
272
  return () =>
152
273
  h(
153
- 'GridLayout',
274
+ MBox,
154
275
  mergeProps(attrs, {
155
276
  onLoaded: (e: EventData) => {
156
277
  view = e.object as View
@@ -160,48 +281,50 @@ const Drag = defineComponent({
160
281
  })
161
282
  },
162
283
  onUnloaded: () => {
163
- cancel()
284
+ unload()
164
285
  view = undefined
165
286
  registry.cards.delete(props.cardId)
166
287
  registry.focus.delete(props.cardId)
167
288
  },
168
289
  }),
169
- [
170
- h(MBox, { motionSurface: surface }, () =>
171
- h(MColumn, { gap: 'xs' }, () => [
172
- h(
173
- MBox,
174
- {
175
- height: 36,
176
- accessibilityHidden: true,
177
- accessibilityLabel: props.label,
178
- opacity: props.disabled ? 0.4 : 0.65,
179
- onPan: (e: PanGestureEventData) => {
180
- if (props.disabled) return
181
- if (e.state === 1) {
182
- anchor = rect(view)
183
- dragging = registry.begin(props.cardId, cancel)
184
- if (dragging && view) view.style.zIndex = 20
185
- }
186
- if (e.state === 2 && dragging && surface.available) {
187
- const current = rect(view)
188
- surface.set({
189
- x: e.deltaX + (anchor && current ? anchor.x - current.x : 0),
190
- y: e.deltaY + (anchor && current ? anchor.y - current.y : 0),
191
- scale: 1.02,
192
- })
193
- registry.move(e.deltaX, e.deltaY)
194
- }
195
- if (e.state === 3) end(true)
196
- if (e.state === 4) cancel()
290
+ () =>
291
+ h(
292
+ MBox,
293
+ {
294
+ motionSurface: surface,
295
+ onLoaded: (e: EventData) => {
296
+ source = e.object as View
297
+ schedule()
298
+ },
299
+ onUnloaded: () => {
300
+ unload()
301
+ source = undefined
302
+ },
303
+ },
304
+ () =>
305
+ h(MColumn, { gap: 'xs' }, () => [
306
+ h(
307
+ MBox,
308
+ {
309
+ height: 36,
310
+ accessibilityHidden: true,
311
+ accessibilityLabel: props.label,
312
+ opacity: props.disabled ? 0.4 : 0.65,
313
+ onTouch: touched,
314
+ onLoaded: (e: EventData) => {
315
+ grip = e.object as View
316
+ schedule()
317
+ },
318
+ onUnloaded: () => {
319
+ unload()
320
+ grip = undefined
321
+ },
197
322
  },
198
- },
199
- () => h(MText, { text: '⠿', textAlignment: 'center' }),
200
- ),
201
- ...(slots.default?.() ?? []),
202
- ]),
323
+ () => h(MText, { text: '⠿', textAlignment: 'center' }),
324
+ ),
325
+ ...(slots.default?.() ?? []),
326
+ ]),
203
327
  ),
204
- ],
205
328
  )
206
329
  },
207
330
  })
@@ -16,6 +16,8 @@ import { useNativeViewAttrs } from '../accessibility.js'
16
16
  import { useMotionRegion } from '../use-motion-region.js'
17
17
  import { useMotionSurface } from '../use-motion-surface.js'
18
18
  import { perspectiveKey } from '../perspective.js'
19
+ import { useOverlayLayout } from '../screen-overlay.js'
20
+ import { boxLayer } from '../layout-context.js'
19
21
 
20
22
  export type { Align, Justify } from '@getcortexlabs/mavis-core/vue'
21
23
 
@@ -45,6 +47,8 @@ function createLayout(name: string, direction: 'row' | 'column') {
45
47
  inheritAttrs: false,
46
48
  props: direction === 'row' ? rowProps : columnProps,
47
49
  setup(props, { attrs, slots }) {
50
+ const overlay = useOverlayLayout()
51
+ provide(boxLayer, false)
48
52
  const region = useMotionRegion(() => props.motionRegion)
49
53
  const { theme } = useMavisTheme()
50
54
  const nativeAttrs = useNativeViewAttrs(props)
@@ -54,6 +58,7 @@ function createLayout(name: string, direction: 'row' | 'column') {
54
58
  h(
55
59
  'MavisFlexLayout',
56
60
  mergeProps(
61
+ overlay(attrs),
57
62
  {
58
63
  style: {
59
64
  ...boxStyle(theme.value, props, shrink.value),
@@ -83,6 +88,8 @@ export const MBox = defineComponent({
83
88
  inheritAttrs: false,
84
89
  props: motionBoxProps,
85
90
  setup(props, { attrs, slots }) {
91
+ const overlay = useOverlayLayout()
92
+ provide(boxLayer, true)
86
93
  const region = useMotionRegion(() => props.motionRegion)
87
94
  const surface = useMotionSurface(() => props.motionSurface)
88
95
  provide(perspectiveKey, () => resolvePerspective(props.perspective))
@@ -93,6 +100,7 @@ export const MBox = defineComponent({
93
100
  h(
94
101
  'MavisBox',
95
102
  mergeProps(
103
+ overlay(attrs),
96
104
  { style: boxStyle(theme.value, props, shrink.value) },
97
105
  nativeAttrs(),
98
106
  attrs,
@@ -1,4 +1,5 @@
1
1
  import { defineComponent, h, mergeProps, registerElement } from 'nativescript-vue'
2
+ import { isIOS, type EventData, type View } from '@nativescript/core'
2
3
  import { ScrollHeaderSurface } from '@rafaelaugusto/jolt'
3
4
  import {
4
5
  createAnimatedText,
@@ -19,6 +20,18 @@ import { MChip } from './MChip.js'
19
20
  import { MPopover } from './MPopover.js'
20
21
 
21
22
  registerElement('MavisRefreshFrame', () => ScrollHeaderSurface, { viewFlags: 4 })
23
+ const Clip = defineComponent({
24
+ name: 'MScrollHeaderClip',
25
+ inheritAttrs: false,
26
+ setup(_, { attrs, slots }) {
27
+ const loaded = ({ object }: EventData) => {
28
+ // Core defaults clipToBounds to true, so assigning true can skip its native
29
+ // setter. Enforce it once the UIView exists, independently of Jolt's header.
30
+ if (isIOS) (object as View).nativeViewProtected.clipsToBounds = true
31
+ }
32
+ return () => h(MBox, mergeProps(attrs, { clipToBounds: true, onLoaded: loaded }), slots)
33
+ },
34
+ })
22
35
  const Frame = defineComponent({
23
36
  name: 'MScrollFrameHost',
24
37
  inheritAttrs: false,
@@ -43,6 +56,7 @@ const Frame = defineComponent({
43
56
  })
44
57
  const ui = {
45
58
  Box: MBox,
59
+ Clip,
46
60
  Card: MCard,
47
61
  Column: MColumn,
48
62
  Row: MRow,
@@ -0,0 +1,4 @@
1
+ import type { InjectionKey } from 'nativescript-vue'
2
+
3
+ /** Text directly in a layered box starts at its top, like text in a CSS grid cell. */
4
+ export const boxLayer: InjectionKey<boolean> = Symbol('mavis.boxLayer')
@@ -1,15 +1 @@
1
- import { Utils } from '@nativescript/core'
2
- import { linkDestination, type NavigationOptions } from '@getcortexlabs/mavis-core'
3
-
4
- export function nativeDestination(options: NavigationOptions) {
5
- const href = linkDestination(options.href!)
6
- if (!options.navigate && !/^[a-z][a-z\d+.-]*:/i.test(href))
7
- throw new TypeError('Native navigation needs a navigate handler for in-app destinations.')
8
- return href
9
- }
10
-
11
- export async function navigateNative(options: NavigationOptions) {
12
- const href = nativeDestination(options)
13
- if (options.navigate) await options.navigate(href)
14
- else if (!(await Utils.openUrl(href))) throw new Error(`The system could not open ${href}.`)
15
- }
1
+ export { nativeDestination, navigateNative } from '../native/navigation.js'
@@ -0,0 +1,20 @@
1
+ import { inject, type InjectionKey } from 'nativescript-vue'
2
+
3
+ /** Only the screen's decorative slot inherits this; modal and toast hosts do not. */
4
+ export const screenOverlay: InjectionKey<boolean> = Symbol('mavis.screenOverlay')
5
+
6
+ export function useOverlayLayout() {
7
+ const overlay = inject(screenOverlay, false)
8
+ return (attrs: Record<string, unknown>) => {
9
+ if (!overlay) return {}
10
+ const style = attrs.style as { pointerEvents?: string } | undefined
11
+ // Explicit native gestures and the Web's pointer opt-in keep interactive
12
+ // layers usable. Plain nested layouts let their empty area pass through.
13
+ const interactive =
14
+ style?.pointerEvents === 'auto' ||
15
+ ['onTap', 'onTouch', 'onPan', 'onLongPress', 'onDoubleTap', 'onSwipe'].some(
16
+ (name) => attrs[name],
17
+ )
18
+ return { isPassThroughParentEnabled: !interactive }
19
+ }
20
+ }
@@ -1,17 +1,7 @@
1
- import { Utils, isAndroid, type EventData, type View } from '@nativescript/core'
2
1
  import { inject, onBeforeUnmount, watch } from 'nativescript-vue'
3
- import { animate, set, onReducedMotion } from '@rafaelaugusto/jolt'
4
- import {
5
- bindMotionSurface,
6
- motionChannels,
7
- motionKeyframes,
8
- type MotionFrames,
9
- type MotionSurface,
10
- } from '@getcortexlabs/mavis-core/experimental'
11
- import { nativeContinuousSurface } from '../native/motion-surface.js'
12
- import { nativeMotionOwner } from '../native/motion-owner.js'
2
+ import type { MotionSurface } from '@getcortexlabs/mavis-core/experimental'
3
+ import { createNativeMotionSurface } from '../native/motion-binding.js'
13
4
  import { perspectiveKey } from './perspective.js'
14
- import { takeShadow } from '../native/moved-shadow.js'
15
5
 
16
6
  export function useMotionSurface(
17
7
  surface: () => MotionSurface | undefined,
@@ -19,132 +9,15 @@ export function useMotionSurface(
19
9
  plainText: () => boolean = () => false,
20
10
  afterLayout = false,
21
11
  ) {
22
- let view: View | undefined
23
- let unbind: (() => void) | undefined
24
- let offPreference: (() => void) | undefined
25
- let continuous: ReturnType<typeof nativeContinuousSurface> | undefined
26
- const active = new Map<ReturnType<typeof animate>, MotionFrames>()
27
- let layoutView: View | undefined
28
- let layoutQueued = false
29
12
  const perspective = inject(perspectiveKey, undefined)
30
- let flat: { view: View; perspective: number } | undefined
31
- const project = () => {
32
- const depth = perspective?.()
33
- if (flat && (depth === undefined || flat.view !== view)) {
34
- flat.view.perspective = flat.perspective
35
- flat = undefined
36
- }
37
- if (!view || depth === undefined || !unbind) return
38
- flat ??= { view, perspective: view.perspective }
39
- // Core multiplies by the density for Android's camera distance, whose unit is not the
40
- // CSS distance. This is the factor that draws the same projection as iOS and the Web.
41
- view.perspective = isAndroid ? depth * Utils.layout.getDisplayDensity() * Math.sqrt(5) : depth
42
- }
43
- const clearLayout = () => {
44
- layoutView?.off('layoutChanged', laidOut)
45
- layoutView = undefined
46
- }
47
- const release = () => {
48
- unbind?.()
49
- unbind = undefined
50
- continuous = undefined
51
- offPreference?.()
52
- offPreference = undefined
53
- for (const handle of active.keys()) handle.stop()
54
- active.clear()
55
- project()
56
- }
57
- const bind = () => {
58
- release()
59
- const target = view
60
- const reference = surface()
61
- if (!target || !reference) return
62
- if (
63
- afterLayout &&
64
- (!target.isLayoutValid ||
65
- target.getActualSize().width <= 0 ||
66
- target.getActualSize().height <= 0)
67
- ) {
68
- if (layoutView !== target) {
69
- clearLayout()
70
- layoutView = target
71
- target.on('layoutChanged', laidOut)
72
- }
73
- return
74
- }
75
- clearLayout()
76
- continuous = nativeContinuousSurface(target, enabled, plainText)
77
- unbind = bindMotionSurface(
78
- reference,
79
- nativeMotionOwner(
80
- {
81
- ...continuous.adapter,
82
- animate(values, options) {
83
- continuous?.interrupt(motionChannels(values))
84
- const handle = animate(target, motionKeyframes(values), options)
85
- takeShadow(target, values)
86
- active.set(handle, values)
87
- void handle.finished.then(() => active.delete(handle))
88
- return handle
89
- },
90
- set: (values) => {
91
- continuous?.interrupt(Object.keys(values))
92
- // Jolt on Android leaves the path's translationY on the view when a path still in
93
- // flight is replaced by a zero-duration set (rafaelaugustos/jolt#479).
94
- if (isAndroid && ('x' in values || 'y' in values || 'rotate' in values))
95
- for (const [handle, frames] of active) if (frames.path) handle.stop()
96
- const handle = animate(target, values, { duration: 0 })
97
- takeShadow(target, values)
98
- return handle
99
- },
100
- },
101
- target,
102
- ),
103
- )
104
- project()
105
- offPreference = onReducedMotion((reduced) => {
106
- if (!reduced) return
107
- // Set only spatial channels: opacity and shadow paint can keep their timelines.
108
- const values: Record<string, number> = {}
109
- for (const frames of active.values()) {
110
- if (frames.path)
111
- Object.assign(values, {
112
- x: frames.path.end.x,
113
- y: frames.path.end.y,
114
- ...(frames.orient ? { rotate: frames.path.end.rotate } : {}),
115
- })
116
- for (const [property, value] of Object.entries(frames)) {
117
- if (property === 'opacity' || property.startsWith('shadow')) continue
118
- const final = Array.isArray(value) ? value.at(-1) : value
119
- if (typeof final === 'number') values[property] = final
120
- }
121
- }
122
- if (Object.keys(values).length) set(target, values)
123
- })
124
- }
125
- const laidOut = () => {
126
- if (layoutQueued) return
127
- layoutQueued = true
128
- void Promise.resolve().then(() => {
129
- layoutQueued = false
130
- if (view) bind()
131
- })
132
- }
133
- const unloaded = () => {
134
- clearLayout()
135
- release()
136
- view = undefined
137
- }
138
- watch(surface, bind, { flush: 'post' })
139
- if (perspective) watch(perspective, project, { flush: 'post' })
140
- watch(enabled, () => continuous?.refresh(), { flush: 'sync' })
141
- onBeforeUnmount(unloaded)
13
+ const binding = createNativeMotionSurface(surface, enabled, plainText, afterLayout, perspective)
14
+ watch(surface, binding.refresh, { flush: 'post' })
15
+ if (perspective) watch(perspective, binding.refreshPerspective, { flush: 'post' })
16
+ watch(enabled, binding.refreshEnabled, { flush: 'sync' })
17
+ onBeforeUnmount(binding.onUnloaded)
142
18
  return {
143
- allowsActivation: () => continuous?.allowsActivation() ?? true,
144
- onLoaded(event: EventData) {
145
- view = event.object as View
146
- bind()
147
- },
148
- onUnloaded: unloaded,
19
+ allowsActivation: binding.allowsActivation,
20
+ onLoaded: binding.onLoaded,
21
+ onUnloaded: binding.onUnloaded,
149
22
  }
150
23
  }