@getcortexlabs/mavis 0.1.0-alpha.7 → 0.1.0-alpha.9

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 (159) hide show
  1. package/README.md +7 -5
  2. package/dist/date-format.android.d.ts +5 -0
  3. package/dist/date-format.android.d.ts.map +1 -0
  4. package/dist/date-format.android.js +39 -0
  5. package/dist/date-format.android.js.map +1 -0
  6. package/dist/date-format.d.ts +3 -0
  7. package/dist/date-format.d.ts.map +1 -0
  8. package/dist/date-format.ios.d.ts +5 -0
  9. package/dist/date-format.ios.d.ts.map +1 -0
  10. package/dist/date-format.ios.js +29 -0
  11. package/dist/date-format.ios.js.map +1 -0
  12. package/dist/date-format.js +2 -0
  13. package/dist/date-format.js.map +1 -0
  14. package/dist/native/collection-motion.d.ts +5 -0
  15. package/dist/native/collection-motion.d.ts.map +1 -0
  16. package/dist/native/collection-motion.js +157 -0
  17. package/dist/native/collection-motion.js.map +1 -0
  18. package/dist/native/date-format.android.d.ts +5 -0
  19. package/dist/native/date-format.android.d.ts.map +1 -0
  20. package/dist/native/date-format.android.js +39 -0
  21. package/dist/native/date-format.android.js.map +1 -0
  22. package/dist/native/date-format.d.ts +6 -0
  23. package/dist/native/date-format.d.ts.map +1 -0
  24. package/dist/native/date-format.ios.d.ts +5 -0
  25. package/dist/native/date-format.ios.d.ts.map +1 -0
  26. package/dist/native/date-format.ios.js +29 -0
  27. package/dist/native/date-format.ios.js.map +1 -0
  28. package/dist/native/date-format.js +8 -0
  29. package/dist/native/date-format.js.map +1 -0
  30. package/dist/native/image-effects.d.ts +11 -0
  31. package/dist/native/image-effects.d.ts.map +1 -0
  32. package/dist/native/image-effects.js +61 -0
  33. package/dist/native/image-effects.js.map +1 -0
  34. package/dist/native/motion-region.d.ts.map +1 -1
  35. package/dist/native/motion-region.js +7 -2
  36. package/dist/native/motion-region.js.map +1 -1
  37. package/dist/native/motion-surface.d.ts +2 -2
  38. package/dist/native/motion-surface.d.ts.map +1 -1
  39. package/dist/native/motion-surface.js +44 -1
  40. package/dist/native/motion-surface.js.map +1 -1
  41. package/dist/native/platform-motion.d.ts +5 -0
  42. package/dist/native/platform-motion.d.ts.map +1 -0
  43. package/dist/native/platform-motion.js +90 -0
  44. package/dist/native/platform-motion.js.map +1 -0
  45. package/dist/native/surface-effects.d.ts +4 -0
  46. package/dist/native/surface-effects.d.ts.map +1 -0
  47. package/dist/native/surface-effects.js +31 -0
  48. package/dist/native/surface-effects.js.map +1 -0
  49. package/dist/native/visual-effects.d.ts +5 -0
  50. package/dist/native/visual-effects.d.ts.map +1 -0
  51. package/dist/native/visual-effects.js +126 -0
  52. package/dist/native/visual-effects.js.map +1 -0
  53. package/dist/vue/components/DateCalendar.d.ts +1 -1
  54. package/dist/vue/components/LoadingDecoration.d.ts +116 -0
  55. package/dist/vue/components/LoadingDecoration.d.ts.map +1 -0
  56. package/dist/vue/components/LoadingDecoration.js +34 -0
  57. package/dist/vue/components/LoadingDecoration.js.map +1 -0
  58. package/dist/vue/components/MAlert.d.ts +1 -1
  59. package/dist/vue/components/MAvatar.d.ts +1 -1
  60. package/dist/vue/components/MButton.d.ts +32 -10
  61. package/dist/vue/components/MButton.d.ts.map +1 -1
  62. package/dist/vue/components/MButton.js +33 -5
  63. package/dist/vue/components/MButton.js.map +1 -1
  64. package/dist/vue/components/MCard.d.ts +4 -4
  65. package/dist/vue/components/MCard.d.ts.map +1 -1
  66. package/dist/vue/components/MCard.js +4 -3
  67. package/dist/vue/components/MCard.js.map +1 -1
  68. package/dist/vue/components/MChip.d.ts +1 -1
  69. package/dist/vue/components/MCombobox.d.ts +2 -2
  70. package/dist/vue/components/MDatePicker.d.ts +56 -8
  71. package/dist/vue/components/MDatePicker.d.ts.map +1 -1
  72. package/dist/vue/components/MDatePicker.js +4 -14
  73. package/dist/vue/components/MDatePicker.js.map +1 -1
  74. package/dist/vue/components/MDialog.d.ts +3 -0
  75. package/dist/vue/components/MDialog.d.ts.map +1 -1
  76. package/dist/vue/components/MEmptyState.d.ts +1 -1
  77. package/dist/vue/components/MGrid.d.ts +165 -0
  78. package/dist/vue/components/MGrid.d.ts.map +1 -0
  79. package/dist/vue/components/MGrid.js +52 -0
  80. package/dist/vue/components/MGrid.js.map +1 -0
  81. package/dist/vue/components/MIcon.d.ts +18 -0
  82. package/dist/vue/components/MIcon.d.ts.map +1 -1
  83. package/dist/vue/components/MIcon.js +13 -2
  84. package/dist/vue/components/MIcon.js.map +1 -1
  85. package/dist/vue/components/MImage.d.ts +57 -1
  86. package/dist/vue/components/MImage.d.ts.map +1 -1
  87. package/dist/vue/components/MImage.js +58 -3
  88. package/dist/vue/components/MImage.js.map +1 -1
  89. package/dist/vue/components/MInput.d.ts +6 -6
  90. package/dist/vue/components/MInput.d.ts.map +1 -1
  91. package/dist/vue/components/MInput.js +15 -0
  92. package/dist/vue/components/MInput.js.map +1 -1
  93. package/dist/vue/components/MLink.d.ts +2 -2
  94. package/dist/vue/components/MLink.d.ts.map +1 -1
  95. package/dist/vue/components/MLink.js +6 -11
  96. package/dist/vue/components/MLink.js.map +1 -1
  97. package/dist/vue/components/MListItem.d.ts +1 -1
  98. package/dist/vue/components/MReveal.d.ts +9 -9
  99. package/dist/vue/components/MScreen.d.ts +11 -1
  100. package/dist/vue/components/MScreen.d.ts.map +1 -1
  101. package/dist/vue/components/MScreen.js +26 -4
  102. package/dist/vue/components/MScreen.js.map +1 -1
  103. package/dist/vue/components/MSelect.d.ts +1 -1
  104. package/dist/vue/components/MSheet.d.ts +13 -4
  105. package/dist/vue/components/MSheet.d.ts.map +1 -1
  106. package/dist/vue/components/MSkeleton.d.ts +12 -1
  107. package/dist/vue/components/MSkeleton.d.ts.map +1 -1
  108. package/dist/vue/components/MSkeleton.js +5 -3
  109. package/dist/vue/components/MSkeleton.js.map +1 -1
  110. package/dist/vue/components/MStack.d.ts +9 -9
  111. package/dist/vue/components/MText.d.ts +11 -0
  112. package/dist/vue/components/MText.d.ts.map +1 -1
  113. package/dist/vue/components/MText.js +3 -1
  114. package/dist/vue/components/MText.js.map +1 -1
  115. package/dist/vue/components/configurator.d.ts +3 -3
  116. package/dist/vue/components/layout.d.ts +30 -19
  117. package/dist/vue/components/layout.d.ts.map +1 -1
  118. package/dist/vue/components/layout.js +3 -1
  119. package/dist/vue/components/layout.js.map +1 -1
  120. package/dist/vue/index.d.ts +11 -11
  121. package/dist/vue/index.d.ts.map +1 -1
  122. package/dist/vue/index.js +12 -12
  123. package/dist/vue/index.js.map +1 -1
  124. package/dist/vue/services.d.ts +16 -0
  125. package/dist/vue/services.d.ts.map +1 -0
  126. package/dist/vue/services.js +18 -0
  127. package/dist/vue/services.js.map +1 -0
  128. package/dist/vue/use-motion-surface.d.ts +1 -1
  129. package/dist/vue/use-motion-surface.d.ts.map +1 -1
  130. package/dist/vue/use-motion-surface.js +31 -2
  131. package/dist/vue/use-motion-surface.js.map +1 -1
  132. package/package.json +15 -4
  133. package/src/date-format.ts +2 -0
  134. package/src/native/collection-motion.ts +166 -0
  135. package/src/native/date-format.android.ts +72 -0
  136. package/src/native/date-format.ios.ts +54 -0
  137. package/src/native/date-format.ts +17 -0
  138. package/src/native/image-effects.ts +71 -0
  139. package/src/native/motion-region.ts +7 -2
  140. package/src/native/motion-surface.ts +51 -2
  141. package/src/native/platform-motion.ts +103 -0
  142. package/src/native/surface-effects.ts +33 -0
  143. package/src/native/visual-effects.ts +147 -0
  144. package/src/vue/components/LoadingDecoration.ts +38 -0
  145. package/src/vue/components/MButton.ts +37 -4
  146. package/src/vue/components/MCard.ts +4 -2
  147. package/src/vue/components/MDatePicker.ts +3 -11
  148. package/src/vue/components/MGrid.ts +86 -0
  149. package/src/vue/components/MIcon.ts +14 -2
  150. package/src/vue/components/MImage.ts +66 -2
  151. package/src/vue/components/MInput.ts +14 -3
  152. package/src/vue/components/MLink.ts +12 -9
  153. package/src/vue/components/MScreen.ts +31 -3
  154. package/src/vue/components/MSkeleton.ts +5 -3
  155. package/src/vue/components/MText.ts +7 -0
  156. package/src/vue/components/layout.ts +3 -0
  157. package/src/vue/index.ts +63 -69
  158. package/src/vue/services.ts +32 -0
  159. package/src/vue/use-motion-surface.ts +32 -1
