@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
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@getcortexlabs/mavis",
3
- "version": "0.1.0-alpha.5",
3
+ "version": "0.1.0-alpha.6",
4
4
  "description": "Mavis UI foundations for NativeScript, with a Vue integration.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "exports": {
8
+ "./app-icons": {
9
+ "types": "./dist/app-icons.d.ts",
10
+ "default": "./dist/app-icons.js"
11
+ },
8
12
  ".": {
9
13
  "types": "./dist/index.d.ts",
10
14
  "default": "./dist/index.js"
@@ -28,7 +32,7 @@
28
32
  },
29
33
  "peerDependencies": {
30
34
  "@nativescript/core": "^9.1.3",
31
- "@rafaelaugusto/jolt": "^0.1.0-rc.7",
35
+ "@rafaelaugusto/jolt": "^0.1.0-rc.8",
32
36
  "nativescript-vue": "^3.1.3"
33
37
  },
34
38
  "peerDependenciesMeta": {
@@ -37,7 +41,7 @@
37
41
  }
38
42
  },
39
43
  "dependencies": {
40
- "@getcortexlabs/mavis-core": "0.1.0-alpha.5"
44
+ "@getcortexlabs/mavis-core": "0.1.0-alpha.6"
41
45
  },
42
46
  "nativescript": {
43
47
  "platforms": {
@@ -0,0 +1,21 @@
1
+ import { createAppIconController, type AppIconChoice } from '@getcortexlabs/mavis-core'
2
+ import { nativeAppIcons } from './native/app-icons'
3
+
4
+ export interface NativeAppIcon extends AppIconChoice {
5
+ /** null for the primary icon; alternate names must appear in CFBundleAlternateIcons. */
6
+ iosName: string | null
7
+ /** Fully qualified activity-alias name, including the primary launcher alias. */
8
+ androidAlias: string
9
+ }
10
+ export interface AppIconsOptions {
11
+ primary: string
12
+ icons: readonly NativeAppIcon[]
13
+ }
14
+
15
+ /** Optional integration: importing Mavis components never changes launcher configuration. */
16
+ export function createAppIcons(options: AppIconsOptions) {
17
+ const config = { primary: options.primary, icons: options.icons.map((icon) => ({ ...icon })) }
18
+ return createAppIconController(config.icons, config.primary, nativeAppIcons(config))
19
+ }
20
+ export { AppIconError } from '@getcortexlabs/mavis-core'
21
+ export type { AppIconController, AppIconChoice } from '@getcortexlabs/mavis-core'
@@ -0,0 +1,95 @@
1
+ import { Application } from '@nativescript/core'
2
+ import { SDK_VERSION } from '@nativescript/core/utils/constants'
3
+ import { AppIconError, type AppIconAdapter } from '@getcortexlabs/mavis-core'
4
+ import type { AppIconsOptions } from '../app-icons.js'
5
+
6
+ type Component = object
7
+ interface PackageManager {
8
+ getActivityInfo(
9
+ component: Component,
10
+ flags: number,
11
+ ): { enabled: boolean; targetActivity: string | null }
12
+ getComponentEnabledSetting(component: Component): number
13
+ setComponentEnabledSetting(component: Component, state: number, flags: number): void
14
+ setComponentEnabledSettings(settings: object): void
15
+ }
16
+ declare const android: {
17
+ content: {
18
+ ComponentName: new (context: object, name: string) => Component
19
+ pm: {
20
+ PackageManager: {
21
+ ComponentEnabledSetting: new (component: Component, state: number, flags: number) => object
22
+ }
23
+ }
24
+ }
25
+ }
26
+ declare const java: { util: { ArrayList: new () => { add(value: object): void } } }
27
+
28
+ export function nativeAppIcons(options: AppIconsOptions): AppIconAdapter {
29
+ const aliases = new Set<string>()
30
+ for (const icon of options.icons) {
31
+ if (!/^[\w]+(?:\.[\w$]+)+$/.test(icon.androidAlias) || aliases.has(icon.androidAlias))
32
+ throw new AppIconError(
33
+ 'configuration',
34
+ 'Android needs unique fully qualified activity-alias names.',
35
+ )
36
+ aliases.add(icon.androidAlias)
37
+ }
38
+ const runtime = () => {
39
+ const context = Application.android.context
40
+ const manager = context.getPackageManager() as PackageManager
41
+ const choices = options.icons.map((icon) => {
42
+ const component = new android.content.ComponentName(context, icon.androidAlias)
43
+ const info = manager.getActivityInfo(component, 512) // MATCH_DISABLED_COMPONENTS
44
+ if (!info.targetActivity)
45
+ throw new AppIconError('configuration', `${icon.androidAlias} must be an activity-alias.`)
46
+ const state = manager.getComponentEnabledSetting(component)
47
+ return { ...icon, component, state, enabled: state === 1 || (state === 0 && info.enabled) }
48
+ })
49
+ return { manager, choices }
50
+ }
51
+ return {
52
+ supported: () => Boolean(Application.android.context),
53
+ current() {
54
+ const enabled = runtime().choices.filter((icon) => icon.enabled)
55
+ return enabled.length === 1 ? enabled[0]!.id : undefined
56
+ },
57
+ async select(id) {
58
+ const { manager, choices } = runtime()
59
+ const next = choices.find((icon) => icon.id === id)!
60
+ try {
61
+ if (SDK_VERSION >= 33) {
62
+ const settings = new java.util.ArrayList()
63
+ for (const icon of choices)
64
+ settings.add(
65
+ new android.content.pm.PackageManager.ComponentEnabledSetting(
66
+ icon.component,
67
+ icon.id === id ? 1 : 2,
68
+ 1,
69
+ ),
70
+ )
71
+ manager.setComponentEnabledSettings(settings)
72
+ } else {
73
+ // Keep at least one launcher entry enabled throughout the non-atomic fallback.
74
+ manager.setComponentEnabledSetting(next.component, 1, 1) // ENABLED, DONT_KILL_APP
75
+ for (const icon of choices)
76
+ if (icon.id !== id) manager.setComponentEnabledSetting(icon.component, 2, 1)
77
+ }
78
+ } catch (cause) {
79
+ const rollback: unknown[] = []
80
+ for (const icon of [...choices].sort((a, b) => Number(b.enabled) - Number(a.enabled))) {
81
+ try {
82
+ manager.setComponentEnabledSetting(icon.component, icon.state, 1)
83
+ } catch (error) {
84
+ rollback.push(error)
85
+ }
86
+ }
87
+ throw new AppIconError('platform', 'Android could not update launcher aliases.', {
88
+ cause: rollback.length
89
+ ? new AggregateError([cause, ...rollback], 'Launcher rollback failed')
90
+ : cause,
91
+ })
92
+ }
93
+ },
94
+ }
95
+ }
@@ -0,0 +1,74 @@
1
+ import { Utils } from '@nativescript/core'
2
+ import { AppIconError, type AppIconAdapter } from '@getcortexlabs/mavis-core'
3
+ import type { AppIconsOptions } from '../app-icons.js'
4
+
5
+ declare const UIApplication: {
6
+ sharedApplication: {
7
+ supportsAlternateIcons: boolean
8
+ alternateIconName: string | null
9
+ setAlternateIconNameCompletionHandler(
10
+ name: string | null,
11
+ complete: (error: { localizedDescription: string } | null) => void,
12
+ ): void
13
+ }
14
+ }
15
+ interface Dictionary {
16
+ objectForKey(key: string): Dictionary | undefined
17
+ }
18
+ declare const NSBundle: {
19
+ mainBundle: { objectForInfoDictionaryKey(key: string): Dictionary | undefined }
20
+ }
21
+
22
+ export function nativeAppIcons(options: AppIconsOptions): AppIconAdapter {
23
+ const names = new Set<string | null>()
24
+ for (const icon of options.icons) {
25
+ if (
26
+ (icon.iosName !== null && typeof icon.iosName !== 'string') ||
27
+ (icon.id === options.primary) !== (icon.iosName === null) ||
28
+ names.has(icon.iosName) ||
29
+ icon.iosName === ''
30
+ )
31
+ throw new AppIconError(
32
+ 'configuration',
33
+ 'iOS needs one primary icon and unique alternate names.',
34
+ )
35
+ names.add(icon.iosName)
36
+ }
37
+ const application = () => UIApplication.sharedApplication
38
+ return {
39
+ supported: () => Boolean(application().supportsAlternateIcons),
40
+ current: () =>
41
+ options.icons.find((icon) => icon.iosName === (application().alternateIconName ?? null))?.id,
42
+ select(id) {
43
+ const icon = options.icons.find((choice) => choice.id === id)!
44
+ if (icon.iosName !== null) {
45
+ const declared = ['CFBundleIcons', 'CFBundleIcons~ipad'].some((key) =>
46
+ NSBundle.mainBundle
47
+ .objectForInfoDictionaryKey(key)
48
+ ?.objectForKey('CFBundleAlternateIcons')
49
+ ?.objectForKey(icon.iosName!),
50
+ )
51
+ if (!declared)
52
+ return Promise.reject(
53
+ new AppIconError('configuration', `Missing bundled alternate icon: ${icon.iosName}`),
54
+ )
55
+ }
56
+ return new Promise((resolve, reject) => {
57
+ Utils.executeOnMainThread(() => {
58
+ try {
59
+ application().setAlternateIconNameCompletionHandler(icon.iosName, (error) => {
60
+ // UIKit may invoke completion away from its main queue.
61
+ Utils.executeOnMainThread(() =>
62
+ error
63
+ ? reject(new AppIconError('platform', error.localizedDescription))
64
+ : resolve(),
65
+ )
66
+ })
67
+ } catch (cause) {
68
+ reject(new AppIconError('platform', 'iOS could not change the app icon.', { cause }))
69
+ }
70
+ })
71
+ })
72
+ },
73
+ }
74
+ }
@@ -0,0 +1,12 @@
1
+ import type { AppIconAdapter } from '@getcortexlabs/mavis-core'
2
+ import { AppIconError } from '@getcortexlabs/mavis-core'
3
+ import type { AppIconsOptions } from '../app-icons.js'
4
+
5
+ export function nativeAppIcons(_options: AppIconsOptions): AppIconAdapter {
6
+ return {
7
+ supported: () => false,
8
+ current: () => undefined,
9
+ select: () =>
10
+ Promise.reject(new AppIconError('unsupported', 'App icons require iOS or Android.')),
11
+ }
12
+ }
@@ -18,6 +18,12 @@ export function nativeMotionOwner(
18
18
  const owned: MotionSurfaceAdapter = {
19
19
  ...result,
20
20
  animate: (...args) => child.add(result.animate(...args)),
21
+ animateValue:
22
+ result.animateValue && ((...args) => child.add(result.animateValue!(...args))),
23
+ playbackProgress:
24
+ result.playbackProgress &&
25
+ ((...args) => child.add(result.playbackProgress!(...args))),
26
+ decay: result.decay && ((...args) => child.add(result.decay!(...args))),
21
27
  set: (...args) => child.add(result.set(...args)),
22
28
  motionValue:
23
29
  result.motionValue && ((...args) => child.add(result.motionValue!(...args))),
@@ -1,5 +1,5 @@
1
1
  import { Application, ScrollView, type View } from '@nativescript/core'
2
- import { animate, reducedMotion, onReducedMotion } from '@rafaelaugusto/jolt'
2
+ import { animate, motionScope, reducedMotion, onReducedMotion } from '@rafaelaugusto/jolt'
3
3
  import { sharedLayout } from '@rafaelaugusto/jolt/shared-layout'
4
4
  import {
5
5
  bindMotionRegion,
@@ -177,7 +177,67 @@ export function attachNativeMotionRegion(reference: MotionRegion, target: View)
177
177
  throw new Error('Declare each surface inside this motion region.')
178
178
  return child
179
179
  }
180
+ const scope = motionScope()
181
+ const steps = (
182
+ items: readonly (
183
+ | import('@getcortexlabs/mavis-core/experimental').MotionStep<MotionSurfaceAdapter>
184
+ | import('@getcortexlabs/mavis-core/experimental').MotionTimelineStep<MotionSurfaceAdapter>
185
+ )[],
186
+ ) =>
187
+ items.map((step) =>
188
+ typeof step === 'function' || 'run' in step
189
+ ? step
190
+ : ([resolveChild(step[0]), step[1], step[2]] as const),
191
+ )
180
192
  const adapter: MotionRegionAdapter = {
193
+ sequence: (items) =>
194
+ scope.sequence(steps(items) as unknown as Parameters<typeof scope.sequence>[0]),
195
+ timeline: (items) =>
196
+ scope.timeline(steps(items) as unknown as Parameters<typeof scope.timeline>[0]),
197
+ states(targets, definitions, options) {
198
+ const timing = (
199
+ input: import('@getcortexlabs/mavis-core/experimental').MotionStateTransition | undefined,
200
+ ) => {
201
+ const { targets, ...transition } = input ?? {}
202
+ return { ...transition, ...targets }
203
+ }
204
+ const control = scope.states(
205
+ Object.fromEntries(
206
+ Object.entries(targets).map(([name, surface]) => [
207
+ name,
208
+ surface && resolveChild(surface),
209
+ ]),
210
+ ),
211
+ Object.fromEntries(
212
+ Object.entries(definitions).map(([name, frames]) => [
213
+ name,
214
+ Object.fromEntries(
215
+ Object.entries(frames).filter(
216
+ (row): row is [string, NonNullable<(typeof row)[1]>] => row[1] !== undefined,
217
+ ),
218
+ ),
219
+ ]),
220
+ ),
221
+ { transition: timing(options?.transition) },
222
+ )
223
+ return {
224
+ get current() {
225
+ return control.current
226
+ },
227
+ get settled() {
228
+ return control.settled
229
+ },
230
+ get paused() {
231
+ return control.paused
232
+ },
233
+ to: (name, transition) => control.to(name, timing(transition)),
234
+ attach: (name, surface) => control.attach(name, surface && resolveChild(surface)),
235
+ pause: () => control.pause(),
236
+ play: () => control.play(),
237
+ stop: () => control.stop(),
238
+ dispose: () => control.dispose(),
239
+ }
240
+ },
181
241
  kind: 'native',
182
242
  viewportEnter(surfaces, options) {
183
243
  surfaces.forEach(resolveChild)
@@ -204,10 +264,12 @@ export function attachNativeMotionRegion(reference: MotionRegion, target: View)
204
264
  release()
205
265
  } finally {
206
266
  regions.delete(adapter)
267
+ scope.dispose()
207
268
  }
208
269
  }
209
270
  } catch (error) {
210
271
  regions.delete(adapter)
272
+ scope.dispose()
211
273
  throw error
212
274
  }
213
275
  }
@@ -2,6 +2,9 @@ import { nativeScrollMotion } from './scroll-motion.js'
2
2
  import { assertNativeRegion } from './motion-region.js'
3
3
  import type { View, EventData, TouchGestureEventData } from '@nativescript/core'
4
4
  import {
5
+ animate,
6
+ decay,
7
+ playbackProgress,
5
8
  bind,
6
9
  motionValue,
7
10
  springValue,
@@ -25,6 +28,10 @@ export function nativeContinuousSurface(target: View, enabled: () => boolean) {
25
28
  let suppressUntil = 0
26
29
  const adapter: Pick<
27
30
  MotionSurfaceAdapter,
31
+ | 'animateValue'
32
+ | 'stopValue'
33
+ | 'playbackProgress'
34
+ | 'decay'
28
35
  | 'motionValue'
29
36
  | 'springValue'
30
37
  | 'bind'
@@ -74,6 +81,26 @@ export function nativeContinuousSurface(target: View, enabled: () => boolean) {
74
81
  sources.set(value, mapped)
75
82
  return value
76
83
  },
84
+ animateValue(value, frames, options) {
85
+ const source = sources.get(value)
86
+ if (!source) throw new TypeError('Use a mutable native motion value.')
87
+ return animate(source as ReturnType<typeof motionValue>, frames, options)
88
+ },
89
+ stopValue(value, options) {
90
+ const source = sources.get(value)
91
+ if (!source) throw new TypeError('Use a native motion value.')
92
+ stop(source as ReturnType<typeof motionValue>, options)
93
+ },
94
+ playbackProgress(handle) {
95
+ const progress = playbackProgress(handle as Parameters<typeof playbackProgress>[0])
96
+ const value = { get: () => progress.get(), dispose() {} }
97
+ sources.set(value, progress)
98
+ return value
99
+ },
100
+ decay(velocity, options) {
101
+ interrupt(Object.keys(velocity))
102
+ return decay(target, velocity, options)
103
+ },
77
104
  motionValue(initial) {
78
105
  const source = motionValue(initial)
79
106
  const value: MotionValueAdapter = {
@@ -119,8 +146,9 @@ export function nativeContinuousSurface(target: View, enabled: () => boolean) {
119
146
  onMove: () => {
120
147
  suppressUntil = Date.now() + 500
121
148
  },
122
- onRelease: () => {
149
+ onRelease: (event) => {
123
150
  suppressUntil = Date.now() + 500
151
+ options.onRelease?.(event)
124
152
  },
125
153
  })
126
154
  const refresh = () => (paused || !enabled() ? gesture.pause() : gesture.play())
@@ -1,11 +1,11 @@
1
1
  import type { EventData, TouchGestureEventData, View } from '@nativescript/core'
2
2
  import { animate, stop, onReducedMotion } from '@rafaelaugusto/jolt'
3
- import { pressMotion } from '@getcortexlabs/mavis-core'
3
+ import { pressMotion, type MotionTheme } from '@getcortexlabs/mavis-core'
4
4
 
5
5
  let nextLayer = 0
6
6
 
7
7
  /** Press multiplies the app's scale; releasing it removes only that contribution. */
8
- export function attachPressFeedback(view: View, scale: number) {
8
+ export function attachPressFeedback(view: View, scale: number | Readonly<MotionTheme>) {
9
9
  let motion = pressMotion(scale)
10
10
  // Each attachment owns its channel, including after a theme change or reload.
11
11
  const layer = `mavis-press-${++nextLayer}`
@@ -47,7 +47,7 @@ export function attachPressFeedback(view: View, scale: number) {
47
47
  press(pressed: boolean) {
48
48
  onTouch({ action: pressed ? 'down' : 'cancel' } as TouchGestureEventData)
49
49
  },
50
- update(scale: number) {
50
+ update(scale: number | Readonly<MotionTheme>) {
51
51
  motion = pressMotion(scale)
52
52
  if (pressed && !disposed) animate(view, motion.pressed[0], { ...motion.pressed[1], layer })
53
53
  },
@@ -1,3 +1,4 @@
1
+ import { nativeDestination, navigateNative } from '../navigation.js'
1
2
  import { MRow } from './layout.js'
2
3
  import { MText } from './MText.js'
3
4
  import { MIcon } from './MIcon.js'
@@ -21,7 +22,7 @@ import {
21
22
  useMavisTheme,
22
23
  actionEmits,
23
24
  textContent,
24
- useDefaultShrink,
25
+ useLayoutShrink,
25
26
  } from '@getcortexlabs/mavis-core/vue'
26
27
  import {
27
28
  fontFamily,
@@ -55,7 +56,7 @@ export const MButton = defineComponent({
55
56
  useButtonAction()
56
57
  const { theme } = useMavisTheme()
57
58
  const nativeAttrs = useNativeViewAttrs(props)
58
- const shrink = useDefaultShrink()
59
+ const shrink = useLayoutShrink()
59
60
  const enabled = () => !props.disabled && !props.loading
60
61
  const keyboardPressed = ref(false)
61
62
  const lifecycle = usePressFeedback(enabled, theme, keyboardPressed)
@@ -68,7 +69,14 @@ export const MButton = defineComponent({
68
69
  focused.value = false
69
70
  }
70
71
  onBeforeUnmount(clearFocus)
72
+ const activate = () => {
73
+ if (!enabled() || !allowsActivation()) return
74
+ emit('click')
75
+ if (props.href !== undefined)
76
+ void navigateNative(props).catch((error) => emit('error', error))
77
+ }
71
78
  return () => {
79
+ if (props.href !== undefined) nativeDestination(props)
72
80
  const { colors, control, radius } = theme.value
73
81
  const tokens = theme.value.components.button
74
82
  const family = fontFamily(
@@ -82,7 +90,9 @@ export const MButton = defineComponent({
82
90
  : (props.text ?? textContent(slots.default?.()))
83
91
  const leading = buttonContent(slots.leading?.())
84
92
  const trailing = buttonContent(slots.trailing?.())
85
- const composed = Boolean(slots.leading || slots.trailing)
93
+ const composed = Boolean(
94
+ slots.leading || slots.trailing || (isAndroid && (props.icon || props.trailingIcon)),
95
+ )
86
96
  const hasIcon = Boolean(composed || props.icon || props.trailingIcon)
87
97
  checkIconOnly(text, hasIcon, props.accessibilityLabel)
88
98
  const iconSize = iconSizes[props.size]
@@ -135,7 +145,7 @@ export const MButton = defineComponent({
135
145
  : shadowStyle(theme.value.elevation[tokens.elevation], 'native'),
136
146
  opacity: props.disabled ? 0.45 : 1,
137
147
  flexGrow: nonNegative(props.grow, 'grow'),
138
- flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
148
+ flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
139
149
  },
140
150
  },
141
151
  nativeAttrs(),
@@ -145,12 +155,12 @@ export const MButton = defineComponent({
145
155
  {
146
156
  isEnabled: enabled(),
147
157
  accessible: true,
148
- accessibilityRole: 'button',
158
+ accessibilityRole: props.href === undefined ? 'button' : 'link',
149
159
  accessibilityState: enabled() ? '' : 'disabled',
150
160
  accessibilityLabel: props.accessibilityLabel ?? text,
151
161
  accessibilityValue: props.accessibilityLabel ? text : undefined,
152
162
  onTap: () => {
153
- if (enabled() && allowsActivation()) emit('click')
163
+ activate()
154
164
  },
155
165
  onLoaded: (event: EventData) => {
156
166
  clearFocus()
@@ -160,7 +170,7 @@ export const MButton = defineComponent({
160
170
  focused.value = value
161
171
  },
162
172
  () => {
163
- if (enabled() && allowsActivation()) emit('click')
173
+ activate()
164
174
  },
165
175
  (value) => {
166
176
  keyboardPressed.value = value
@@ -246,7 +256,7 @@ export const MButton = defineComponent({
246
256
  margin: 0,
247
257
  opacity: props.disabled ? 0.45 : 1,
248
258
  flexGrow: nonNegative(props.grow, 'grow'),
249
- flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
259
+ flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
250
260
  minWidth: isAndroid ? 48 : 44,
251
261
  },
252
262
  },
@@ -257,13 +267,13 @@ export const MButton = defineComponent({
257
267
  {
258
268
  isEnabled: enabled(),
259
269
  accessible: true,
260
- accessibilityRole: 'button',
270
+ accessibilityRole: props.href === undefined ? 'button' : 'link',
261
271
  accessibilityState: enabled() ? '' : 'disabled',
262
272
  accessibilityLabel: props.accessibilityLabel ?? text,
263
273
  accessibilityValue:
264
274
  attrs.accessibilityValue ?? (props.accessibilityLabel ? text : undefined),
265
275
  onTap: () => {
266
- if (enabled() && allowsActivation()) emit('click')
276
+ activate()
267
277
  },
268
278
  },
269
279
  ),
@@ -1,3 +1,4 @@
1
+ import { nativeDestination, navigateNative } from '../navigation.js'
1
2
  import { resolveSpace, resolveRadius, shadowStyle } from '@getcortexlabs/mavis-core'
2
3
  import { ActionChildren } from '../accessibility.js'
3
4
  import { defineComponent, h, mergeProps } from 'nativescript-vue'
@@ -17,16 +18,28 @@ export const MCard = defineComponent({
17
18
  props: cardProps,
18
19
  emits: actionEmits,
19
20
  setup(props, { attrs, slots, emit }) {
20
- useButtonAction(() => props.interactive)
21
+ useButtonAction(() => props.interactive || props.href !== undefined)
21
22
  const { theme } = useMavisTheme()
22
- const enabled = () => props.interactive && !props.disabled
23
+ const enabled = () => (props.interactive || props.href !== undefined) && !props.disabled
23
24
  const lifecycle = usePressFeedback(enabled, theme)
24
25
  const { allowsActivation, ...surface } = useMotionSurface(
25
26
  () => props.motionSurface,
26
27
  () => !props.disabled,
27
28
  )
28
29
  return () => {
29
- const { interactive, disabled, elevation, motionSurface, ...layout } = props
30
+ const {
31
+ interactive: action,
32
+ disabled,
33
+ elevation,
34
+ motionSurface,
35
+ href,
36
+ navigate,
37
+ target,
38
+ rel,
39
+ ...layout
40
+ } = props
41
+ const interactive = action || href !== undefined
42
+ if (href !== undefined) nativeDestination(props)
30
43
  const tokens = theme.value.components.card
31
44
  layout.padding ??= tokens.padding
32
45
  layout.radius ??= tokens.radius
@@ -51,11 +64,15 @@ export const MCard = defineComponent({
51
64
  surface,
52
65
  {
53
66
  accessible: interactive,
54
- accessibilityRole: interactive ? 'button' : '',
67
+ accessibilityRole: href !== undefined ? 'link' : interactive ? 'button' : '',
55
68
  accessibilityState: interactive && disabled ? 'disabled' : '',
56
69
  onTap: interactive
57
70
  ? () => {
58
- if (enabled() && allowsActivation()) emit('click')
71
+ if (enabled() && allowsActivation()) {
72
+ emit('click')
73
+ if (href !== undefined)
74
+ void navigateNative(props).catch((error) => emit('error', error))
75
+ }
59
76
  }
60
77
  : undefined,
61
78
  },
@@ -14,7 +14,7 @@ import {
14
14
  inputProps,
15
15
  inputEmits,
16
16
  useMavisTheme,
17
- useDefaultShrink,
17
+ useLayoutShrink,
18
18
  layoutDirection,
19
19
  } from '@getcortexlabs/mavis-core/vue'
20
20
  import {
@@ -48,7 +48,7 @@ const Input = defineComponent({
48
48
  setup(props, { attrs, emit, expose }) {
49
49
  useButtonAction()
50
50
  const { theme } = useMavisTheme()
51
- const shrink = useDefaultShrink()
51
+ const shrink = useLayoutShrink()
52
52
  provide(layoutDirection, 'column')
53
53
  const nativeAttrs = useNativeViewAttrs(props)
54
54
  const editor = shallowRef<{ nativeView: TextField | TextView }>()
@@ -127,7 +127,7 @@ const Input = defineComponent({
127
127
  style: {
128
128
  width: resolveDimension(props.width),
129
129
  flexGrow: nonNegative(props.grow, 'grow'),
130
- flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
130
+ flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
131
131
  minWidth: 0,
132
132
  opacity: props.disabled ? 0.5 : 1,
133
133
  },