@getcortexlabs/mavis 0.1.0-alpha.5 → 0.1.0-alpha.6

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 (106) hide show
  1. package/README.md +5 -7
  2. package/dist/app-icons.d.ts +26 -0
  3. package/dist/app-icons.d.ts.map +1 -0
  4. package/dist/app-icons.js +9 -0
  5. package/dist/app-icons.js.map +1 -0
  6. package/dist/native/app-icons.android.d.ts +4 -0
  7. package/dist/native/app-icons.android.d.ts.map +1 -0
  8. package/dist/native/app-icons.android.js +67 -0
  9. package/dist/native/app-icons.android.js.map +1 -0
  10. package/dist/native/app-icons.d.ts +4 -0
  11. package/dist/native/app-icons.d.ts.map +1 -0
  12. package/dist/native/app-icons.ios.d.ts +4 -0
  13. package/dist/native/app-icons.ios.d.ts.map +1 -0
  14. package/dist/native/app-icons.ios.js +45 -0
  15. package/dist/native/app-icons.ios.js.map +1 -0
  16. package/dist/native/app-icons.js +9 -0
  17. package/dist/native/app-icons.js.map +1 -0
  18. package/dist/native/motion-owner.d.ts.map +1 -1
  19. package/dist/native/motion-owner.js +4 -0
  20. package/dist/native/motion-owner.js.map +1 -1
  21. package/dist/native/motion-region.d.ts.map +1 -1
  22. package/dist/native/motion-region.js +39 -1
  23. package/dist/native/motion-region.js.map +1 -1
  24. package/dist/native/motion-surface.d.ts +1 -1
  25. package/dist/native/motion-surface.d.ts.map +1 -1
  26. package/dist/native/motion-surface.js +25 -2
  27. package/dist/native/motion-surface.js.map +1 -1
  28. package/dist/native/press.d.ts +3 -2
  29. package/dist/native/press.d.ts.map +1 -1
  30. package/dist/native/press.js.map +1 -1
  31. package/dist/vue/components/MAlert.d.ts +1 -1
  32. package/dist/vue/components/MBadge.d.ts +1 -1
  33. package/dist/vue/components/MButton.d.ts +50 -4
  34. package/dist/vue/components/MButton.d.ts.map +1 -1
  35. package/dist/vue/components/MButton.js +20 -13
  36. package/dist/vue/components/MButton.js.map +1 -1
  37. package/dist/vue/components/MCard.d.ts +49 -3
  38. package/dist/vue/components/MCard.d.ts.map +1 -1
  39. package/dist/vue/components/MCard.js +12 -5
  40. package/dist/vue/components/MCard.js.map +1 -1
  41. package/dist/vue/components/MChip.d.ts +2 -2
  42. package/dist/vue/components/MDatePicker.d.ts +56 -8
  43. package/dist/vue/components/MDatePicker.d.ts.map +1 -1
  44. package/dist/vue/components/MEmptyState.d.ts +2 -2
  45. package/dist/vue/components/MIcon.d.ts +1 -1
  46. package/dist/vue/components/MInput.d.ts +3 -3
  47. package/dist/vue/components/MInput.js +3 -3
  48. package/dist/vue/components/MInput.js.map +1 -1
  49. package/dist/vue/components/MLink.d.ts +120 -0
  50. package/dist/vue/components/MLink.d.ts.map +1 -0
  51. package/dist/vue/components/MLink.js +81 -0
  52. package/dist/vue/components/MLink.js.map +1 -0
  53. package/dist/vue/components/MListItem.d.ts +2 -0
  54. package/dist/vue/components/MListItem.d.ts.map +1 -1
  55. package/dist/vue/components/MProgress.d.ts +1 -1
  56. package/dist/vue/components/MReveal.d.ts +5 -5
  57. package/dist/vue/components/MReveal.d.ts.map +1 -1
  58. package/dist/vue/components/MReveal.js +80 -35
  59. package/dist/vue/components/MReveal.js.map +1 -1
  60. package/dist/vue/components/MSheet.d.ts +1 -1
  61. package/dist/vue/components/MSkeleton.d.ts +1 -1
  62. package/dist/vue/components/MStack.d.ts +199 -0
  63. package/dist/vue/components/MStack.d.ts.map +1 -0
  64. package/dist/vue/components/MStack.js +62 -0
  65. package/dist/vue/components/MStack.js.map +1 -0
  66. package/dist/vue/components/MText.d.ts +4 -4
  67. package/dist/vue/components/MText.js +3 -3
  68. package/dist/vue/components/MText.js.map +1 -1
  69. package/dist/vue/components/layout.d.ts +11 -11
  70. package/dist/vue/components/layout.d.ts.map +1 -1
  71. package/dist/vue/components/layout.js +5 -5
  72. package/dist/vue/components/layout.js.map +1 -1
  73. package/dist/vue/index.d.ts +3 -1
  74. package/dist/vue/index.d.ts.map +1 -1
  75. package/dist/vue/index.js +5 -1
  76. package/dist/vue/index.js.map +1 -1
  77. package/dist/vue/navigation.d.ts +4 -0
  78. package/dist/vue/navigation.d.ts.map +1 -0
  79. package/dist/vue/navigation.js +16 -0
  80. package/dist/vue/navigation.js.map +1 -0
  81. package/dist/vue/reveal-motion.d.ts.map +1 -1
  82. package/dist/vue/reveal-motion.js +6 -3
  83. package/dist/vue/reveal-motion.js.map +1 -1
  84. package/dist/vue/use-press.js +3 -3
  85. package/dist/vue/use-press.js.map +1 -1
  86. package/package.json +7 -3
  87. package/src/app-icons.ts +21 -0
  88. package/src/native/app-icons.android.ts +95 -0
  89. package/src/native/app-icons.ios.ts +74 -0
  90. package/src/native/app-icons.ts +12 -0
  91. package/src/native/motion-owner.ts +6 -0
  92. package/src/native/motion-region.ts +63 -1
  93. package/src/native/motion-surface.ts +29 -1
  94. package/src/native/press.ts +3 -3
  95. package/src/vue/components/MButton.ts +20 -10
  96. package/src/vue/components/MCard.ts +22 -5
  97. package/src/vue/components/MInput.ts +3 -3
  98. package/src/vue/components/MLink.ts +96 -0
  99. package/src/vue/components/MReveal.ts +89 -47
  100. package/src/vue/components/MStack.ts +83 -0
  101. package/src/vue/components/MText.ts +3 -3
  102. package/src/vue/components/layout.ts +10 -5
  103. package/src/vue/index.ts +6 -0
  104. package/src/vue/navigation.ts +15 -0
  105. package/src/vue/use-press.ts +3 -3
  106. package/src/vue/reveal-motion.ts +0 -61
