@getcortexlabs/mavis 0.1.0-rc.14 → 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 (148) 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/motion-binding.d.ts +11 -0
  31. package/dist/native/motion-binding.d.ts.map +1 -0
  32. package/dist/native/motion-binding.js +132 -0
  33. package/dist/native/motion-binding.js.map +1 -0
  34. package/dist/native/motion-surface.d.ts +1 -1
  35. package/dist/native/motion-surface.d.ts.map +1 -1
  36. package/dist/native/motion-surface.js +20 -5
  37. package/dist/native/motion-surface.js.map +1 -1
  38. package/dist/native/navigation.d.ts +4 -0
  39. package/dist/native/navigation.d.ts.map +1 -0
  40. package/dist/native/navigation.js +16 -0
  41. package/dist/native/navigation.js.map +1 -0
  42. package/dist/native/pointer-availability.d.ts +7 -0
  43. package/dist/native/pointer-availability.d.ts.map +1 -0
  44. package/dist/native/pointer-availability.js +43 -0
  45. package/dist/native/pointer-availability.js.map +1 -0
  46. package/dist/native/scroll-motion.d.ts +1 -1
  47. package/dist/native/section-scroll.d.ts +1 -1
  48. package/dist/vue/components/ChoiceControl.d.ts +3 -3
  49. package/dist/vue/components/DateCalendar.d.ts +1 -1
  50. package/dist/vue/components/LoadingDecoration.d.ts +5 -5
  51. package/dist/vue/components/MAccordion.d.ts +3 -3
  52. package/dist/vue/components/MAlert.d.ts +4 -4
  53. package/dist/vue/components/MAvatar.d.ts +4 -4
  54. package/dist/vue/components/MBadge.d.ts +3 -3
  55. package/dist/vue/components/MButton.d.ts +16 -16
  56. package/dist/vue/components/MCard.d.ts +11 -11
  57. package/dist/vue/components/MCheckbox.d.ts +3 -3
  58. package/dist/vue/components/MChip.d.ts +4 -4
  59. package/dist/vue/components/MCombobox.d.ts +5 -5
  60. package/dist/vue/components/MDialog.d.ts +3 -3
  61. package/dist/vue/components/MEmptyState.d.ts +3 -3
  62. package/dist/vue/components/MGrid.d.ts +7 -7
  63. package/dist/vue/components/MGrid.d.ts.map +1 -1
  64. package/dist/vue/components/MGrid.js +5 -1
  65. package/dist/vue/components/MGrid.js.map +1 -1
  66. package/dist/vue/components/MIcon.d.ts +2 -2
  67. package/dist/vue/components/MImage.d.ts +7 -7
  68. package/dist/vue/components/MImageCompare.d.ts +1 -1
  69. package/dist/vue/components/MInput.d.ts +20 -20
  70. package/dist/vue/components/MLink.d.ts +5 -5
  71. package/dist/vue/components/MListItem.d.ts +5 -5
  72. package/dist/vue/components/MPinInput.d.ts +1 -1
  73. package/dist/vue/components/MPopover.d.ts +3 -3
  74. package/dist/vue/components/MProgress.d.ts +5 -5
  75. package/dist/vue/components/MRadioGroup.d.ts +3 -3
  76. package/dist/vue/components/MRangeSlider.d.ts +3 -3
  77. package/dist/vue/components/MResizablePanels.d.ts +3 -3
  78. package/dist/vue/components/MReveal.d.ts +9 -9
  79. package/dist/vue/components/MScreen.d.ts +3 -3
  80. package/dist/vue/components/MScreen.d.ts.map +1 -1
  81. package/dist/vue/components/MScreen.js +11 -1
  82. package/dist/vue/components/MScreen.js.map +1 -1
  83. package/dist/vue/components/MSegmentedControl.d.ts +3 -3
  84. package/dist/vue/components/MSelect.d.ts +4 -4
  85. package/dist/vue/components/MSheet.d.ts +3 -3
  86. package/dist/vue/components/MSkeleton.d.ts +3 -3
  87. package/dist/vue/components/MSlider.d.ts +2 -2
  88. package/dist/vue/components/MStack.d.ts +11 -11
  89. package/dist/vue/components/MStack.d.ts.map +1 -1
  90. package/dist/vue/components/MStack.js +12 -2
  91. package/dist/vue/components/MStack.js.map +1 -1
  92. package/dist/vue/components/MSwitch.d.ts +3 -3
  93. package/dist/vue/components/MTabs.d.ts +3 -3
  94. package/dist/vue/components/MText.d.ts +8 -8
  95. package/dist/vue/components/MText.d.ts.map +1 -1
  96. package/dist/vue/components/MText.js +4 -1
  97. package/dist/vue/components/MText.js.map +1 -1
  98. package/dist/vue/components/MTooltip.d.ts +2 -2
  99. package/dist/vue/components/dashboard.d.ts.map +1 -1
  100. package/dist/vue/components/dashboard.js +21 -6
  101. package/dist/vue/components/dashboard.js.map +1 -1
  102. package/dist/vue/components/layout.d.ts +29 -29
  103. package/dist/vue/components/layout.d.ts.map +1 -1
  104. package/dist/vue/components/layout.js +8 -2
  105. package/dist/vue/components/layout.js.map +1 -1
  106. package/dist/vue/components/screen-components.d.ts.map +1 -1
  107. package/dist/vue/components/screen-components.js +15 -0
  108. package/dist/vue/components/screen-components.js.map +1 -1
  109. package/dist/vue/layout-context.d.ts +4 -0
  110. package/dist/vue/layout-context.d.ts.map +1 -0
  111. package/dist/vue/layout-context.js +3 -0
  112. package/dist/vue/layout-context.js.map +1 -0
  113. package/dist/vue/navigation.d.ts +1 -3
  114. package/dist/vue/navigation.d.ts.map +1 -1
  115. package/dist/vue/navigation.js +1 -15
  116. package/dist/vue/navigation.js.map +1 -1
  117. package/dist/vue/screen-overlay.d.ts +9 -0
  118. package/dist/vue/screen-overlay.d.ts.map +1 -0
  119. package/dist/vue/screen-overlay.js +17 -0
  120. package/dist/vue/screen-overlay.js.map +1 -0
  121. package/dist/vue/use-motion-surface.d.ts +2 -3
  122. package/dist/vue/use-motion-surface.d.ts.map +1 -1
  123. package/dist/vue/use-motion-surface.js +9 -128
  124. package/dist/vue/use-motion-surface.js.map +1 -1
  125. package/package.json +8 -4
  126. package/platforms/android/java/com/mavis/ui/Box.java +31 -0
  127. package/src/components/bindings.ts +32 -0
  128. package/src/components/contracts.ts +60 -0
  129. package/src/components/controller.ts +542 -0
  130. package/src/components/index.ts +136 -0
  131. package/src/components/style.ts +84 -0
  132. package/src/components/theme.ts +25 -0
  133. package/src/native/box.ios.ts +31 -1
  134. package/src/native/motion-binding.ts +143 -0
  135. package/src/native/motion-surface.ts +19 -5
  136. package/src/native/navigation.ts +15 -0
  137. package/src/native/pointer-availability.ts +44 -0
  138. package/src/vue/components/MGrid.ts +10 -1
  139. package/src/vue/components/MScreen.ts +12 -1
  140. package/src/vue/components/MStack.ts +17 -2
  141. package/src/vue/components/MText.ts +4 -1
  142. package/src/vue/components/dashboard.ts +23 -5
  143. package/src/vue/components/layout.ts +8 -0
  144. package/src/vue/components/screen-components.ts +14 -0
  145. package/src/vue/layout-context.ts +4 -0
  146. package/src/vue/navigation.ts +1 -15
  147. package/src/vue/screen-overlay.ts +20 -0
  148. package/src/vue/use-motion-surface.ts +10 -133