@@ -0,0 +1,147 @@
1
+ import { Label, Image, isIOS, type View } from '@nativescript/core'
2
+ import { nativeSurfaceEffects } from './surface-effects.js'
3
+ import {
4
+ gradient,
5
+ shimmer,
6
+ loader,
7
+ reveal,
8
+ conceal,
9
+ animateText,
10
+ rollTo,
11
+ type DerivedValue,
12
+ type DerivedColor,
13
+ } from '@rafaelaugusto/jolt'
14
+ import {
15
+ mapGradientBindings,
16
+ type MotionVisualAdapter,
17
+ type MotionCircular,
18
+ type MotionPlayback,
19
+ } from '@getcortexlabs/mavis-core/experimental'
20
+
21
+ const circles = new WeakMap<View, { dispose(): void }>()
22
+ export function nativeVisualEffects(
23
+ target: View,
24
+ sources: WeakMap<object, DerivedValue>,
25
+ colors: WeakMap<object, DerivedColor>,
26
+ plainText: () => boolean,
27
+ ): MotionVisualAdapter {
28
+ const text = () => {
29
+ if (!plainText() || !(target instanceof Label) || target.formattedText)
30
+ throw new TypeError(
31
+ 'Declare a motionSurface on MText with an explicit text prop; rich/slotted text is unsupported.',
32
+ )
33
+ return target
34
+ }
35
+ return {
36
+ ...nativeSurfaceEffects(target),
37
+ supports: (effect) => {
38
+ if (effect === 'text') return plainText()
39
+ if (effect === 'symbol')
40
+ return isIOS && target instanceof Image && Boolean(target.ios?.image?.symbolImage)
41
+ if (effect === 'image') return target instanceof Image
42
+ if (effect === 'liquid') return isIOS && target instanceof Image
43
+ return (
44
+ ['gradient', 'particles', 'confetti', 'blur', 'shape', 'keyboard'].includes(effect) || isIOS
45
+ )
46
+ },
47
+ gradient(options) {
48
+ const paint = gradient(target, options)
49
+ return {
50
+ type: paint.type,
51
+ get suspended() {
52
+ return paint.suspended
53
+ },
54
+ animate: (values, options) => paint.animate(values, options),
55
+ set: (values) => paint.set(values),
56
+ stop: () => paint.stop(),
57
+ suspend: () => paint.suspend(),
58
+ resume: () => paint.resume(),
59
+ bind(values) {
60
+ const dispose = paint.bind(
61
+ mapGradientBindings(
62
+ values,
63
+ (value) => sources.get(value)!,
64
+ (value) => colors.get(value)!,
65
+ ),
66
+ )
67
+ return { dispose }
68
+ },
69
+ dispose: () => paint.remove(),
70
+ }
71
+ },
72
+ shimmer: (options) => ({ supported: isIOS, dispose: shimmer(target, options) }),
73
+ loader: (options) => ({ supported: isIOS, dispose: loader(target, options) }),
74
+ animateText: (options) => animateText(text(), options),
75
+ rollTo: (value, options) => rollTo(text(), value, options),
76
+ circular() {
77
+ circles.get(target)?.dispose()
78
+ const hidden = target.accessibilityHidden,
79
+ interactive = target.isUserInteractionEnabled
80
+ const visibility = target.visibility
81
+ let active: MotionPlayback | undefined,
82
+ locked = false,
83
+ generation = 0,
84
+ disposed = false
85
+ let writtenVisibility: View['visibility'] | undefined
86
+ const focused = (view: View): boolean => {
87
+ if (view.ios?.isFirstResponder) return true
88
+ let found = false
89
+ view.eachChildView((child) => {
90
+ found = focused(child)
91
+ return !found
92
+ })
93
+ return found
94
+ }
95
+ const unlock = () => {
96
+ if (!locked) return
97
+ locked = false
98
+ if (target.accessibilityHidden) target.accessibilityHidden = hidden
99
+ if (!target.isUserInteractionEnabled) target.isUserInteractionEnabled = interactive
100
+ }
101
+ const run = (open: boolean, options: Parameters<MotionCircular['reveal']>[0] = {}) => {
102
+ if (isIOS && !open && focused(target))
103
+ throw new Error('Move focus outside the circular surface before conceal().')
104
+ const handle = open
105
+ ? reveal(target, { from: options.origin, duration: options.duration })
106
+ : conceal(target, { to: options.origin, duration: options.duration })
107
+ const token = ++generation
108
+ active = handle
109
+ if (isIOS) writtenVisibility = target.visibility
110
+ if (isIOS) {
111
+ if (open) unlock()
112
+ else {
113
+ locked = true
114
+ target.accessibilityHidden = true
115
+ target.isUserInteractionEnabled = false
116
+ }
117
+ }
118
+ void handle.finished.then((completed) => {
119
+ if (token !== generation || disposed) return
120
+ active = undefined
121
+ if (completed && isIOS) writtenVisibility = target.visibility
122
+ if (!completed && target.visibility !== 'hidden') unlock()
123
+ })
124
+ return handle
125
+ }
126
+ const control = {
127
+ supported: isIOS,
128
+ reveal: (options?: Parameters<MotionCircular['reveal']>[0]) => run(true, options),
129
+ conceal: (options?: Parameters<MotionCircular['conceal']>[0]) => run(false, options),
130
+ dispose() {
131
+ if (disposed) return
132
+ disposed = true
133
+ generation++
134
+ active?.stop()
135
+ unlock()
136
+ if (circles.get(target) === control) {
137
+ circles.delete(target)
138
+ if (isIOS && writtenVisibility !== undefined && target.visibility === writtenVisibility)
139
+ target.visibility = visibility
140
+ }
141
+ },
142
+ }
143
+ circles.set(target, control)
144
+ return control
145
+ },
146
+ }
147
+ }
@@ -0,0 +1,38 @@
1
+ import { defineComponent, h, mergeProps, type PropType } from 'nativescript-vue'
2
+ import { skeletonProps, useLoadingDecoration } from '@getcortexlabs/mavis-core/vue'
3
+ import { MBox } from './layout.js'
4
+
5
+ export const LoadingDecoration = defineComponent({
6
+ name: 'MavisLoadingDecoration',
7
+ inheritAttrs: false,
8
+ props: {
9
+ ...skeletonProps,
10
+ kind: { type: String as PropType<'shimmer' | 'dots' | 'bars' | 'ring'>, required: true },
11
+ color: { type: String, default: undefined },
12
+ size: { type: Number, default: 24 },
13
+ },
14
+ setup(props, { attrs }) {
15
+ const surface = useLoadingDecoration(() => ({
16
+ kind: props.kind,
17
+ animated: props.animated,
18
+ size: props.size,
19
+ color: props.color,
20
+ }))
21
+ return () =>
22
+ h(
23
+ MBox,
24
+ mergeProps(attrs, {
25
+ id: props.id,
26
+ width: props.width,
27
+ height: props.height,
28
+ radius: props.radius,
29
+ grow: props.grow,
30
+ shrink: props.shrink,
31
+ motionSurface: surface,
32
+ accessibilityHidden: true,
33
+ accessible: false,
34
+ isUserInteractionEnabled: false,
35
+ }),
36
+ )
37
+ },
38
+ })
@@ -20,6 +20,7 @@ import {
20
20
  buttonContent,
21
21
  ButtonAdornment,
22
22
  useMavisTheme,
23
+ useNavigationOptions,
23
24
  actionEmits,
24
25
  textContent,
25
26
  useLayoutShrink,
@@ -39,8 +40,11 @@ import { useMotionSurface } from '../use-motion-surface.js'
39
40
  import { usePressFeedback } from '../use-press.js'
40
41
  import { MavisButton } from '../../native/button'
41
42
  import { useNativeViewAttrs } from '../accessibility.js'
43
+ import { LoadingDecoration } from './LoadingDecoration.js'
44
+ import { ReorderHandle } from '@rafaelaugusto/jolt/reorder'
42
45
 
43
46
  registerElement('MavisButton', () => MavisButton)
47
+ registerElement('MavisReorderHandle', () => ReorderHandle)
44
48
 
45
49
  export const MButton = defineComponent({
46
50
  name: 'MButton',
@@ -55,6 +59,7 @@ export const MButton = defineComponent({
55
59
  setup(props, { attrs, slots, emit }) {
56
60
  useButtonAction()
57
61
  const { theme } = useMavisTheme()
62
+ const navigation = useNavigationOptions(props)
58
63
  const nativeAttrs = useNativeViewAttrs(props)
59
64
  const shrink = useLayoutShrink()
60
65
  const enabled = () => !props.disabled && !props.loading
@@ -73,10 +78,22 @@ export const MButton = defineComponent({
73
78
  if (!enabled() || !allowsActivation()) return
74
79
  emit('click')
75
80
  if (props.href !== undefined)
76
- void navigateNative(props).catch((error) => emit('error', error))
81
+ void navigateNative(navigation()).catch((error) => emit('error', error))
77
82
  }
78
83
  return () => {
79
- if (props.href !== undefined) nativeDestination(props)
84
+ if (
85
+ props.reorderHandle &&
86
+ (slots.leading ||
87
+ slots.trailing ||
88
+ props.icon ||
89
+ props.trailingIcon ||
90
+ props.href ||
91
+ props.loadingIndicator !== 'none')
92
+ )
93
+ throw new TypeError(
94
+ 'A reorder handle requires a plain-text MButton without navigation or adornments.',
95
+ )
96
+ if (props.href !== undefined) nativeDestination(navigation())
80
97
  const { colors, control, radius } = theme.value
81
98
  const tokens = theme.value.components.button
82
99
  const family = fontFamily(
@@ -90,8 +107,12 @@ export const MButton = defineComponent({
90
107
  : (props.text ?? textContent(slots.default?.()))
91
108
  const leading = buttonContent(slots.leading?.())
92
109
  const trailing = buttonContent(slots.trailing?.())
110
+ const indicator = props.loading && props.loadingIndicator !== 'none' && !isAndroid
93
111
  const composed = Boolean(
94
- slots.leading || slots.trailing || (isAndroid && (props.icon || props.trailingIcon)),
112
+ slots.leading ||
113
+ slots.trailing ||
114
+ indicator ||
115
+ (isAndroid && (props.icon || props.trailingIcon)),
95
116
  )
96
117
  const hasIcon = Boolean(composed || props.icon || props.trailingIcon)
97
118
  checkIconOnly(text, hasIcon, props.accessibilityLabel)
@@ -187,6 +208,18 @@ export const MButton = defineComponent({
187
208
  { hidden: true },
188
209
  {
189
210
  default: () => [
211
+ ...(indicator
212
+ ? [
213
+ h(LoadingDecoration, {
214
+ kind: props.loadingIndicator as 'dots' | 'bars' | 'ring',
215
+ width: iconSize,
216
+ height: iconSize,
217
+ size: iconSize,
218
+ color: primary ? colors.onPrimary : colors.text,
219
+ radius: 'none',
220
+ }),
221
+ ]
222
+ : []),
190
223
  slots.leading
191
224
  ? adornment(leading)
192
225
  : props.icon
@@ -218,7 +251,7 @@ export const MButton = defineComponent({
218
251
  )
219
252
  }
220
253
  return h(
221
- 'MavisButton',
254
+ props.reorderHandle ? 'MavisReorderHandle' : 'MavisButton',
222
255
  mergeProps(
223
256
  {
224
257
  // Android builds the accessible description from the current text.
@@ -6,6 +6,7 @@ import {
6
6
  useButtonAction,
7
7
  cardProps,
8
8
  useMavisTheme,
9
+ useNavigationOptions,
9
10
  actionEmits,
10
11
  } from '@getcortexlabs/mavis-core/vue'
11
12
  import { MColumn } from './layout.js'
@@ -20,6 +21,7 @@ export const MCard = defineComponent({
20
21
  setup(props, { attrs, slots, emit }) {
21
22
  useButtonAction(() => props.interactive || props.href !== undefined)
22
23
  const { theme } = useMavisTheme()
24
+ const navigation = useNavigationOptions(props)
23
25
  const enabled = () => (props.interactive || props.href !== undefined) && !props.disabled
24
26
  const lifecycle = usePressFeedback(enabled, theme)
25
27
  const { allowsActivation, ...surface } = useMotionSurface(
@@ -39,7 +41,7 @@ export const MCard = defineComponent({
39
41
  ...layout
40
42
  } = props
41
43
  const interactive = action || href !== undefined
42
- if (href !== undefined) nativeDestination(props)
44
+ if (href !== undefined) nativeDestination(navigation())
43
45
  const tokens = theme.value.components.card
44
46
  layout.padding ??= tokens.padding
45
47
  layout.radius ??= tokens.radius
@@ -71,7 +73,7 @@ export const MCard = defineComponent({
71
73
  if (enabled() && allowsActivation()) {
72
74
  emit('click')
73
75
  if (href !== undefined)
74
- void navigateNative(props).catch((error) => emit('error', error))
76
+ void navigateNative(navigation()).catch((error) => emit('error', error))
75
77
  }
76
78
  }
77
79
  : undefined,
@@ -1,15 +1,13 @@
1
- import { Utils, isAndroid, type View } from '@nativescript/core'
1
+ import { Utils } from '@nativescript/core'
2
2
  import { createDatePickers } from '@getcortexlabs/mavis-core/vue'
3
3
  import { MInput } from './MInput.js'
4
4
  import { MButton } from './MButton.js'
5
5
  import { MColumn, MRow } from './layout.js'
6
6
  import { MSheet } from './MSheet.js'
7
7
  import { DateCalendar } from './DateCalendar.js'
8
- import { notifyAccessibilityLayout } from '../../native/accessibility-layout'
9
8
 
10
9
  function focusOpener(opener: unknown) {
11
- const view = (opener as { $el?: { nativeView?: View } } | undefined)?.$el?.nativeView
12
- view?.focus()
10
+ ;(opener as { focusAction?: () => void } | undefined)?.focusAction?.()
13
11
  }
14
12
 
15
13
  export const { MDatePicker, MDateRangePicker } = createDatePickers({
@@ -23,11 +21,5 @@ export const { MDatePicker, MDateRangePicker } = createDatePickers({
23
21
  Utils.dismissKeyboard()
24
22
  focusOpener(opener)
25
23
  },
26
- afterClose: (opener) => {
27
- const view = (opener as { $el?: { nativeView?: View } } | undefined)?.$el?.nativeView
28
- if (!view?.isLoaded) return
29
- view.focus()
30
- if (isAndroid) view.android.performAccessibilityAction(64, null)
31
- else notifyAccessibilityLayout(view)
32
- },
24
+ afterClose: focusOpener,
33
25
  })
@@ -0,0 +1,86 @@
1
+ import {
2
+ Comment,
3
+ Fragment,
4
+ Text,
5
+ createVNode,
6
+ defineComponent,
7
+ h,
8
+ mergeProps,
9
+ provide,
10
+ shallowRef,
11
+ type VNode,
12
+ } from 'nativescript-vue'
13
+ import type { EventData, View } from '@nativescript/core'
14
+ import { gridColumns, resolveSpace } from '@getcortexlabs/mavis-core'
15
+ import {
16
+ gridProps,
17
+ layoutDirection,
18
+ useLayoutShrink,
19
+ useMavisTheme,
20
+ } from '@getcortexlabs/mavis-core/vue'
21
+ import { boxStyle } from '../props.js'
22
+ import { useNativeViewAttrs } from '../accessibility.js'
23
+ import './layout.js'
24
+
25
+ export const MGrid = defineComponent({
26
+ name: 'MGrid',
27
+ inheritAttrs: false,
28
+ props: gridProps,
29
+ setup(props, { attrs, slots }) {
30
+ const { theme } = useMavisTheme()
31
+ const shrink = useLayoutShrink()
32
+ const nativeAttrs = useNativeViewAttrs(props)
33
+ provide(layoutDirection, 'column')
34
+ const width = shallowRef<number>()
35
+ return () => {
36
+ const gap = resolveSpace(theme.value, props.gap ?? 'none')
37
+ const count = gridColumns(props.columns, props.minColumnWidth, gap, width.value)
38
+ let index = 0
39
+ // Keep fragment boundaries so independently keyed slot groups retain their identity.
40
+ const place = (nodes: VNode[]): VNode[] =>
41
+ nodes.flatMap((child) => {
42
+ if (child.type === Fragment)
43
+ return [
44
+ createVNode(
45
+ Fragment,
46
+ { key: child.key ?? undefined },
47
+ place(child.children as VNode[]),
48
+ ),
49
+ ]
50
+ if (child.type === Comment || (child.type === Text && !String(child.children).trim()))
51
+ return []
52
+ const cell = index++
53
+ return [
54
+ h(
55
+ 'MavisBox',
56
+ {
57
+ key: child.key ?? cell,
58
+ col: (cell % count) * 2,
59
+ row: Math.floor(cell / count) * 2,
60
+ },
61
+ [child],
62
+ ),
63
+ ]
64
+ })
65
+ const children = place(slots.default?.() ?? [])
66
+ const rows = Math.ceil(index / count)
67
+ return h(
68
+ 'MavisBox',
69
+ mergeProps({ style: boxStyle(theme.value, props, shrink.value) }, nativeAttrs(), attrs),
70
+ [
71
+ h(
72
+ 'GridLayout',
73
+ {
74
+ columns: Array.from({ length: count }, () => '*').join(`,${gap},`),
75
+ rows: Array.from({ length: rows }, () => 'auto').join(`,${gap},`),
76
+ onLayoutChanged: (event: EventData) => {
77
+ width.value = (event.object as View).getActualSize().width
78
+ },
79
+ },
80
+ children,
81
+ ),
82
+ ],
83
+ )
84
+ }
85
+ },
86
+ })
@@ -2,6 +2,8 @@ import { defineComponent, h, mergeProps, registerElement } from 'nativescript-vu
2
2
  import { iconProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
3
3
  import { iconFontFamily, iconGlyph, resolveIconSize } from '@getcortexlabs/mavis-core'
4
4
  import { MavisLabel } from '../../native/label'
5
+ import { isIOS } from '@nativescript/core'
6
+ import { useMotionSurface } from '../use-motion-surface.js'
5
7
 
6
8
  registerElement('MavisIcon', () => MavisLabel)
7
9
 
@@ -11,14 +13,24 @@ export const MIcon = defineComponent({
11
13
  props: iconProps,
12
14
  setup(props, { attrs }) {
13
15
  const { theme } = useMavisTheme()
16
+ const motion = useMotionSurface(() => props.motionSurface)
14
17
  return () => {
15
18
  const size = resolveIconSize(props.size)
16
19
  return h(
17
- 'MavisIcon',
20
+ props.systemName && isIOS ? 'Image' : 'MavisIcon',
18
21
  mergeProps(
22
+ { onLoaded: motion.onLoaded, onUnloaded: motion.onUnloaded },
19
23
  {
20
24
  id: props.id,
21
- text: iconGlyph(props.name),
25
+ key: props.systemName && isIOS ? props.systemName : 'glyph',
26
+ ...(props.systemName && isIOS
27
+ ? {
28
+ src: `sys://${props.systemName}`,
29
+ width: size,
30
+ height: size,
31
+ tintColor: theme.value.colors[props.tone],
32
+ }
33
+ : { text: iconGlyph(props.name) }),
22
34
  textWrap: false,
23
35
  accessible: Boolean(props.label),
24
36
  accessibilityHidden: !props.label,
@@ -2,23 +2,30 @@ import {
2
2
  defineComponent,
3
3
  h,
4
4
  mergeProps,
5
+ nextTick,
5
6
  onBeforeUnmount,
6
7
  ref,
7
8
  shallowRef,
8
9
  watch,
9
10
  } from 'nativescript-vue'
10
- import type { EventData, View, ImageSource } from '@nativescript/core'
11
+ import type { EventData, View, ImageSource, Image } from '@nativescript/core'
11
12
  import { imageProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
12
13
  import { resolveRadius } from '@getcortexlabs/mavis-core'
13
14
  import { loadAvatarImage } from '../../native/avatar-image'
14
15
  import { MBox } from './layout.js'
15
16
  import { MText } from './MText.js'
17
+ import { useMotionSurface } from '../use-motion-surface.js'
18
+ import { registerMotionImage } from '../../native/image-effects.js'
16
19
 
17
20
  export const MImage = defineComponent({
18
21
  name: 'MImage',
19
22
  inheritAttrs: false,
20
23
  props: imageProps,
21
- emits: { load: (_src: string) => true, error: (_src: string) => true },
24
+ emits: {
25
+ load: (_src: string) => true,
26
+ error: (_src: string) => true,
27
+ 'update:src': (_src: string) => true,
28
+ },
22
29
  setup(props, { attrs, emit }) {
23
30
  const { theme } = useMavisTheme()
24
31
  const image = shallowRef<ImageSource | null>(null)
@@ -26,6 +33,15 @@ export const MImage = defineComponent({
26
33
  const width = ref(typeof props.width === 'number' ? props.width : 0)
27
34
  let generation = 0,
28
35
  loaded = false
36
+ let releaseImage: (() => void) | undefined,
37
+ committing: string | undefined,
38
+ currentImage: Image | undefined
39
+ const motion = useMotionSurface(
40
+ () => props.motionSurface,
41
+ () => true,
42
+ () => false,
43
+ true,
44
+ )
29
45
  async function load() {
30
46
  const current = ++generation,
31
47
  src = props.src
@@ -47,6 +63,10 @@ export const MImage = defineComponent({
47
63
  }
48
64
  }
49
65
  function unload() {
66
+ motion.onUnloaded()
67
+ releaseImage?.()
68
+ releaseImage = undefined
69
+ currentImage = undefined
50
70
  loaded = false
51
71
  generation++
52
72
  image.value = null
@@ -54,8 +74,13 @@ export const MImage = defineComponent({
54
74
  watch(
55
75
  () => props.src,
56
76
  () => {
77
+ if (props.src === committing) {
78
+ committing = undefined
79
+ return
80
+ }
57
81
  void load()
58
82
  },
83
+ { flush: 'sync' },
59
84
  )
60
85
  onBeforeUnmount(unload)
61
86
  return () => {
@@ -66,6 +91,7 @@ export const MImage = defineComponent({
66
91
  MBox,
67
92
  mergeProps(attrs, {
68
93
  ...props,
94
+ motionSurface: undefined,
69
95
  width: props.width ?? '100%',
70
96
  height: props.height ?? width.value / props.aspectRatio,
71
97
  backgroundColor: props.backgroundColor || theme.value.colors.elevated,
@@ -93,6 +119,7 @@ export const MImage = defineComponent({
93
119
  image.value
94
120
  ? [
95
121
  h('Image', {
122
+ key: generation,
96
123
  imageSource: image.value,
97
124
  width: '100%',
98
125
  height: '100%',
@@ -100,6 +127,43 @@ export const MImage = defineComponent({
100
127
  borderRadius: radius,
101
128
  accessible: false,
102
129
  accessibilityHidden: true,
130
+ onLoaded(event: EventData) {
131
+ const target = event.object as Image,
132
+ current = generation
133
+ currentImage = target
134
+ releaseImage?.()
135
+ releaseImage = registerMotionImage(target, {
136
+ current: () =>
137
+ loaded &&
138
+ current === generation &&
139
+ currentImage === target &&
140
+ target.isLoaded,
141
+ async commit(destination, prepared) {
142
+ if (!loaded || current !== generation) return false
143
+ const previous = image.value
144
+ image.value = prepared ?? null
145
+ committing = destination
146
+ emit('update:src', destination)
147
+ await nextTick()
148
+ const accepted =
149
+ loaded && current === generation && props.src === destination
150
+ committing = undefined
151
+ if (!accepted && current === generation) {
152
+ image.value = previous
153
+ if (previous) target.imageSource = previous
154
+ }
155
+ return accepted
156
+ },
157
+ })
158
+ motion.onLoaded(event)
159
+ },
160
+ onUnloaded(event: EventData) {
161
+ if (event.object !== currentImage) return
162
+ motion.onUnloaded()
163
+ releaseImage?.()
164
+ releaseImage = undefined
165
+ currentImage = undefined
166
+ },
103
167
  }),
104
168
  ]
105
169
  : [
@@ -25,7 +25,7 @@ import {
25
25
  resolveDimension,
26
26
  iconSizes,
27
27
  inputActionSize,
28
- type InputHandle,
28
+ type InputActionHandle,
29
29
  } from '@getcortexlabs/mavis-core'
30
30
  import { isAndroid } from '@nativescript/core'
31
31
  import type { EventData, PropertyChangeData, TextField, TextView, View } from '@nativescript/core'
@@ -36,6 +36,7 @@ import { MIcon } from './MIcon.js'
36
36
  import { MButton } from './MButton.js'
37
37
  import { keepEditingOn } from '../../native/input-action'
38
38
  import { useNativeViewAttrs } from '../accessibility.js'
39
+ import { notifyAccessibilityLayout } from '../../native/accessibility-layout'
39
40
 
40
41
  registerElement('MavisTextField', () => MavisTextField)
41
42
  registerElement('MavisTextView', () => MavisTextView)
@@ -52,6 +53,7 @@ const Input = defineComponent({
52
53
  provide(layoutDirection, 'column')
53
54
  const nativeAttrs = useNativeViewAttrs(props)
54
55
  const editor = shallowRef<{ nativeView: TextField | TextView }>()
56
+ const actionButton = shallowRef<{ $el?: { nativeView?: View } }>()
55
57
  const focused = ref(false)
56
58
  let focusFeedback: ReturnType<typeof setTimeout> | undefined
57
59
  function cancelFocusFeedback() {
@@ -79,11 +81,19 @@ const Input = defineComponent({
79
81
  },
80
82
  )
81
83
  expose({
84
+ focusAction: () => {
85
+ if (props.disabled || props.readonly || props.trailingAction?.disabled) return
86
+ const view = actionButton.value?.$el?.nativeView
87
+ if (!view?.isLoaded) return
88
+ view.focus()
89
+ if (isAndroid) view.android?.performAccessibilityAction(64, null)
90
+ else notifyAccessibilityLayout(view)
91
+ },
82
92
  focus: () => {
83
93
  if (!props.disabled && !props.readonly) editor.value?.nativeView.focus()
84
94
  },
85
95
  blur,
86
- } satisfies InputHandle)
96
+ } satisfies InputActionHandle)
87
97
 
88
98
  return () => {
89
99
  validateInput(props)
@@ -238,6 +248,7 @@ const Input = defineComponent({
238
248
  icon(props.trailingIcon, true),
239
249
  action
240
250
  ? h(MButton, {
251
+ ref: actionButton,
241
252
  row: 1,
242
253
  icon: action.icon,
243
254
  accessibilityLabel: action.label,
@@ -282,5 +293,5 @@ const Input = defineComponent({
282
293
 
283
294
  // Keep the constructor declaration aligned with the portable handle exposed above.
284
295
  export const MInput = Input as typeof Input & {
285
- new (): InstanceType<typeof Input> & InputHandle
296
+ new (): InstanceType<typeof Input> & InputActionHandle
286
297
  }