@@ -0,0 +1,96 @@
1
+ import { defineComponent, h, mergeProps, onBeforeUnmount, ref } from 'nativescript-vue'
2
+ import { Utils, type EventData, type View } from '@nativescript/core'
3
+ import { linkDestination } from '@getcortexlabs/mavis-core'
4
+ import { linkProps, linkEmits, textContent, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
5
+ import { MRow } from './layout.js'
6
+ import { MText } from './MText.js'
7
+ import { ActionChildren, useNativeViewAttrs } from '../accessibility.js'
8
+ import { observeComposedButton } from '../../native/composed-button'
9
+
10
+ export const MLink = defineComponent({
11
+ name: 'MLink',
12
+ inheritAttrs: false,
13
+ props: linkProps,
14
+ emits: linkEmits,
15
+ setup(props, { attrs, slots, emit }) {
16
+ const { theme } = useMavisTheme()
17
+ const nativeAttrs = useNativeViewAttrs(props)
18
+ const focused = ref(false)
19
+ let release: (() => void) | undefined
20
+ const clear = () => {
21
+ release?.()
22
+ release = undefined
23
+ focused.value = false
24
+ }
25
+ onBeforeUnmount(clear)
26
+ const activate = async () => {
27
+ if (props.disabled) return
28
+ const href = linkDestination(props.href)
29
+ emit('click')
30
+ try {
31
+ if (props.navigate) await props.navigate(href)
32
+ else if (!(await Utils.openUrl(href))) throw new Error(`The system could not open ${href}.`)
33
+ } catch (error) {
34
+ emit('error', error)
35
+ }
36
+ }
37
+ return () => {
38
+ const href = linkDestination(props.href)
39
+ if (!props.navigate && !/^[a-z][a-z\d+.-]*:/i.test(href))
40
+ throw new TypeError('Native MLink needs a navigate handler for in-app destinations.')
41
+ const text = props.text ?? textContent(slots.default?.())
42
+ const label = props.accessibilityLabel ?? text
43
+ if (!label.trim()) throw new TypeError('MLink requires a name.')
44
+ return h(
45
+ MRow,
46
+ mergeProps(
47
+ {
48
+ align: 'center',
49
+ justify: 'center',
50
+ grow: props.grow,
51
+ shrink: props.shrink,
52
+ style: {
53
+ minHeight: props.inline ? 0 : 44,
54
+ opacity: props.disabled ? 0.45 : 1,
55
+ borderWidth: focused.value ? 1 : 0,
56
+ borderColor: theme.value.colors.primary,
57
+ },
58
+ },
59
+ nativeAttrs(),
60
+ attrs,
61
+ {
62
+ accessible: true,
63
+ accessibilityRole: 'link',
64
+ accessibilityLabel: label,
65
+ accessibilityState: props.disabled ? 'disabled' : '',
66
+ isEnabled: !props.disabled,
67
+ onTap: activate,
68
+ onLoaded(event: EventData) {
69
+ clear()
70
+ release = observeComposedButton(
71
+ event.object as View,
72
+ (value) => {
73
+ focused.value = value
74
+ },
75
+ activate,
76
+ () => {},
77
+ )
78
+ },
79
+ onUnloaded: clear,
80
+ },
81
+ ),
82
+ {
83
+ default: () =>
84
+ h(
85
+ ActionChildren,
86
+ { hidden: true },
87
+ {
88
+ default: () =>
89
+ h(MText, { text, tone: 'primary', style: { textDecoration: 'underline' } }),
90
+ },
91
+ ),
92
+ },
93
+ )
94
+ }
95
+ },
96
+ })
@@ -1,8 +1,9 @@
1
- import { defineComponent, h, mergeProps, BaseTransition } from 'nativescript-vue'
2
- import { useRevealMotion } from '../reveal-motion.js'
3
- import { revealProps } from '@getcortexlabs/mavis-core/vue'
4
- import { MColumn } from './layout.js'
5
- import { isAndroid, type View } from '@nativescript/core'
1
+ import { defineComponent, h, mergeProps } from 'nativescript-vue'
2
+ import { animate, animateSize } from '@rafaelaugusto/jolt'
3
+ import { motionRecipe } from '@getcortexlabs/mavis-core'
4
+ import { revealProps, useMavisTheme, useRevealState } from '@getcortexlabs/mavis-core/vue'
5
+ import { MColumn, MBox } from './layout.js'
6
+ import { isAndroid, type EventData, type View } from '@nativescript/core'
6
7
  import { focusedView } from '../accessibility.js'
7
8
  import { notifyAccessibilityLayout } from '../../native/accessibility-layout'
8
9
 
@@ -11,51 +12,92 @@ export const MReveal = defineComponent({
11
12
  inheritAttrs: false,
12
13
  props: revealProps,
13
14
  setup(props, { attrs, slots }) {
14
- const motion = useRevealMotion()
15
+ const { theme } = useMavisTheme()
16
+ const state = useRevealState(() => props.show)
15
17
  let trigger: WeakRef<View> | undefined
16
- let restore = false
17
- return () => {
18
- const { show, ...layout } = props
19
- return h(
20
- BaseTransition,
21
- {
22
- ...motion,
23
- onBeforeEnter: (element: { nativeView?: View }) => {
24
- if (element.nativeView)
25
- element.nativeView.accessibilityHidden = Boolean(props.accessibilityHidden)
26
-
27
- const page = element.nativeView?.page
28
- const focused = page && focusedView(page)
29
- trigger = focused ? new WeakRef(focused) : undefined
30
- restore = false
31
- },
32
- onAfterEnter: (element: { nativeView?: View }) => {
33
- const page = element.nativeView?.page
34
- notifyAccessibilityLayout(page ? focusedView(page) : undefined)
35
- },
36
- onBeforeLeave: (element: { nativeView?: View }) => {
37
- const view = element.nativeView
38
- if (!view?.page) return
39
- let focused = focusedView(view.page)
40
- while (focused && focused !== view) focused = focused.parent as View | undefined
41
- restore = focused === view
42
- view.accessibilityHidden = true
43
- },
44
- onAfterLeave: () => {
45
- const target = trigger?.deref()
46
- if (restore && target?.isLoaded) {
47
- if (isAndroid) target.android.performAccessibilityAction(64, null)
48
- else notifyAccessibilityLayout(target)
49
- }
50
- trigger = undefined
51
- restore = false
52
- },
18
+ function activeView(root: View): View | undefined {
19
+ if (
20
+ isAndroid
21
+ ? root.android?.hasFocus?.() && !root.android?.getFocusedChild?.()
22
+ : root.ios?.isFirstResponder
23
+ )
24
+ return root
25
+ let found: View | undefined
26
+ root.eachChildView((child) => {
27
+ found = activeView(child)
28
+ return !found
29
+ })
30
+ return found
31
+ }
32
+ function currentFocus(view: View) {
33
+ return view.page && (activeView(view.page) ?? focusedView(view.page))
34
+ }
35
+ function attach(view: View) {
36
+ const focusability = isAndroid ? view.android.getDescendantFocusability() : undefined
37
+ return state.attach({
38
+ animate(open, fromClosed) {
39
+ if (fromClosed) {
40
+ view.height = 0
41
+ view.opacity = 0
42
+ }
43
+ const recipe = motionRecipe(theme.value, open ? 'enter' : 'exit')
44
+ const size = animateSize(view, { height: open ? 'auto' : 0 }, recipe.transition)
45
+ const opacity = animate(view, { opacity: open ? 1 : 0 }, recipe.transition)
46
+ return {
47
+ finished: size.finished,
48
+ stop() {
49
+ size.stop({ restore: true })
50
+ opacity.stop()
51
+ },
52
+ }
53
53
  },
54
- {
55
- default: () =>
56
- show ? h(MColumn, mergeProps(layout, attrs, { key: 'content' }), slots) : null,
54
+ interactive(enabled) {
55
+ view.accessibilityHidden = !enabled || Boolean(props.accessibilityHidden)
56
+ view.isUserInteractionEnabled = enabled
57
+ if (isAndroid) view.android.setDescendantFocusability(enabled ? focusability : 393216)
57
58
  },
58
- )
59
+ captureFocus() {
60
+ const active = currentFocus(view)
61
+ let ancestor = active
62
+ while (ancestor && ancestor !== view) ancestor = ancestor.parent as View | undefined
63
+ if (active && !ancestor) trigger = new WeakRef(active)
64
+ },
65
+ restoreFocus() {
66
+ const focused = currentFocus(view)
67
+ let active = focused
68
+ while (active && active !== view) active = active.parent as View | undefined
69
+ const target = trigger?.deref()
70
+ if (active === view && target?.isLoaded) {
71
+ ;(focused as View & { dismissSoftInput?(): void })?.dismissSoftInput?.()
72
+ target.focus()
73
+ if (isAndroid) target.android.performAccessibilityAction(64, null)
74
+ else notifyAccessibilityLayout(target)
75
+ }
76
+ },
77
+ release() {
78
+ view.height = 'auto'
79
+ view.opacity = 1
80
+ if (isAndroid && view.android) view.android.setDescendantFocusability(focusability)
81
+ },
82
+ })
83
+ }
84
+ return () => {
85
+ const { show, grow, shrink, width, id, ...content } = props
86
+ return state.present.value
87
+ ? h(MBox, mergeProps({ grow, shrink, width, id }, attrs), {
88
+ default: () =>
89
+ h(
90
+ MBox,
91
+ {
92
+ clipToBounds: true,
93
+ accessibilityHidden: !show || props.accessibilityHidden,
94
+ onLoaded: (event: EventData) => attach(event.object as View),
95
+ onUnloaded: state.detach,
96
+ },
97
+ { default: () => h(MColumn, content, slots) },
98
+ ),
99
+ })
100
+ : null
59
101
  }
60
102
  },
61
103
  })
@@ -0,0 +1,83 @@
1
+ import { computed, defineComponent, h, mergeProps, provide, shallowRef } from 'nativescript-vue'
2
+ import type { EventData, View } from '@nativescript/core'
3
+ import { resolveSpace, stackLayout } from '@getcortexlabs/mavis-core'
4
+ import {
5
+ stackProps,
6
+ layoutDirection,
7
+ useLayoutShrink,
8
+ useMavisTheme,
9
+ } from '@getcortexlabs/mavis-core/vue'
10
+ import { boxStyle } from '../props.js'
11
+ import { useNativeViewAttrs } from '../accessibility.js'
12
+ import './layout.js'
13
+
14
+ const align = {
15
+ start: 'flex-start',
16
+ end: 'flex-end',
17
+ center: 'center',
18
+ stretch: 'stretch',
19
+ } as const
20
+ const justify = {
21
+ start: 'flex-start',
22
+ end: 'flex-end',
23
+ center: 'center',
24
+ between: 'space-between',
25
+ around: 'space-around',
26
+ } as const
27
+
28
+ export const MStack = defineComponent({
29
+ name: 'MStack',
30
+ inheritAttrs: false,
31
+ props: stackProps,
32
+ setup(props, { attrs, slots }) {
33
+ const { theme } = useMavisTheme()
34
+ const nativeAttrs = useNativeViewAttrs(props)
35
+ const shrink = useLayoutShrink()
36
+ const width = shallowRef<number>()
37
+ const layout = computed(() =>
38
+ stackLayout(
39
+ {
40
+ direction: props.direction,
41
+ gap: props.gap,
42
+ align: props.align,
43
+ justify: props.justify,
44
+ wrap: props.wrap,
45
+ },
46
+ props.responsive,
47
+ width.value,
48
+ ),
49
+ )
50
+ const direction = computed(() => layout.value.direction ?? props.direction)
51
+ provide(layoutDirection, direction)
52
+ const measure = (event: EventData) => {
53
+ const view = event.object as View
54
+ const size = view.getActualSize().width
55
+ // The inner layout occupies the outer Box's content area, after padding.
56
+ if (size > 0 && size !== width.value) width.value = size
57
+ }
58
+ return () =>
59
+ h(
60
+ 'MavisBox',
61
+ mergeProps({ style: boxStyle(theme.value, props, shrink.value) }, nativeAttrs(), attrs),
62
+ [
63
+ h(
64
+ 'MavisFlexLayout',
65
+ {
66
+ onLayoutChanged: measure,
67
+ onUnloaded: () => {
68
+ width.value = undefined
69
+ },
70
+ style: {
71
+ flexDirection: direction.value,
72
+ alignItems: align[layout.value.align ?? props.align],
73
+ justifyContent: justify[layout.value.justify ?? props.justify],
74
+ flexWrap: layout.value.wrap ? 'wrap' : 'nowrap',
75
+ gap: resolveSpace(theme.value, layout.value.gap ?? 'none'),
76
+ },
77
+ },
78
+ slots.default?.(),
79
+ ),
80
+ ],
81
+ )
82
+ },
83
+ })
@@ -3,7 +3,7 @@ import {
3
3
  textProps,
4
4
  useMavisTheme,
5
5
  inlineContent,
6
- useDefaultShrink,
6
+ useLayoutShrink,
7
7
  } from '@getcortexlabs/mavis-core/vue'
8
8
  import { fontFamily, nonNegative, validateWeight } from '@getcortexlabs/mavis-core'
9
9
  import { isAndroid } from '@nativescript/core'
@@ -19,7 +19,7 @@ export const MText = defineComponent({
19
19
  setup(props, { attrs, slots }) {
20
20
  const { theme } = useMavisTheme()
21
21
  const nativeAttrs = useNativeViewAttrs(props)
22
- const shrink = useDefaultShrink()
22
+ const shrink = useLayoutShrink()
23
23
  return () => {
24
24
  const type = theme.value.typography[props.variant]
25
25
  const runs =
@@ -46,7 +46,7 @@ export const MText = defineComponent({
46
46
  color: theme.value.colors[props.tone],
47
47
  textAlignment: props.align,
48
48
  flexGrow: nonNegative(props.grow, 'grow'),
49
- flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
49
+ flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
50
50
  minWidth: 0,
51
51
  },
52
52
  },
@@ -3,7 +3,7 @@ import {
3
3
  columnProps,
4
4
  useMavisTheme,
5
5
  layoutDirection,
6
- useDefaultShrink,
6
+ useLayoutShrink,
7
7
  motionBoxProps,
8
8
  } from '@getcortexlabs/mavis-core/vue'
9
9
  import { defineComponent, h, mergeProps, provide, registerElement } from 'nativescript-vue'
@@ -44,7 +44,7 @@ function createLayout(name: string, direction: 'row' | 'column') {
44
44
  setup(props, { attrs, slots }) {
45
45
  const { theme } = useMavisTheme()
46
46
  const nativeAttrs = useNativeViewAttrs(props)
47
- const shrink = useDefaultShrink()
47
+ const shrink = useLayoutShrink()
48
48
  provide(layoutDirection, direction)
49
49
  return () =>
50
50
  h(
@@ -52,7 +52,7 @@ function createLayout(name: string, direction: 'row' | 'column') {
52
52
  mergeProps(
53
53
  {
54
54
  style: {
55
- ...boxStyle(theme.value, props, shrink),
55
+ ...boxStyle(theme.value, props, shrink.value),
56
56
  flexDirection: direction,
57
57
  alignItems: alignment[props.align],
58
58
  justifyContent: distribution[props.justify],
@@ -81,11 +81,16 @@ export const MBox = defineComponent({
81
81
  const region = useMotionRegion(() => props.motionRegion)
82
82
  const { theme } = useMavisTheme()
83
83
  const nativeAttrs = useNativeViewAttrs(props)
84
- const shrink = useDefaultShrink()
84
+ const shrink = useLayoutShrink()
85
85
  return () =>
86
86
  h(
87
87
  'MavisBox',
88
- mergeProps({ style: boxStyle(theme.value, props, shrink) }, nativeAttrs(), attrs, region),
88
+ mergeProps(
89
+ { style: boxStyle(theme.value, props, shrink.value) },
90
+ nativeAttrs(),
91
+ attrs,
92
+ region,
93
+ ),
89
94
  slots.default?.(),
90
95
  )
91
96
  },
package/src/vue/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { MStack } from './components/MStack.js'
2
+ import { MLink } from './components/MLink.js'
1
3
  import { MDatePicker, MDateRangePicker } from './components/MDatePicker.js'
2
4
  import { MCombobox } from './components/MCombobox.js'
3
5
  import { MFilePicker } from './components/MFilePicker.js'
@@ -49,6 +51,8 @@ export {
49
51
  MBox,
50
52
  MRow,
51
53
  MColumn,
54
+ MStack,
55
+ MLink,
52
56
  MCard,
53
57
  MText,
54
58
  MButton,
@@ -125,6 +129,8 @@ export function createMavis(options: MavisOptions = {}) {
125
129
  MBox,
126
130
  MRow,
127
131
  MColumn,
132
+ MStack,
133
+ MLink,
128
134
  MCard,
129
135
  MText,
130
136
  MButton,
@@ -0,0 +1,15 @@
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
+ }
@@ -17,15 +17,15 @@ export function usePressFeedback(
17
17
  }
18
18
  const refresh = () => {
19
19
  if (view && enabled()) {
20
- if (remove) remove.update(theme.value.motion.pressScale)
21
- else remove = attachPressFeedback(view, theme.value.motion.pressScale)
20
+ if (remove) remove.update(theme.value.motion)
21
+ else remove = attachPressFeedback(view, theme.value.motion)
22
22
  } else release()
23
23
  }
24
24
  const unloaded = () => {
25
25
  release()
26
26
  view = undefined
27
27
  }
28
- watch([enabled, () => theme.value.motion.pressScale], refresh, { flush: 'post' })
28
+ watch([enabled, () => theme.value.motion], refresh, { flush: 'post' })
29
29
  if (keyboard) watch(keyboard, (pressed) => remove?.press(pressed), { flush: 'sync' })
30
30
  onBeforeUnmount(unloaded)
31
31
 
@@ -1,61 +0,0 @@
1
- import { onBeforeUnmount } from 'nativescript-vue'
2
- import type { View } from '@nativescript/core'
3
- import { animate, set, onReducedMotion } from '@rafaelaugusto/jolt'
4
- import { revealMotion } from '@getcortexlabs/mavis-core'
5
-
6
- type Element = { nativeView: View }
7
-
8
- /** Each transition owns its completion; an interrupted leave cannot finish a new entry. */
9
- export function useRevealMotion() {
10
- const entered = new WeakSet<View>()
11
- const active = new Map<
12
- View,
13
- { handle: ReturnType<typeof animate>; phase: 'enter' | 'leave'; remove: () => void }
14
- >()
15
- const cancel = ({ nativeView: view }: Element) => {
16
- const operation = active.get(view)
17
- if (!operation) return
18
- active.delete(view)
19
- operation.remove()
20
- operation.handle.stop()
21
- }
22
- const run = (phase: 'enter' | 'leave') => (element: Element, done: () => void) => {
23
- const view = element.nativeView
24
- cancel(element)
25
- if (phase === 'enter' && !entered.has(view)) {
26
- entered.add(view)
27
- set(view, { opacity: revealMotion.enter[0].opacity[0], y: revealMotion.enter[0].y[0] })
28
- }
29
- const handle = animate(
30
- view,
31
- phase === 'enter' ? { opacity: 1, y: 0 } : revealMotion.leave[0],
32
- revealMotion[phase][1],
33
- )
34
- const unloaded = () => cancel(element)
35
- const operation = { handle, phase, remove: () => view.off('unloaded', unloaded) }
36
- active.set(view, operation)
37
- view.on('unloaded', unloaded)
38
- void handle.finished.then(() => {
39
- if (active.get(view) !== operation) return
40
- active.delete(view)
41
- operation.remove()
42
- done()
43
- })
44
- }
45
- const offPreference = onReducedMotion((reduced) => {
46
- if (reduced)
47
- for (const [view, operation] of active) {
48
- if (operation.phase === 'enter') set(view, { y: 0 })
49
- }
50
- })
51
- onBeforeUnmount(() => {
52
- offPreference()
53
- for (const view of active.keys()) cancel({ nativeView: view })
54
- })
55
- return {
56
- onEnter: run('enter'),
57
- onLeave: run('leave'),
58
- onEnterCancelled: cancel,
59
- onLeaveCancelled: cancel,
60
- }
61
- }