@@ -0,0 +1,136 @@
1
+ import { GridLayout, View, type LayoutBase, type Label, type Button } from '@nativescript/core'
2
+ import { MavisFlexLayout } from '../native/flex-layout'
3
+ import { MavisBox } from '../native/box'
4
+ import { MavisButton } from '../native/button'
5
+ import { MavisLabel } from '../native/label'
6
+ import { NativeComponentController } from './controller.js'
7
+ import { createMavisTheme, MavisThemeScope } from './theme.js'
8
+ import type {
9
+ NativeComponentName,
10
+ NativeComponentProps,
11
+ NativeComponentEvents,
12
+ NativeComponentOptions,
13
+ } from './contracts.js'
14
+ import type { MavisTheme } from '@getcortexlabs/mavis-core'
15
+
16
+ export * from './contracts.js'
17
+ export { componentEvents, plainComponentText, type ComponentCallbacks } from './bindings.js'
18
+ export { createMavisTheme, MavisThemeScope } from './theme.js'
19
+
20
+ /** Framework bridges assign an immutable props snapshot; native view attributes stay separate. */
21
+ export interface MavisNativeView extends View {
22
+ mavisProps: NativeComponentProps<NativeComponentName>
23
+ mavisTheme: MavisThemeScope | undefined
24
+ mavisEvents: NativeComponentEvents
25
+ mavisContentText: string
26
+ disposeMavis(): void
27
+ focusInput(): void
28
+ blurInput(): void
29
+ focusInputAction(): void
30
+ }
31
+
32
+ export type NativeViewFor<N extends NativeComponentName> = MavisNativeView &
33
+ (N extends 'MBox' | 'MRow' | 'MColumn' | 'MInput'
34
+ ? LayoutBase
35
+ : N extends 'MText'
36
+ ? Label
37
+ : Button)
38
+
39
+ function componentClass(
40
+ name: NativeComponentName,
41
+ Base: new () => View,
42
+ ): new () => MavisNativeView {
43
+ return class extends Base {
44
+ private mavisController = new NativeComponentController(this, name)
45
+ set mavisProps(props: NativeComponentProps<NativeComponentName>) {
46
+ this.mavisController.setProps(props)
47
+ }
48
+ get mavisProps() {
49
+ return this.mavisController.props as NativeComponentProps<NativeComponentName>
50
+ }
51
+ set mavisTheme(scope: MavisThemeScope | undefined) {
52
+ this.mavisController.setTheme(scope)
53
+ }
54
+ get mavisTheme(): MavisThemeScope {
55
+ return this.mavisController.themeScope
56
+ }
57
+ set mavisEvents(events: NativeComponentEvents) {
58
+ this.mavisController.events = events ?? {}
59
+ }
60
+ get mavisEvents() {
61
+ return this.mavisController.events
62
+ }
63
+ set mavisContentText(text: string) {
64
+ this.mavisController.setContentText(text)
65
+ }
66
+ disposeMavis() {
67
+ this.mavisController.dispose()
68
+ }
69
+ focusInput() {
70
+ this.mavisController.focus()
71
+ }
72
+ blurInput() {
73
+ this.mavisController.blur()
74
+ }
75
+ focusInputAction() {
76
+ this.mavisController.focusAction()
77
+ }
78
+ }
79
+ }
80
+
81
+ export const nativeComponents = {
82
+ MBox: componentClass('MBox', MavisBox),
83
+ MRow: componentClass('MRow', MavisFlexLayout),
84
+ MColumn: componentClass('MColumn', MavisFlexLayout),
85
+ MText: componentClass('MText', MavisLabel),
86
+ MButton: componentClass('MButton', MavisButton),
87
+ MInput: componentClass('MInput', GridLayout),
88
+ } as const
89
+
90
+ /** Direct JS/TS integration. The owner decides whether to accept controlled value requests. */
91
+ export function createNativeComponent<N extends NativeComponentName>(
92
+ name: N,
93
+ props: NativeComponentProps<N>,
94
+ options: NativeComponentOptions = {},
95
+ ) {
96
+ const view = new nativeComponents[name]() as NativeViewFor<N>
97
+ view.mavisTheme = options.theme
98
+ view.mavisEvents = options.events ?? {}
99
+ view.mavisProps = props
100
+ return {
101
+ view,
102
+ update(next: NativeComponentProps<N>) {
103
+ view.mavisProps = next
104
+ },
105
+ setEvents(events: NativeComponentEvents) {
106
+ view.mavisEvents = events
107
+ },
108
+ focus() {
109
+ view.focusInput()
110
+ },
111
+ blur() {
112
+ view.blurInput()
113
+ },
114
+ focusAction() {
115
+ view.focusInputAction()
116
+ },
117
+ dispose() {
118
+ view.disposeMavis()
119
+ },
120
+ }
121
+ }
122
+
123
+ export function createMavis(options: { theme?: MavisTheme } = {}) {
124
+ const scope = createMavisTheme(options.theme)
125
+ return {
126
+ theme: scope,
127
+ setTheme: (theme: MavisTheme) => scope.setTheme(theme),
128
+ create<N extends NativeComponentName>(
129
+ name: N,
130
+ props: NativeComponentProps<N>,
131
+ events?: NativeComponentEvents,
132
+ ) {
133
+ return createNativeComponent(name, props, { theme: scope, events })
134
+ },
135
+ }
136
+ }
@@ -0,0 +1,84 @@
1
+ import {
2
+ fontFamily,
3
+ nonNegative,
4
+ resolveDimension,
5
+ resolveRadius,
6
+ resolveSpace,
7
+ shadowStyle,
8
+ validateWeight,
9
+ type MavisTheme,
10
+ } from '@getcortexlabs/mavis-core'
11
+ import { isAndroid } from '@nativescript/core'
12
+ import type { MBoxProps, MTextProps, MButtonProps } from './contracts.js'
13
+
14
+ export function nativeBoxStyle(theme: MavisTheme, props: MBoxProps, shrink = 0) {
15
+ const padding = props.padding === undefined ? undefined : resolveSpace(theme, props.padding)
16
+ const x = props.paddingX === undefined ? padding : resolveSpace(theme, props.paddingX)
17
+ const y = props.paddingY === undefined ? padding : resolveSpace(theme, props.paddingY)
18
+ return {
19
+ paddingLeft: x ?? 0,
20
+ paddingRight: x ?? 0,
21
+ paddingTop: y ?? 0,
22
+ paddingBottom: y ?? 0,
23
+ borderRadius: props.radius === undefined ? 0 : resolveRadius(theme, props.radius),
24
+ width: resolveDimension(props.width) ?? 'auto',
25
+ height: resolveDimension(props.height) ?? 'auto',
26
+ backgroundColor: props.backgroundColor ?? 'transparent',
27
+ flexGrow: nonNegative(props.grow ?? 0, 'grow'),
28
+ flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
29
+ minWidth: 0,
30
+ }
31
+ }
32
+
33
+ export function nativeTextStyle(theme: MavisTheme, props: MTextProps, shrink = 0) {
34
+ const type = theme.typography[props.variant ?? 'body']
35
+ return {
36
+ ...type,
37
+ fontFamily: fontFamily(type.fontFamily, isAndroid ? 'android' : 'ios'),
38
+ fontWeight: props.weight === undefined ? type.fontWeight : validateWeight(props.weight),
39
+ lineHeight: type.fontSize * (type.lineHeight - 1),
40
+ color: theme.colors[props.tone ?? 'text'],
41
+ textAlignment: props.align ?? 'left',
42
+ flexGrow: nonNegative(props.grow ?? 0, 'grow'),
43
+ flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
44
+ minWidth: 0,
45
+ }
46
+ }
47
+
48
+ export function nativeButtonStyle(theme: MavisTheme, props: MButtonProps, shrink = 0) {
49
+ const tokens = theme.components.button
50
+ const size = theme.control[props.size ?? 'md']
51
+ const primary = (props.variant ?? 'primary') === 'primary'
52
+ return {
53
+ minHeight: Math.max(size.height, isAndroid ? 48 : 44),
54
+ minWidth: isAndroid ? 48 : 44,
55
+ paddingLeft: size.padding,
56
+ paddingRight: size.padding,
57
+ paddingTop: tokens.paddingY,
58
+ paddingBottom: tokens.paddingY,
59
+ fontSize: size.fontSize,
60
+ fontWeight: tokens.fontWeight,
61
+ fontFamily: fontFamily(
62
+ tokens.fontFamily ?? theme.typography.body.fontFamily,
63
+ isAndroid ? 'android' : 'ios',
64
+ ),
65
+ lineHeight: size.fontSize * (tokens.lineHeight - 1),
66
+ textTransform: 'none',
67
+ backgroundColor: primary
68
+ ? theme.colors.primary
69
+ : props.variant === 'secondary'
70
+ ? theme.colors.elevated
71
+ : 'transparent',
72
+ color: primary ? theme.colors.onPrimary : theme.colors.text,
73
+ borderRadius: resolveRadius(theme, tokens.radius),
74
+ borderWidth: 0,
75
+ androidElevation: 0,
76
+ androidDynamicElevationOffset: 0,
77
+ margin: 0,
78
+ boxShadow:
79
+ props.variant === 'ghost' ? 'none' : shadowStyle(theme.elevation[tokens.elevation], 'native'),
80
+ opacity: props.disabled ? 0.45 : 1,
81
+ flexGrow: nonNegative(props.grow ?? 0, 'grow'),
82
+ flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
83
+ }
84
+ }
@@ -0,0 +1,25 @@
1
+ import { mavis, type MavisTheme } from '@getcortexlabs/mavis-core'
2
+
3
+ /** An application or an explicitly isolated theme scope. No process-wide mutable theme. */
4
+ export class MavisThemeScope {
5
+ private listeners = new Set<() => void>()
6
+ constructor(private current: MavisTheme = mavis) {}
7
+ get theme() {
8
+ return this.current
9
+ }
10
+ setTheme(theme: MavisTheme) {
11
+ if (theme === this.current) return
12
+ this.current = theme
13
+ for (const listener of [...this.listeners]) listener()
14
+ }
15
+ subscribe(listener: () => void) {
16
+ this.listeners.add(listener)
17
+ return () => {
18
+ this.listeners.delete(listener)
19
+ }
20
+ }
21
+ }
22
+
23
+ export function createMavisTheme(theme: MavisTheme = mavis) {
24
+ return new MavisThemeScope(theme)
25
+ }
@@ -1,4 +1,4 @@
1
- import { GridLayout, Utils } from '@nativescript/core'
1
+ import { GridLayout, Utils, View } from '@nativescript/core'
2
2
  import {
3
3
  filledLimit,
4
4
  layoutChildren,
@@ -13,6 +13,36 @@ const { layout } = Utils
13
13
  export class MavisBox extends GridLayout {
14
14
  measureRecord?: MeasureRecord
15
15
 
16
+ // MBox is one shared area. Core centres a fixed child whose default alignment
17
+ // is stretch; CSS grid instead anchors that child at the start of the area.
18
+ // Offer only its measured extent on a fixed axis, without changing its style
19
+ // or laying it out twice. Unsized axes still receive the whole content area.
20
+ onLayout(left: number, top: number, right: number, bottom: number) {
21
+ const insets = this.getSafeAreaInsets()
22
+ const x = this.effectiveBorderLeftWidth + this.effectivePaddingLeft + insets.left
23
+ const y = this.effectiveBorderTopWidth + this.effectivePaddingTop + insets.top
24
+ const endX =
25
+ right - left - this.effectiveBorderRightWidth - this.effectivePaddingRight - insets.right
26
+ const endY =
27
+ bottom - top - this.effectiveBorderBottomWidth - this.effectivePaddingBottom - insets.bottom
28
+ this.eachLayoutChild((child) => {
29
+ const fixedX = child.effectiveWidth >= 0 && child.horizontalAlignment === 'stretch'
30
+ const fixedY = child.effectiveHeight >= 0 && child.verticalAlignment === 'stretch'
31
+ View.layoutChild(
32
+ this,
33
+ child,
34
+ x,
35
+ y,
36
+ fixedX
37
+ ? x + child.getMeasuredWidth() + child.effectiveMarginLeft + child.effectiveMarginRight
38
+ : endX,
39
+ fixedY
40
+ ? y + child.getMeasuredHeight() + child.effectiveMarginTop + child.effectiveMarginBottom
41
+ : endY,
42
+ )
43
+ })
44
+ }
45
+
16
46
  measure(widthSpec: number, heightSpec: number) {
17
47
  if (reuseMeasurement(this, widthSpec, heightSpec)) return
18
48
  super.measure(widthSpec, heightSpec)
@@ -0,0 +1,143 @@
1
+ import { Utils, isAndroid, type EventData, type View } from '@nativescript/core'
2
+ import { animate, set, onReducedMotion } from '@rafaelaugusto/jolt'
3
+ import {
4
+ bindMotionSurface,
5
+ motionChannels,
6
+ motionKeyframes,
7
+ type MotionFrames,
8
+ type MotionSurface,
9
+ } from '@getcortexlabs/mavis-core/experimental'
10
+ import { nativeContinuousSurface } from './motion-surface.js'
11
+ import { nativeMotionOwner } from './motion-owner.js'
12
+ import { takeShadow } from './moved-shadow.js'
13
+
14
+ export function createNativeMotionSurface(
15
+ surface: () => MotionSurface | undefined,
16
+ enabled: () => boolean = () => true,
17
+ plainText: () => boolean = () => false,
18
+ afterLayout = false,
19
+ perspective?: () => number | undefined,
20
+ ) {
21
+ let view: View | undefined
22
+ let unbind: (() => void) | undefined
23
+ let offPreference: (() => void) | undefined
24
+ let continuous: ReturnType<typeof nativeContinuousSurface> | undefined
25
+ const active = new Map<ReturnType<typeof animate>, MotionFrames>()
26
+ let layoutView: View | undefined
27
+ let layoutQueued = false
28
+ let flat: { view: View; perspective: number } | undefined
29
+ const project = () => {
30
+ const depth = perspective?.()
31
+ if (flat && (depth === undefined || flat.view !== view)) {
32
+ flat.view.perspective = flat.perspective
33
+ flat = undefined
34
+ }
35
+ if (!view || depth === undefined || !unbind) return
36
+ flat ??= { view, perspective: view.perspective }
37
+ // Core multiplies by the density for Android's camera distance, whose unit is not the
38
+ // CSS distance. This is the factor that draws the same projection as iOS and the Web.
39
+ view.perspective = isAndroid ? depth * Utils.layout.getDisplayDensity() * Math.sqrt(5) : depth
40
+ }
41
+ const clearLayout = () => {
42
+ layoutView?.off('layoutChanged', laidOut)
43
+ layoutView = undefined
44
+ }
45
+ const release = () => {
46
+ unbind?.()
47
+ unbind = undefined
48
+ continuous = undefined
49
+ offPreference?.()
50
+ offPreference = undefined
51
+ for (const handle of active.keys()) handle.stop()
52
+ active.clear()
53
+ project()
54
+ }
55
+ const bind = () => {
56
+ release()
57
+ const target = view
58
+ const reference = surface()
59
+ if (!target || !reference) return
60
+ if (
61
+ afterLayout &&
62
+ (!target.isLayoutValid ||
63
+ target.getActualSize().width <= 0 ||
64
+ target.getActualSize().height <= 0)
65
+ ) {
66
+ if (layoutView !== target) {
67
+ clearLayout()
68
+ layoutView = target
69
+ target.on('layoutChanged', laidOut)
70
+ }
71
+ return
72
+ }
73
+ clearLayout()
74
+ continuous = nativeContinuousSurface(target, enabled, plainText)
75
+ unbind = bindMotionSurface(
76
+ reference,
77
+ nativeMotionOwner(
78
+ {
79
+ ...continuous.adapter,
80
+ animate(values, options) {
81
+ continuous?.interrupt(motionChannels(values))
82
+ const handle = animate(target, motionKeyframes(values), options)
83
+ takeShadow(target, values)
84
+ active.set(handle, values)
85
+ void handle.finished.then(() => active.delete(handle))
86
+ return handle
87
+ },
88
+ set: (values) => {
89
+ continuous?.interrupt(Object.keys(values))
90
+ const handle = animate(target, values, { duration: 0 })
91
+ takeShadow(target, values)
92
+ return handle
93
+ },
94
+ },
95
+ target,
96
+ ),
97
+ )
98
+ project()
99
+ offPreference = onReducedMotion((reduced) => {
100
+ if (!reduced) return
101
+ // Set only spatial channels: opacity and shadow paint can keep their timelines.
102
+ const values: Record<string, number> = {}
103
+ for (const frames of active.values()) {
104
+ if (frames.path)
105
+ Object.assign(values, {
106
+ x: frames.path.end.x,
107
+ y: frames.path.end.y,
108
+ ...(frames.orient ? { rotate: frames.path.end.rotate } : {}),
109
+ })
110
+ for (const [property, value] of Object.entries(frames)) {
111
+ if (property === 'opacity' || property.startsWith('shadow')) continue
112
+ const final = Array.isArray(value) ? value.at(-1) : value
113
+ if (typeof final === 'number') values[property] = final
114
+ }
115
+ }
116
+ if (Object.keys(values).length) set(target, values)
117
+ })
118
+ }
119
+ const laidOut = () => {
120
+ if (layoutQueued) return
121
+ layoutQueued = true
122
+ void Promise.resolve().then(() => {
123
+ layoutQueued = false
124
+ if (view) bind()
125
+ })
126
+ }
127
+ const unloaded = () => {
128
+ clearLayout()
129
+ release()
130
+ view = undefined
131
+ }
132
+ return {
133
+ refresh: bind,
134
+ refreshEnabled: () => continuous?.refresh(),
135
+ refreshPerspective: project,
136
+ allowsActivation: () => continuous?.allowsActivation() ?? true,
137
+ onLoaded(event: EventData) {
138
+ view = event.object as View
139
+ bind()
140
+ },
141
+ onUnloaded: unloaded,
142
+ }
143
+ }
@@ -2,6 +2,7 @@ import { nativeScrollMotion } from './scroll-motion.js'
2
2
  import { assertNativeRegion, nativeRegionTarget } from './motion-region.js'
3
3
  import { nativeSectionScroll } from './section-scroll.js'
4
4
  import { nativeVisualEffects } from './visual-effects.js'
5
+ import { watchPointerAvailability } from './pointer-availability.js'
5
6
  import { sensor } from '@rafaelaugusto/jolt/sensors'
6
7
  import type { View, EventData, TouchGestureEventData } from '@nativescript/core'
7
8
  import {
@@ -102,12 +103,18 @@ export function nativeContinuousSurface(
102
103
  assertNativeRegion(region, target)
103
104
  // Jolt owns the hover listener, its geometry, suspension and the views' load state.
104
105
  // Ordinary touch is not hover, so scrolling, taps and focus stay with the app.
105
- const pointer = pointerFollow(nativeRegionTarget(region), {
106
- ...options,
106
+ const { onAvailabilityChange, ...inputOptions } = options
107
+ const inputRegion = nativeRegionTarget(region)
108
+ const pointer = pointerFollow(inputRegion, {
109
+ ...inputOptions,
107
110
  disabled: options.disabled || !enabled(),
108
111
  } as PointerOptions)
109
112
  let disabled = options.disabled ?? false
110
- const refresh = () => pointer.update({ disabled: disabled || !enabled() })
113
+ const unwatch = watchPointerAvailability(pointer, inputRegion, onAvailabilityChange)
114
+ const refresh = () => {
115
+ pointer.update({ disabled: disabled || !enabled() })
116
+ unwatch.notify()
117
+ }
111
118
  refreshes.add(refresh)
112
119
  // The pointer owns its values; wrappers are borrowed by Mavis bindings.
113
120
  const wrap = (source: DerivedValue) => {
@@ -132,10 +139,17 @@ export function nativeContinuousSurface(
132
139
  disabled = state.disabled
133
140
  refresh()
134
141
  },
135
- refresh: () => pointer.refresh(),
142
+ refresh: () => {
143
+ pointer.refresh()
144
+ unwatch.notify()
145
+ },
136
146
  dispose() {
137
147
  refreshes.delete(refresh)
138
- pointer.dispose()
148
+ try {
149
+ unwatch()
150
+ } finally {
151
+ pointer.dispose()
152
+ }
139
153
  },
140
154
  }
141
155
  },
@@ -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
+ }
@@ -0,0 +1,44 @@
1
+ import { Application, type View } from '@nativescript/core'
2
+ import { onReducedMotion, type PointerFollow } from '@rafaelaugusto/jolt'
3
+
4
+ /** Publish Jolt's live state after its native load, preference and application handlers run. */
5
+ export function watchPointerAvailability(
6
+ pointer: PointerFollow,
7
+ region: View,
8
+ changed?: (available: boolean) => void,
9
+ ) {
10
+ if (!changed) return Object.assign(() => {}, { notify() {} })
11
+ let stopped = false,
12
+ queued = false,
13
+ previous: boolean | undefined
14
+ const notify = () => {
15
+ if (stopped || queued) return
16
+ queued = true
17
+ void Promise.resolve().then(() => {
18
+ queued = false
19
+ if (stopped) return
20
+ const available = pointer.available
21
+ if (available !== previous) changed((previous = available))
22
+ })
23
+ }
24
+ const events = ['loaded', 'unloaded', 'layoutChanged', 'isEnabledChange', 'visibilityChange']
25
+ for (const event of events) region.on(event, notify)
26
+ region.style.on('visibilityChange', notify)
27
+ Application.on(Application.suspendEvent, notify)
28
+ Application.on(Application.resumeEvent, notify)
29
+ const offReduced = onReducedMotion(notify)
30
+ notify()
31
+ return Object.assign(
32
+ () => {
33
+ if (stopped) return
34
+ stopped = true
35
+ for (const event of events) region.off(event, notify)
36
+ region.style.off('visibilityChange', notify)
37
+ Application.off(Application.suspendEvent, notify)
38
+ Application.off(Application.resumeEvent, notify)
39
+ offReduced()
40
+ if (previous !== false) changed(false)
41
+ },
42
+ { notify },
43
+ )
44
+ }
@@ -23,12 +23,14 @@ import {
23
23
  import { boxStyle } from '../props.js'
24
24
  import { useNativeViewAttrs } from '../accessibility.js'
25
25
  import './layout.js'
26
+ import { useOverlayLayout } from '../screen-overlay.js'
26
27
 
27
28
  export const MGrid = defineComponent({
28
29
  name: 'MGrid',
29
30
  inheritAttrs: false,
30
31
  props: gridProps,
31
32
  setup(props, { attrs, slots }) {
33
+ const overlay = useOverlayLayout()
32
34
  const { theme } = useMavisTheme()
33
35
  const shrink = useLayoutShrink()
34
36
  const nativeAttrs = useNativeViewAttrs(props)
@@ -67,6 +69,7 @@ export const MGrid = defineComponent({
67
69
  h(
68
70
  'MavisBox',
69
71
  {
72
+ ...overlay({}),
70
73
  key: child.key ?? cell,
71
74
  col: (cell % count) * 2,
72
75
  row: Math.floor(cell / count) * 2,
@@ -79,11 +82,17 @@ export const MGrid = defineComponent({
79
82
  const rows = Math.ceil(index / count)
80
83
  return h(
81
84
  'MavisBox',
82
- mergeProps({ style: boxStyle(theme.value, props, shrink.value) }, nativeAttrs(), attrs),
85
+ mergeProps(
86
+ overlay(attrs),
87
+ { style: boxStyle(theme.value, props, shrink.value) },
88
+ nativeAttrs(),
89
+ attrs,
90
+ ),
83
91
  [
84
92
  h(
85
93
  'GridLayout',
86
94
  {
95
+ ...overlay({}),
87
96
  ...motion,
88
97
  columns: Array.from({ length: count }, () => '*').join(`,${gap},`),
89
98
  rows: Array.from({ length: rows }, () => 'auto').join(`,${gap},`),
@@ -23,6 +23,7 @@ import { useNativeViewAttrs } from '../accessibility.js'
23
23
  import { provideLayerHost } from '../layers.js'
24
24
  import { expandLayerHost } from '../../native/sheet'
25
25
  import { useMotionRegion } from '../use-motion-region.js'
26
+ import { screenOverlay } from '../screen-overlay.js'
26
27
 
27
28
  registerElement('MavisScreenScroll', () => MavisScreenScroll, {
28
29
  // NSVViewFlags.CONTENT_VIEW; ScrollView owns one content view.
@@ -48,6 +49,16 @@ function placeOverlay(node: VNode, covered: boolean): VNode {
48
49
  return copy
49
50
  }
50
51
 
52
+ // A Fragment preserves retained header/ScrollView sibling identity while
53
+ // passing the hit-test policy through every nested Mavis layout.
54
+ const ScreenOverlay = defineComponent({
55
+ props: { covered: Boolean },
56
+ setup(props, { slots }) {
57
+ provide(screenOverlay, true)
58
+ return () => slots.default?.().map((node) => placeOverlay(node, props.covered))
59
+ },
60
+ })
61
+
51
62
  export const MScreen = defineComponent({
52
63
  name: 'MScreen',
53
64
  inheritAttrs: false,
@@ -132,7 +143,7 @@ export const MScreen = defineComponent({
132
143
  [content],
133
144
  )
134
145
  : content,
135
- slots.overlay?.().map((node) => placeOverlay(node, covered)),
146
+ slots.overlay ? h(ScreenOverlay, { covered }, { default: slots.overlay }) : null,
136
147
  ...notices.map((layer) =>
137
148
  h(layer.component, { ...layer.props, covered, key: layer.key }),
138
149
  ),
@@ -12,6 +12,7 @@ import {
12
12
  import { boxStyle } from '../props.js'
13
13
  import { useNativeViewAttrs } from '../accessibility.js'
14
14
  import './layout.js'
15
+ import { useOverlayLayout } from '../screen-overlay.js'
15
16
 
16
17
  const align = {
17
18
  start: 'flex-start',
@@ -32,6 +33,7 @@ export const MStack = defineComponent({
32
33
  inheritAttrs: false,
33
34
  props: stackProps,
34
35
  setup(props, { attrs, slots }) {
36
+ const overlay = useOverlayLayout()
35
37
  const { theme } = useMavisTheme()
36
38
  const nativeAttrs = useNativeViewAttrs(props)
37
39
  const shrink = useLayoutShrink()
@@ -55,25 +57,38 @@ export const MStack = defineComponent({
55
57
  provide(layoutDirection, direction)
56
58
  const measure = (event: EventData) => {
57
59
  const view = event.object as View
58
- const size = view.getActualSize().width
60
+ const size = view.getActualSize()?.width ?? 0
59
61
  // The inner layout occupies the outer Box's content area, after padding.
60
62
  if (size > 0 && size !== width.value) width.value = size
61
63
  }
62
64
  return () =>
63
65
  h(
64
66
  'MavisBox',
65
- mergeProps({ style: boxStyle(theme.value, props, shrink.value) }, nativeAttrs(), attrs),
67
+ mergeProps(
68
+ overlay(attrs),
69
+ { style: boxStyle(theme.value, props, shrink.value) },
70
+ nativeAttrs(),
71
+ attrs,
72
+ ),
66
73
  [
67
74
  h(
68
75
  'MavisFlexLayout',
69
76
  {
77
+ ...overlay({}),
70
78
  ...motion,
79
+ onLoaded: (event: EventData) => {
80
+ motion.onLoaded(event)
81
+ measure(event)
82
+ },
71
83
  onLayoutChanged: measure,
72
84
  onUnloaded: () => {
73
85
  motion.onUnloaded()
74
86
  width.value = undefined
75
87
  },
76
88
  style: {
89
+ // Flex growth/shrink needs an exact content width on native;
90
+ // a GridLayout's loose offer otherwise retains oversized columns.
91
+ width: '100%',
77
92
  flexDirection: direction.value,
78
93
  alignItems: align[layout.value.align ?? props.align],
79
94
  justifyContent: justify[layout.value.justify ?? props.justify],