@getcortexlabs/mavis 0.1.0-rc.13 → 0.1.0-rc.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/dist/components/bindings.d.ts +14 -0
- package/dist/components/bindings.d.ts.map +1 -0
- package/dist/components/bindings.js +21 -0
- package/dist/components/bindings.js.map +1 -0
- package/dist/components/contracts.d.ts +28 -0
- package/dist/components/contracts.d.ts.map +1 -0
- package/dist/components/contracts.js +27 -0
- package/dist/components/contracts.js.map +1 -0
- package/dist/components/controller.d.ts +56 -0
- package/dist/components/controller.d.ts.map +1 -0
- package/dist/components/controller.js +508 -0
- package/dist/components/controller.js.map +1 -0
- package/dist/components/index.d.ts +53 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +95 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/style.d.ts +52 -0
- package/dist/components/style.d.ts.map +1 -0
- package/dist/components/style.js +68 -0
- package/dist/components/style.js.map +1 -0
- package/dist/components/theme.d.ts +12 -0
- package/dist/components/theme.d.ts.map +1 -0
- package/dist/components/theme.js +29 -0
- package/dist/components/theme.js.map +1 -0
- package/dist/native/box.ios.d.ts +1 -0
- package/dist/native/box.ios.d.ts.map +1 -1
- package/dist/native/box.ios.js +21 -1
- package/dist/native/box.ios.js.map +1 -1
- package/dist/native/flex-layout.ios.d.ts.map +1 -1
- package/dist/native/flex-layout.ios.js +4 -0
- package/dist/native/flex-layout.ios.js.map +1 -1
- package/dist/native/motion-binding.d.ts +11 -0
- package/dist/native/motion-binding.d.ts.map +1 -0
- package/dist/native/motion-binding.js +132 -0
- package/dist/native/motion-binding.js.map +1 -0
- package/dist/native/motion-region.d.ts.map +1 -1
- package/dist/native/motion-region.js +1 -0
- package/dist/native/motion-region.js.map +1 -1
- package/dist/native/motion-surface.d.ts +1 -1
- package/dist/native/motion-surface.d.ts.map +1 -1
- package/dist/native/motion-surface.js +40 -8
- package/dist/native/motion-surface.js.map +1 -1
- package/dist/native/navigation.d.ts +4 -0
- package/dist/native/navigation.d.ts.map +1 -0
- package/dist/native/navigation.js +16 -0
- package/dist/native/navigation.js.map +1 -0
- package/dist/native/pointer-availability.d.ts +7 -0
- package/dist/native/pointer-availability.d.ts.map +1 -0
- package/dist/native/pointer-availability.js +43 -0
- package/dist/native/pointer-availability.js.map +1 -0
- package/dist/native/scroll-motion.d.ts +1 -1
- package/dist/native/scroll-motion.d.ts.map +1 -1
- package/dist/native/scroll-motion.js +55 -16
- package/dist/native/scroll-motion.js.map +1 -1
- package/dist/native/section-scroll.d.ts +1 -1
- package/dist/native/section-scroll.d.ts.map +1 -1
- package/dist/native/section-scroll.js +19 -6
- package/dist/native/section-scroll.js.map +1 -1
- package/dist/vue/card-input.d.ts +4 -0
- package/dist/vue/card-input.d.ts.map +1 -0
- package/dist/vue/card-input.js +37 -0
- package/dist/vue/card-input.js.map +1 -0
- package/dist/vue/components/ChoiceControl.d.ts +3 -3
- package/dist/vue/components/LoadingDecoration.d.ts +5 -5
- package/dist/vue/components/MAccordion.d.ts +3 -3
- package/dist/vue/components/MAlert.d.ts +4 -4
- package/dist/vue/components/MAvatar.d.ts +4 -4
- package/dist/vue/components/MBadge.d.ts +3 -3
- package/dist/vue/components/MButton.d.ts +20 -20
- package/dist/vue/components/MCard.d.ts +11 -11
- package/dist/vue/components/MCard.d.ts.map +1 -1
- package/dist/vue/components/MCard.js +3 -2
- package/dist/vue/components/MCard.js.map +1 -1
- package/dist/vue/components/MCheckbox.d.ts +3 -3
- package/dist/vue/components/MChip.d.ts +4 -4
- package/dist/vue/components/MCombobox.d.ts +5 -5
- package/dist/vue/components/MDatePicker.d.ts +96 -96
- package/dist/vue/components/MDatePicker.d.ts.map +1 -1
- package/dist/vue/components/MDialog.d.ts +3 -3
- package/dist/vue/components/MEmptyState.d.ts +3 -3
- package/dist/vue/components/MGrid.d.ts +7 -7
- package/dist/vue/components/MGrid.d.ts.map +1 -1
- package/dist/vue/components/MGrid.js +5 -1
- package/dist/vue/components/MGrid.js.map +1 -1
- package/dist/vue/components/MIcon.d.ts +2 -2
- package/dist/vue/components/MImage.d.ts +7 -7
- package/dist/vue/components/MImageCompare.d.ts +1 -1
- package/dist/vue/components/MInput.d.ts +22 -22
- package/dist/vue/components/MLink.d.ts +5 -5
- package/dist/vue/components/MListItem.d.ts +5 -5
- package/dist/vue/components/MPinInput.d.ts +1 -1
- package/dist/vue/components/MPopover.d.ts +3 -3
- package/dist/vue/components/MProgress.d.ts +5 -5
- package/dist/vue/components/MRadioGroup.d.ts +3 -3
- package/dist/vue/components/MRangeSlider.d.ts +1 -1
- package/dist/vue/components/MResizablePanels.d.ts +3 -3
- package/dist/vue/components/MReveal.d.ts +17 -17
- package/dist/vue/components/MScreen.d.ts +3 -3
- package/dist/vue/components/MScreen.d.ts.map +1 -1
- package/dist/vue/components/MScreen.js +11 -1
- package/dist/vue/components/MScreen.js.map +1 -1
- package/dist/vue/components/MSegmentedControl.d.ts +3 -3
- package/dist/vue/components/MSelect.d.ts +4 -4
- package/dist/vue/components/MSheet.d.ts +7 -7
- package/dist/vue/components/MSkeleton.d.ts +3 -3
- package/dist/vue/components/MSlider.d.ts +1 -1
- package/dist/vue/components/MStack.d.ts +19 -19
- package/dist/vue/components/MStack.d.ts.map +1 -1
- package/dist/vue/components/MStack.js +12 -2
- package/dist/vue/components/MStack.js.map +1 -1
- package/dist/vue/components/MSwitch.d.ts +3 -3
- package/dist/vue/components/MTabs.d.ts +3 -3
- package/dist/vue/components/MText.d.ts +8 -8
- package/dist/vue/components/MText.d.ts.map +1 -1
- package/dist/vue/components/MText.js +4 -1
- package/dist/vue/components/MText.js.map +1 -1
- package/dist/vue/components/MTimePicker.d.ts +40 -40
- package/dist/vue/components/MTimePicker.d.ts.map +1 -1
- package/dist/vue/components/MTooltip.d.ts +2 -2
- package/dist/vue/components/MVirtualList.d.ts.map +1 -1
- package/dist/vue/components/MVirtualList.js +88 -67
- package/dist/vue/components/MVirtualList.js.map +1 -1
- package/dist/vue/components/advanced.d.ts +34 -34
- package/dist/vue/components/configurator.d.ts +33 -33
- package/dist/vue/components/creative.d.ts +20 -20
- package/dist/vue/components/dashboard.d.ts +12 -12
- package/dist/vue/components/dashboard.d.ts.map +1 -1
- package/dist/vue/components/dashboard.js +185 -69
- package/dist/vue/components/dashboard.js.map +1 -1
- package/dist/vue/components/discovery.d.ts +10 -10
- package/dist/vue/components/interactive.d.ts +6 -6
- package/dist/vue/components/layout.d.ts +45 -45
- package/dist/vue/components/layout.d.ts.map +1 -1
- package/dist/vue/components/layout.js +8 -2
- package/dist/vue/components/layout.js.map +1 -1
- package/dist/vue/components/navigation.d.ts +4 -4
- package/dist/vue/components/screen-components.d.ts +23 -23
- package/dist/vue/components/screen-components.d.ts.map +1 -1
- package/dist/vue/components/screen-components.js +15 -0
- package/dist/vue/components/screen-components.js.map +1 -1
- package/dist/vue/components/wayfinding.d.ts +11 -11
- package/dist/vue/components/workflows.d.ts +5 -5
- package/dist/vue/layout-context.d.ts +4 -0
- package/dist/vue/layout-context.d.ts.map +1 -0
- package/dist/vue/layout-context.js +3 -0
- package/dist/vue/layout-context.js.map +1 -0
- package/dist/vue/navigation.d.ts +1 -3
- package/dist/vue/navigation.d.ts.map +1 -1
- package/dist/vue/navigation.js +1 -15
- package/dist/vue/navigation.js.map +1 -1
- package/dist/vue/screen-overlay.d.ts +9 -0
- package/dist/vue/screen-overlay.d.ts.map +1 -0
- package/dist/vue/screen-overlay.js +17 -0
- package/dist/vue/screen-overlay.js.map +1 -0
- package/dist/vue/use-motion-surface.d.ts +2 -3
- package/dist/vue/use-motion-surface.d.ts.map +1 -1
- package/dist/vue/use-motion-surface.js +9 -134
- package/dist/vue/use-motion-surface.js.map +1 -1
- package/package.json +8 -4
- package/platforms/android/java/com/mavis/ui/Box.java +31 -0
- package/src/components/bindings.ts +32 -0
- package/src/components/contracts.ts +60 -0
- package/src/components/controller.ts +542 -0
- package/src/components/index.ts +136 -0
- package/src/components/style.ts +84 -0
- package/src/components/theme.ts +25 -0
- package/src/native/box.ios.ts +31 -1
- package/src/native/flex-layout.ios.ts +4 -0
- package/src/native/motion-binding.ts +143 -0
- package/src/native/motion-region.ts +1 -0
- package/src/native/motion-surface.ts +41 -8
- package/src/native/navigation.ts +15 -0
- package/src/native/pointer-availability.ts +44 -0
- package/src/native/scroll-motion.ts +60 -19
- package/src/native/section-scroll.ts +16 -6
- package/src/vue/card-input.ts +44 -0
- package/src/vue/components/MCard.ts +4 -3
- package/src/vue/components/MGrid.ts +10 -1
- package/src/vue/components/MScreen.ts +12 -1
- package/src/vue/components/MStack.ts +17 -2
- package/src/vue/components/MText.ts +4 -1
- package/src/vue/components/MVirtualList.ts +104 -78
- package/src/vue/components/dashboard.ts +192 -69
- package/src/vue/components/layout.ts +8 -0
- package/src/vue/components/screen-components.ts +14 -0
- package/src/vue/layout-context.ts +4 -0
- package/src/vue/navigation.ts +1 -15
- package/src/vue/screen-overlay.ts +20 -0
- package/src/vue/use-motion-surface.ts +10 -137
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { TapGestureEventData, View } from '@nativescript/core'
|
|
2
|
+
|
|
3
|
+
/** A child's native control owns its hit; blank space still belongs to the card. */
|
|
4
|
+
export function ownsCardTap(event?: Partial<TapGestureEventData>): boolean {
|
|
5
|
+
const card = (event?.object ?? event?.view) as View | undefined
|
|
6
|
+
if (!card || !event?.getX || !event.getY) return true
|
|
7
|
+
const x = event.getX(),
|
|
8
|
+
y = event.getY()
|
|
9
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) return true
|
|
10
|
+
const containsControl = (view: View): boolean => {
|
|
11
|
+
if (view.visibility !== undefined && view.visibility !== 'visible') return false
|
|
12
|
+
if (
|
|
13
|
+
/^(MavisButton|Button|TextField|TextView|SearchBar|Switch|Slider|DatePicker|TimePicker|ListPicker|SegmentedBar|WebView)$/.test(
|
|
14
|
+
view.typeName,
|
|
15
|
+
) ||
|
|
16
|
+
['button', 'link', 'checkbox', 'radio', 'switch', 'slider', 'combobox', 'tab'].includes(
|
|
17
|
+
view.accessibilityRole,
|
|
18
|
+
)
|
|
19
|
+
) {
|
|
20
|
+
const origin = view.getLocationRelativeTo(card)
|
|
21
|
+
const size = view.getActualSize()
|
|
22
|
+
if (
|
|
23
|
+
origin &&
|
|
24
|
+
x >= origin.x &&
|
|
25
|
+
y >= origin.y &&
|
|
26
|
+
x <= origin.x + size.width &&
|
|
27
|
+
y <= origin.y + size.height
|
|
28
|
+
)
|
|
29
|
+
return true
|
|
30
|
+
}
|
|
31
|
+
let found = false
|
|
32
|
+
view.eachChildView?.((child) => {
|
|
33
|
+
found = containsControl(child)
|
|
34
|
+
return !found
|
|
35
|
+
})
|
|
36
|
+
return found
|
|
37
|
+
}
|
|
38
|
+
let found = false
|
|
39
|
+
card.eachChildView?.((child) => {
|
|
40
|
+
found = containsControl(child)
|
|
41
|
+
return !found
|
|
42
|
+
})
|
|
43
|
+
return !found
|
|
44
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { nativeDestination, navigateNative } from '../navigation.js'
|
|
2
|
+
import { ownsCardTap } from '../card-input.js'
|
|
2
3
|
import { resolveSpace, resolveRadius, shadowStyle } from '@getcortexlabs/mavis-core'
|
|
3
4
|
import { ActionChildren } from '../accessibility.js'
|
|
4
5
|
import { defineComponent, getCurrentInstance, h, mergeProps } from 'nativescript-vue'
|
|
@@ -13,7 +14,7 @@ import { MColumn } from './layout.js'
|
|
|
13
14
|
import { usePressFeedback } from '../use-press.js'
|
|
14
15
|
import { useMotionSurface } from '../use-motion-surface.js'
|
|
15
16
|
import { keepShadow } from '../../native/moved-shadow.js'
|
|
16
|
-
import type { EventData, View } from '@nativescript/core'
|
|
17
|
+
import type { EventData, TapGestureEventData, View } from '@nativescript/core'
|
|
17
18
|
|
|
18
19
|
export const MCard = defineComponent({
|
|
19
20
|
name: 'MCard',
|
|
@@ -90,8 +91,8 @@ export const MCard = defineComponent({
|
|
|
90
91
|
accessibilityRole: href !== undefined ? 'link' : interactive ? 'button' : '',
|
|
91
92
|
accessibilityState: interactive && disabled ? 'disabled' : '',
|
|
92
93
|
onTap: interactive
|
|
93
|
-
? () => {
|
|
94
|
-
if (enabled() && allowsActivation()) {
|
|
94
|
+
? (event?: TapGestureEventData) => {
|
|
95
|
+
if (enabled() && allowsActivation() && ownsCardTap(event)) {
|
|
95
96
|
emit('click')
|
|
96
97
|
if (href !== undefined)
|
|
97
98
|
void navigateNative(navigation()).catch((error) => emit('error', error))
|
|
@@ -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(
|
|
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
|
|
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()
|
|
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(
|
|
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],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, h, mergeProps, registerElement } from 'nativescript-vue'
|
|
1
|
+
import { defineComponent, h, inject, mergeProps, registerElement } from 'nativescript-vue'
|
|
2
2
|
import {
|
|
3
3
|
textProps,
|
|
4
4
|
useMavisTheme,
|
|
@@ -10,6 +10,7 @@ import { isAndroid } from '@nativescript/core'
|
|
|
10
10
|
import { MavisLabel } from '../../native/label'
|
|
11
11
|
import { useNativeViewAttrs } from '../accessibility.js'
|
|
12
12
|
import { useMotionSurface } from '../use-motion-surface.js'
|
|
13
|
+
import { boxLayer } from '../layout-context.js'
|
|
13
14
|
|
|
14
15
|
registerElement('MavisLabel', () => MavisLabel)
|
|
15
16
|
|
|
@@ -18,6 +19,7 @@ export const MText = defineComponent({
|
|
|
18
19
|
inheritAttrs: false,
|
|
19
20
|
props: textProps,
|
|
20
21
|
setup(props, { attrs, slots }) {
|
|
22
|
+
const layered = inject(boxLayer, false)
|
|
21
23
|
const { theme } = useMavisTheme()
|
|
22
24
|
const nativeAttrs = useNativeViewAttrs(props)
|
|
23
25
|
const shrink = useLayoutShrink()
|
|
@@ -44,6 +46,7 @@ export const MText = defineComponent({
|
|
|
44
46
|
accessible: true,
|
|
45
47
|
accessibilityRole: /^h[1-6]$/.test(props.as) ? 'header' : 'text',
|
|
46
48
|
style: {
|
|
49
|
+
...(layered ? { verticalAlignment: 'top' } : {}),
|
|
47
50
|
...type,
|
|
48
51
|
fontFamily: fontFamily(type.fontFamily, isAndroid ? 'android' : 'ios'),
|
|
49
52
|
fontWeight: props.weight ? validateWeight(props.weight) : type.fontWeight,
|
|
@@ -1,138 +1,164 @@
|
|
|
1
|
-
import { useComponentContent } from '@getcortexlabs/mavis-core/vue'
|
|
2
|
-
import { useMotionSurface } from '../use-motion-surface.js'
|
|
3
1
|
import type { VirtualListComponent } from '@getcortexlabs/mavis-core/vue'
|
|
4
2
|
import {
|
|
5
|
-
computed,
|
|
6
3
|
defineComponent,
|
|
7
4
|
h,
|
|
8
|
-
ListView,
|
|
9
5
|
mergeProps,
|
|
10
6
|
nextTick,
|
|
7
|
+
onBeforeUnmount,
|
|
8
|
+
registerElement,
|
|
11
9
|
shallowRef,
|
|
12
|
-
|
|
10
|
+
useItemTemplates,
|
|
13
11
|
watch,
|
|
14
12
|
} from 'nativescript-vue'
|
|
15
|
-
import {
|
|
16
|
-
|
|
13
|
+
import {
|
|
14
|
+
isAndroid,
|
|
15
|
+
ListView as NativeList,
|
|
16
|
+
type EventData,
|
|
17
|
+
type ItemEventData,
|
|
18
|
+
} from '@nativescript/core'
|
|
19
|
+
import { listChanges, type ListChanges } from '@rafaelaugusto/jolt'
|
|
20
|
+
import { useMavisTheme, virtualListProps } from '@getcortexlabs/mavis-core/vue'
|
|
17
21
|
import {
|
|
18
22
|
choiceKey,
|
|
23
|
+
componentMotion,
|
|
19
24
|
virtualKeys,
|
|
20
25
|
virtualWindow,
|
|
21
|
-
type VirtualItemSlot,
|
|
22
26
|
type VirtualListHandle,
|
|
23
27
|
} from '@getcortexlabs/mavis-core'
|
|
24
28
|
import { MText } from './MText.js'
|
|
25
29
|
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
const RealizedContent = defineComponent({
|
|
29
|
-
props: { revision: Number, height: Number },
|
|
30
|
-
setup(props, { slots }) {
|
|
31
|
-
const feedback = useComponentContent(() => props.revision, false)
|
|
32
|
-
const motion = useMotionSurface(() => feedback)
|
|
33
|
-
return () => h('GridLayout', { ...motion, height: props.height }, slots.default?.())
|
|
34
|
-
},
|
|
35
|
-
})
|
|
30
|
+
// Core owns placement/recycling. Vue owns the contents, with no independent items watcher.
|
|
31
|
+
registerElement('MavisVirtualList', () => NativeList, { viewFlags: 8 })
|
|
36
32
|
|
|
37
33
|
const VirtualList = defineComponent({
|
|
38
34
|
name: 'MVirtualList',
|
|
39
35
|
inheritAttrs: false,
|
|
40
36
|
props: virtualListProps,
|
|
41
37
|
setup(props, { attrs, slots, expose }) {
|
|
42
|
-
const
|
|
38
|
+
const { theme } = useMavisTheme()
|
|
43
39
|
const list = shallowRef<NativeList>()
|
|
44
|
-
|
|
40
|
+
let rendered: readonly unknown[] = [...props.items]
|
|
41
|
+
let controller: ListChanges<unknown> | undefined
|
|
45
42
|
let requested = props.initialIndex
|
|
43
|
+
const key = (item: unknown) => virtualKeys([item], props.itemKey)[0]!
|
|
44
|
+
const templates = useItemTemplates({
|
|
45
|
+
componentName: 'MVirtualList',
|
|
46
|
+
slots: {
|
|
47
|
+
default: ({ item, index }) => [
|
|
48
|
+
h('GridLayout', { height: props.rowHeight, bindingContext: item }, [
|
|
49
|
+
h(
|
|
50
|
+
'GridLayout',
|
|
51
|
+
{ key: choiceKey(key(item)), height: props.rowHeight },
|
|
52
|
+
slots.default?.({ item, index, itemKey: key(item) }),
|
|
53
|
+
),
|
|
54
|
+
]),
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
function renderItem(data: EventData) {
|
|
59
|
+
const event = data as ItemEventData
|
|
60
|
+
const item = rendered[event.index]
|
|
61
|
+
if (item === undefined) return
|
|
62
|
+
event.view = templates.renderCell(
|
|
63
|
+
{ item, index: event.index, even: event.index % 2 === 0, odd: event.index % 2 !== 0 },
|
|
64
|
+
event.view,
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
function clear() {
|
|
68
|
+
list.value?.off(NativeList.itemLoadingEvent, renderItem)
|
|
69
|
+
controller?.dispose()
|
|
70
|
+
controller = undefined
|
|
71
|
+
}
|
|
72
|
+
function attach() {
|
|
73
|
+
clear()
|
|
74
|
+
const view = list.value
|
|
75
|
+
if (!view?.isLoaded) return
|
|
76
|
+
controller = listChanges(view, {
|
|
77
|
+
key: (item) => choiceKey(key(item)),
|
|
78
|
+
rowHeight: props.rowHeight,
|
|
79
|
+
move: componentMotion(theme.value, 'layout'),
|
|
80
|
+
enter: true,
|
|
81
|
+
exit: 'fadeOut',
|
|
82
|
+
})
|
|
83
|
+
if (!props.animated) controller.pause()
|
|
84
|
+
// Jolt subscribed first: recycle notification clears the old key's motion
|
|
85
|
+
// before Vue patches the reused cell with another item.
|
|
86
|
+
view.on(NativeList.itemLoadingEvent, renderItem)
|
|
87
|
+
}
|
|
46
88
|
function scrollToIndex(index: number) {
|
|
47
89
|
if (!Number.isInteger(index) || index < 0 || index >= props.items.length)
|
|
48
90
|
throw new RangeError('List index is out of range.')
|
|
49
91
|
requested = index
|
|
92
|
+
controller?.stop()
|
|
50
93
|
list.value?.scrollToIndex(index)
|
|
51
94
|
}
|
|
52
95
|
expose({ scrollToIndex } satisfies VirtualListHandle)
|
|
53
96
|
watch(
|
|
54
|
-
|
|
55
|
-
(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
? view.android?.getFirstVisiblePosition()
|
|
61
|
-
: view.ios?.indexPathsForVisibleRows?.firstObject?.row
|
|
62
|
-
: requested
|
|
63
|
-
const key = previous[Math.max(0, first ?? requested)]
|
|
64
|
-
const index = key === undefined ? -1 : next.indexOf(key)
|
|
65
|
-
requested = Math.max(0, Math.min(index < 0 ? requested : index, next.length - 1))
|
|
66
|
-
void nextTick(() => {
|
|
67
|
-
if (next.length && view?.isLoaded) view.scrollToIndex(requested)
|
|
68
|
-
})
|
|
97
|
+
() => props.items.map((item) => ({ item, key: key(item) })),
|
|
98
|
+
() => {
|
|
99
|
+
virtualKeys(props.items, props.itemKey)
|
|
100
|
+
rendered = [...props.items]
|
|
101
|
+
if (controller && !controller.disposed) controller.update(rendered)
|
|
102
|
+
else if (list.value) list.value.items = [...rendered]
|
|
69
103
|
},
|
|
70
104
|
{ flush: 'pre' },
|
|
71
105
|
)
|
|
106
|
+
watch(
|
|
107
|
+
() => props.animated,
|
|
108
|
+
(enabled) => (enabled ? controller?.play() : controller?.pause()),
|
|
109
|
+
)
|
|
110
|
+
watch(
|
|
111
|
+
() => [props.rowHeight, props.height],
|
|
112
|
+
() => {
|
|
113
|
+
attach()
|
|
114
|
+
},
|
|
115
|
+
{ flush: 'post' },
|
|
116
|
+
)
|
|
117
|
+
onBeforeUnmount(clear)
|
|
72
118
|
return () => {
|
|
73
119
|
virtualWindow(props.items.length, props.rowHeight, props.height, 0, props.overscan)
|
|
74
|
-
|
|
120
|
+
virtualKeys(props.items, props.itemKey)
|
|
75
121
|
if (!props.label.trim()) throw new TypeError('Virtual lists require a label.')
|
|
76
122
|
if (!Number.isInteger(props.initialIndex) || props.initialIndex < 0)
|
|
77
123
|
throw new RangeError('initialIndex must be a nonnegative integer.')
|
|
78
|
-
if (!props.items.length)
|
|
79
|
-
return h(
|
|
80
|
-
'GridLayout',
|
|
81
|
-
mergeProps(attrs, {
|
|
82
|
-
id: props.id,
|
|
83
|
-
height: props.height,
|
|
84
|
-
accessibilityLabel: props.label,
|
|
85
|
-
}),
|
|
86
|
-
slots.empty?.() ?? [h(MText, { text: props.emptyLabel, tone: 'muted' })],
|
|
87
|
-
)
|
|
88
124
|
const content = h(
|
|
89
|
-
|
|
125
|
+
'MavisVirtualList',
|
|
90
126
|
mergeProps(attrs, {
|
|
91
127
|
id: props.id,
|
|
92
|
-
items: props.items,
|
|
93
128
|
rowHeight: props.rowHeight,
|
|
94
129
|
height: props.height,
|
|
95
130
|
separatorColor: 'transparent',
|
|
96
131
|
accessibilityLabel: props.label,
|
|
132
|
+
itemTemplates: templates.itemTemplates,
|
|
133
|
+
itemTemplateSelector: () => 'default',
|
|
97
134
|
onLoaded: (event: EventData) => {
|
|
98
|
-
list.value = event.object as NativeList
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
135
|
+
const view = (list.value = event.object as NativeList)
|
|
136
|
+
if (!isAndroid) view.rowHeight = 'auto'
|
|
137
|
+
view.rowHeight = props.rowHeight
|
|
138
|
+
rendered = [...props.items]
|
|
139
|
+
view.on(NativeList.itemLoadingEvent, renderItem)
|
|
140
|
+
view.items = [...rendered]
|
|
141
|
+
attach()
|
|
105
142
|
void nextTick(() => {
|
|
106
|
-
if (
|
|
107
|
-
|
|
143
|
+
if (view.isLoaded && rendered.length)
|
|
144
|
+
view.scrollToIndex(Math.min(requested, rendered.length - 1))
|
|
108
145
|
})
|
|
109
146
|
},
|
|
110
147
|
onUnloaded: () => {
|
|
148
|
+
clear()
|
|
111
149
|
list.value = undefined
|
|
112
150
|
},
|
|
113
151
|
}),
|
|
114
|
-
|
|
115
|
-
default: ({ item, index }: VirtualItemSlot) =>
|
|
116
|
-
h('GridLayout', { height: props.rowHeight }, [
|
|
117
|
-
// NativeScript owns cell reuse. A keyed child remounts local state when its logical item changes.
|
|
118
|
-
h(
|
|
119
|
-
RealizedContent,
|
|
120
|
-
{
|
|
121
|
-
key: choiceKey(keys.value[index]!),
|
|
122
|
-
height: props.rowHeight,
|
|
123
|
-
revision: revision.value,
|
|
124
|
-
},
|
|
125
|
-
() => slots.default?.({ item, index, itemKey: keys.value[index]! }),
|
|
126
|
-
),
|
|
127
|
-
]),
|
|
128
|
-
},
|
|
152
|
+
templates.cellVNodes(),
|
|
129
153
|
)
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
154
|
+
// The stable exact-size parent avoids iOS width-mode reloads and keeps the
|
|
155
|
+
// native list alive when the data becomes empty.
|
|
156
|
+
return h('GridLayout', { rows: '*', columns: '*', height: props.height }, [
|
|
157
|
+
content,
|
|
158
|
+
...(!props.items.length
|
|
159
|
+
? (slots.empty?.() ?? [h(MText, { text: props.emptyLabel, tone: 'muted' })])
|
|
160
|
+
: []),
|
|
161
|
+
])
|
|
136
162
|
}
|
|
137
163
|
},
|
|
138
164
|
})
|