@getcortexlabs/mavis 0.1.0-alpha.7 → 0.1.0-alpha.8
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 +5 -5
- package/dist/native/collection-motion.d.ts +5 -0
- package/dist/native/collection-motion.d.ts.map +1 -0
- package/dist/native/collection-motion.js +157 -0
- package/dist/native/collection-motion.js.map +1 -0
- package/dist/native/image-effects.d.ts +11 -0
- package/dist/native/image-effects.d.ts.map +1 -0
- package/dist/native/image-effects.js +61 -0
- package/dist/native/image-effects.js.map +1 -0
- package/dist/native/motion-region.d.ts.map +1 -1
- package/dist/native/motion-region.js +7 -2
- package/dist/native/motion-region.js.map +1 -1
- package/dist/native/motion-surface.d.ts +2 -2
- package/dist/native/motion-surface.d.ts.map +1 -1
- package/dist/native/motion-surface.js +44 -1
- package/dist/native/motion-surface.js.map +1 -1
- package/dist/native/platform-motion.d.ts +5 -0
- package/dist/native/platform-motion.d.ts.map +1 -0
- package/dist/native/platform-motion.js +90 -0
- package/dist/native/platform-motion.js.map +1 -0
- package/dist/native/surface-effects.d.ts +4 -0
- package/dist/native/surface-effects.d.ts.map +1 -0
- package/dist/native/surface-effects.js +31 -0
- package/dist/native/surface-effects.js.map +1 -0
- package/dist/native/visual-effects.d.ts +5 -0
- package/dist/native/visual-effects.d.ts.map +1 -0
- package/dist/native/visual-effects.js +126 -0
- package/dist/native/visual-effects.js.map +1 -0
- package/dist/vue/components/LoadingDecoration.d.ts +116 -0
- package/dist/vue/components/LoadingDecoration.d.ts.map +1 -0
- package/dist/vue/components/LoadingDecoration.js +34 -0
- package/dist/vue/components/LoadingDecoration.js.map +1 -0
- package/dist/vue/components/MAlert.d.ts +1 -1
- package/dist/vue/components/MAvatar.d.ts +1 -1
- package/dist/vue/components/MButton.d.ts +32 -10
- package/dist/vue/components/MButton.d.ts.map +1 -1
- package/dist/vue/components/MButton.js +29 -2
- package/dist/vue/components/MButton.js.map +1 -1
- package/dist/vue/components/MCard.d.ts +4 -4
- package/dist/vue/components/MChip.d.ts +1 -1
- package/dist/vue/components/MCombobox.d.ts +2 -2
- package/dist/vue/components/MDialog.d.ts +3 -0
- package/dist/vue/components/MDialog.d.ts.map +1 -1
- package/dist/vue/components/MEmptyState.d.ts +1 -1
- package/dist/vue/components/MIcon.d.ts +18 -0
- package/dist/vue/components/MIcon.d.ts.map +1 -1
- package/dist/vue/components/MIcon.js +13 -2
- package/dist/vue/components/MIcon.js.map +1 -1
- package/dist/vue/components/MImage.d.ts +12 -1
- package/dist/vue/components/MImage.d.ts.map +1 -1
- package/dist/vue/components/MImage.js +58 -3
- package/dist/vue/components/MImage.js.map +1 -1
- package/dist/vue/components/MInput.d.ts +4 -4
- package/dist/vue/components/MLink.d.ts +2 -2
- package/dist/vue/components/MListItem.d.ts +1 -1
- package/dist/vue/components/MReveal.d.ts +9 -9
- package/dist/vue/components/MScreen.d.ts +11 -1
- package/dist/vue/components/MScreen.d.ts.map +1 -1
- package/dist/vue/components/MScreen.js +26 -4
- package/dist/vue/components/MScreen.js.map +1 -1
- package/dist/vue/components/MSelect.d.ts +1 -1
- package/dist/vue/components/MSheet.d.ts +4 -4
- package/dist/vue/components/MSkeleton.d.ts +12 -1
- package/dist/vue/components/MSkeleton.d.ts.map +1 -1
- package/dist/vue/components/MSkeleton.js +5 -3
- package/dist/vue/components/MSkeleton.js.map +1 -1
- package/dist/vue/components/MStack.d.ts +9 -9
- package/dist/vue/components/MText.d.ts +11 -0
- package/dist/vue/components/MText.d.ts.map +1 -1
- package/dist/vue/components/MText.js +3 -1
- package/dist/vue/components/MText.js.map +1 -1
- package/dist/vue/components/layout.d.ts +30 -19
- package/dist/vue/components/layout.d.ts.map +1 -1
- package/dist/vue/components/layout.js +3 -1
- package/dist/vue/components/layout.js.map +1 -1
- package/dist/vue/use-motion-surface.d.ts +1 -1
- package/dist/vue/use-motion-surface.d.ts.map +1 -1
- package/dist/vue/use-motion-surface.js +31 -2
- package/dist/vue/use-motion-surface.js.map +1 -1
- package/package.json +3 -3
- package/src/native/collection-motion.ts +166 -0
- package/src/native/image-effects.ts +71 -0
- package/src/native/motion-region.ts +7 -2
- package/src/native/motion-surface.ts +51 -2
- package/src/native/platform-motion.ts +103 -0
- package/src/native/surface-effects.ts +33 -0
- package/src/native/visual-effects.ts +147 -0
- package/src/vue/components/LoadingDecoration.ts +38 -0
- package/src/vue/components/MButton.ts +33 -2
- package/src/vue/components/MIcon.ts +14 -2
- package/src/vue/components/MImage.ts +66 -2
- package/src/vue/components/MScreen.ts +31 -3
- package/src/vue/components/MSkeleton.ts +5 -3
- package/src/vue/components/MText.ts +7 -0
- package/src/vue/components/layout.ts +3 -0
- package/src/vue/use-motion-surface.ts +32 -1
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Label, Image, isIOS, type View } from '@nativescript/core'
|
|
2
|
+
import { nativeSurfaceEffects } from './surface-effects.js'
|
|
3
|
+
import {
|
|
4
|
+
gradient,
|
|
5
|
+
shimmer,
|
|
6
|
+
loader,
|
|
7
|
+
reveal,
|
|
8
|
+
conceal,
|
|
9
|
+
animateText,
|
|
10
|
+
rollTo,
|
|
11
|
+
type DerivedValue,
|
|
12
|
+
type DerivedColor,
|
|
13
|
+
} from '@rafaelaugusto/jolt'
|
|
14
|
+
import {
|
|
15
|
+
mapGradientBindings,
|
|
16
|
+
type MotionVisualAdapter,
|
|
17
|
+
type MotionCircular,
|
|
18
|
+
type MotionPlayback,
|
|
19
|
+
} from '@getcortexlabs/mavis-core/experimental'
|
|
20
|
+
|
|
21
|
+
const circles = new WeakMap<View, { dispose(): void }>()
|
|
22
|
+
export function nativeVisualEffects(
|
|
23
|
+
target: View,
|
|
24
|
+
sources: WeakMap<object, DerivedValue>,
|
|
25
|
+
colors: WeakMap<object, DerivedColor>,
|
|
26
|
+
plainText: () => boolean,
|
|
27
|
+
): MotionVisualAdapter {
|
|
28
|
+
const text = () => {
|
|
29
|
+
if (!plainText() || !(target instanceof Label) || target.formattedText)
|
|
30
|
+
throw new TypeError(
|
|
31
|
+
'Declare a motionSurface on MText with an explicit text prop; rich/slotted text is unsupported.',
|
|
32
|
+
)
|
|
33
|
+
return target
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
...nativeSurfaceEffects(target),
|
|
37
|
+
supports: (effect) => {
|
|
38
|
+
if (effect === 'text') return plainText()
|
|
39
|
+
if (effect === 'symbol')
|
|
40
|
+
return isIOS && target instanceof Image && Boolean(target.ios?.image?.symbolImage)
|
|
41
|
+
if (effect === 'image') return target instanceof Image
|
|
42
|
+
if (effect === 'liquid') return isIOS && target instanceof Image
|
|
43
|
+
return (
|
|
44
|
+
['gradient', 'particles', 'confetti', 'blur', 'shape', 'keyboard'].includes(effect) || isIOS
|
|
45
|
+
)
|
|
46
|
+
},
|
|
47
|
+
gradient(options) {
|
|
48
|
+
const paint = gradient(target, options)
|
|
49
|
+
return {
|
|
50
|
+
type: paint.type,
|
|
51
|
+
get suspended() {
|
|
52
|
+
return paint.suspended
|
|
53
|
+
},
|
|
54
|
+
animate: (values, options) => paint.animate(values, options),
|
|
55
|
+
set: (values) => paint.set(values),
|
|
56
|
+
stop: () => paint.stop(),
|
|
57
|
+
suspend: () => paint.suspend(),
|
|
58
|
+
resume: () => paint.resume(),
|
|
59
|
+
bind(values) {
|
|
60
|
+
const dispose = paint.bind(
|
|
61
|
+
mapGradientBindings(
|
|
62
|
+
values,
|
|
63
|
+
(value) => sources.get(value)!,
|
|
64
|
+
(value) => colors.get(value)!,
|
|
65
|
+
),
|
|
66
|
+
)
|
|
67
|
+
return { dispose }
|
|
68
|
+
},
|
|
69
|
+
dispose: () => paint.remove(),
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
shimmer: (options) => ({ supported: isIOS, dispose: shimmer(target, options) }),
|
|
73
|
+
loader: (options) => ({ supported: isIOS, dispose: loader(target, options) }),
|
|
74
|
+
animateText: (options) => animateText(text(), options),
|
|
75
|
+
rollTo: (value, options) => rollTo(text(), value, options),
|
|
76
|
+
circular() {
|
|
77
|
+
circles.get(target)?.dispose()
|
|
78
|
+
const hidden = target.accessibilityHidden,
|
|
79
|
+
interactive = target.isUserInteractionEnabled
|
|
80
|
+
const visibility = target.visibility
|
|
81
|
+
let active: MotionPlayback | undefined,
|
|
82
|
+
locked = false,
|
|
83
|
+
generation = 0,
|
|
84
|
+
disposed = false
|
|
85
|
+
let writtenVisibility: View['visibility'] | undefined
|
|
86
|
+
const focused = (view: View): boolean => {
|
|
87
|
+
if (view.ios?.isFirstResponder) return true
|
|
88
|
+
let found = false
|
|
89
|
+
view.eachChildView((child) => {
|
|
90
|
+
found = focused(child)
|
|
91
|
+
return !found
|
|
92
|
+
})
|
|
93
|
+
return found
|
|
94
|
+
}
|
|
95
|
+
const unlock = () => {
|
|
96
|
+
if (!locked) return
|
|
97
|
+
locked = false
|
|
98
|
+
if (target.accessibilityHidden) target.accessibilityHidden = hidden
|
|
99
|
+
if (!target.isUserInteractionEnabled) target.isUserInteractionEnabled = interactive
|
|
100
|
+
}
|
|
101
|
+
const run = (open: boolean, options: Parameters<MotionCircular['reveal']>[0] = {}) => {
|
|
102
|
+
if (isIOS && !open && focused(target))
|
|
103
|
+
throw new Error('Move focus outside the circular surface before conceal().')
|
|
104
|
+
const handle = open
|
|
105
|
+
? reveal(target, { from: options.origin, duration: options.duration })
|
|
106
|
+
: conceal(target, { to: options.origin, duration: options.duration })
|
|
107
|
+
const token = ++generation
|
|
108
|
+
active = handle
|
|
109
|
+
if (isIOS) writtenVisibility = target.visibility
|
|
110
|
+
if (isIOS) {
|
|
111
|
+
if (open) unlock()
|
|
112
|
+
else {
|
|
113
|
+
locked = true
|
|
114
|
+
target.accessibilityHidden = true
|
|
115
|
+
target.isUserInteractionEnabled = false
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
void handle.finished.then((completed) => {
|
|
119
|
+
if (token !== generation || disposed) return
|
|
120
|
+
active = undefined
|
|
121
|
+
if (completed && isIOS) writtenVisibility = target.visibility
|
|
122
|
+
if (!completed && target.visibility !== 'hidden') unlock()
|
|
123
|
+
})
|
|
124
|
+
return handle
|
|
125
|
+
}
|
|
126
|
+
const control = {
|
|
127
|
+
supported: isIOS,
|
|
128
|
+
reveal: (options?: Parameters<MotionCircular['reveal']>[0]) => run(true, options),
|
|
129
|
+
conceal: (options?: Parameters<MotionCircular['conceal']>[0]) => run(false, options),
|
|
130
|
+
dispose() {
|
|
131
|
+
if (disposed) return
|
|
132
|
+
disposed = true
|
|
133
|
+
generation++
|
|
134
|
+
active?.stop()
|
|
135
|
+
unlock()
|
|
136
|
+
if (circles.get(target) === control) {
|
|
137
|
+
circles.delete(target)
|
|
138
|
+
if (isIOS && writtenVisibility !== undefined && target.visibility === writtenVisibility)
|
|
139
|
+
target.visibility = visibility
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
}
|
|
143
|
+
circles.set(target, control)
|
|
144
|
+
return control
|
|
145
|
+
},
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { defineComponent, h, mergeProps, type PropType } from 'nativescript-vue'
|
|
2
|
+
import { skeletonProps, useLoadingDecoration } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
import { MBox } from './layout.js'
|
|
4
|
+
|
|
5
|
+
export const LoadingDecoration = defineComponent({
|
|
6
|
+
name: 'MavisLoadingDecoration',
|
|
7
|
+
inheritAttrs: false,
|
|
8
|
+
props: {
|
|
9
|
+
...skeletonProps,
|
|
10
|
+
kind: { type: String as PropType<'shimmer' | 'dots' | 'bars' | 'ring'>, required: true },
|
|
11
|
+
color: { type: String, default: undefined },
|
|
12
|
+
size: { type: Number, default: 24 },
|
|
13
|
+
},
|
|
14
|
+
setup(props, { attrs }) {
|
|
15
|
+
const surface = useLoadingDecoration(() => ({
|
|
16
|
+
kind: props.kind,
|
|
17
|
+
animated: props.animated,
|
|
18
|
+
size: props.size,
|
|
19
|
+
color: props.color,
|
|
20
|
+
}))
|
|
21
|
+
return () =>
|
|
22
|
+
h(
|
|
23
|
+
MBox,
|
|
24
|
+
mergeProps(attrs, {
|
|
25
|
+
id: props.id,
|
|
26
|
+
width: props.width,
|
|
27
|
+
height: props.height,
|
|
28
|
+
radius: props.radius,
|
|
29
|
+
grow: props.grow,
|
|
30
|
+
shrink: props.shrink,
|
|
31
|
+
motionSurface: surface,
|
|
32
|
+
accessibilityHidden: true,
|
|
33
|
+
accessible: false,
|
|
34
|
+
isUserInteractionEnabled: false,
|
|
35
|
+
}),
|
|
36
|
+
)
|
|
37
|
+
},
|
|
38
|
+
})
|
|
@@ -39,8 +39,11 @@ import { useMotionSurface } from '../use-motion-surface.js'
|
|
|
39
39
|
import { usePressFeedback } from '../use-press.js'
|
|
40
40
|
import { MavisButton } from '../../native/button'
|
|
41
41
|
import { useNativeViewAttrs } from '../accessibility.js'
|
|
42
|
+
import { LoadingDecoration } from './LoadingDecoration.js'
|
|
43
|
+
import { ReorderHandle } from '@rafaelaugusto/jolt/reorder'
|
|
42
44
|
|
|
43
45
|
registerElement('MavisButton', () => MavisButton)
|
|
46
|
+
registerElement('MavisReorderHandle', () => ReorderHandle)
|
|
44
47
|
|
|
45
48
|
export const MButton = defineComponent({
|
|
46
49
|
name: 'MButton',
|
|
@@ -76,6 +79,18 @@ export const MButton = defineComponent({
|
|
|
76
79
|
void navigateNative(props).catch((error) => emit('error', error))
|
|
77
80
|
}
|
|
78
81
|
return () => {
|
|
82
|
+
if (
|
|
83
|
+
props.reorderHandle &&
|
|
84
|
+
(slots.leading ||
|
|
85
|
+
slots.trailing ||
|
|
86
|
+
props.icon ||
|
|
87
|
+
props.trailingIcon ||
|
|
88
|
+
props.href ||
|
|
89
|
+
props.loadingIndicator !== 'none')
|
|
90
|
+
)
|
|
91
|
+
throw new TypeError(
|
|
92
|
+
'A reorder handle requires a plain-text MButton without navigation or adornments.',
|
|
93
|
+
)
|
|
79
94
|
if (props.href !== undefined) nativeDestination(props)
|
|
80
95
|
const { colors, control, radius } = theme.value
|
|
81
96
|
const tokens = theme.value.components.button
|
|
@@ -90,8 +105,12 @@ export const MButton = defineComponent({
|
|
|
90
105
|
: (props.text ?? textContent(slots.default?.()))
|
|
91
106
|
const leading = buttonContent(slots.leading?.())
|
|
92
107
|
const trailing = buttonContent(slots.trailing?.())
|
|
108
|
+
const indicator = props.loading && props.loadingIndicator !== 'none' && !isAndroid
|
|
93
109
|
const composed = Boolean(
|
|
94
|
-
slots.leading ||
|
|
110
|
+
slots.leading ||
|
|
111
|
+
slots.trailing ||
|
|
112
|
+
indicator ||
|
|
113
|
+
(isAndroid && (props.icon || props.trailingIcon)),
|
|
95
114
|
)
|
|
96
115
|
const hasIcon = Boolean(composed || props.icon || props.trailingIcon)
|
|
97
116
|
checkIconOnly(text, hasIcon, props.accessibilityLabel)
|
|
@@ -187,6 +206,18 @@ export const MButton = defineComponent({
|
|
|
187
206
|
{ hidden: true },
|
|
188
207
|
{
|
|
189
208
|
default: () => [
|
|
209
|
+
...(indicator
|
|
210
|
+
? [
|
|
211
|
+
h(LoadingDecoration, {
|
|
212
|
+
kind: props.loadingIndicator as 'dots' | 'bars' | 'ring',
|
|
213
|
+
width: iconSize,
|
|
214
|
+
height: iconSize,
|
|
215
|
+
size: iconSize,
|
|
216
|
+
color: primary ? colors.onPrimary : colors.text,
|
|
217
|
+
radius: 'none',
|
|
218
|
+
}),
|
|
219
|
+
]
|
|
220
|
+
: []),
|
|
190
221
|
slots.leading
|
|
191
222
|
? adornment(leading)
|
|
192
223
|
: props.icon
|
|
@@ -218,7 +249,7 @@ export const MButton = defineComponent({
|
|
|
218
249
|
)
|
|
219
250
|
}
|
|
220
251
|
return h(
|
|
221
|
-
'MavisButton',
|
|
252
|
+
props.reorderHandle ? 'MavisReorderHandle' : 'MavisButton',
|
|
222
253
|
mergeProps(
|
|
223
254
|
{
|
|
224
255
|
// Android builds the accessible description from the current text.
|
|
@@ -2,6 +2,8 @@ import { defineComponent, h, mergeProps, registerElement } from 'nativescript-vu
|
|
|
2
2
|
import { iconProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
3
3
|
import { iconFontFamily, iconGlyph, resolveIconSize } from '@getcortexlabs/mavis-core'
|
|
4
4
|
import { MavisLabel } from '../../native/label'
|
|
5
|
+
import { isIOS } from '@nativescript/core'
|
|
6
|
+
import { useMotionSurface } from '../use-motion-surface.js'
|
|
5
7
|
|
|
6
8
|
registerElement('MavisIcon', () => MavisLabel)
|
|
7
9
|
|
|
@@ -11,14 +13,24 @@ export const MIcon = defineComponent({
|
|
|
11
13
|
props: iconProps,
|
|
12
14
|
setup(props, { attrs }) {
|
|
13
15
|
const { theme } = useMavisTheme()
|
|
16
|
+
const motion = useMotionSurface(() => props.motionSurface)
|
|
14
17
|
return () => {
|
|
15
18
|
const size = resolveIconSize(props.size)
|
|
16
19
|
return h(
|
|
17
|
-
'MavisIcon',
|
|
20
|
+
props.systemName && isIOS ? 'Image' : 'MavisIcon',
|
|
18
21
|
mergeProps(
|
|
22
|
+
{ onLoaded: motion.onLoaded, onUnloaded: motion.onUnloaded },
|
|
19
23
|
{
|
|
20
24
|
id: props.id,
|
|
21
|
-
|
|
25
|
+
key: props.systemName && isIOS ? props.systemName : 'glyph',
|
|
26
|
+
...(props.systemName && isIOS
|
|
27
|
+
? {
|
|
28
|
+
src: `sys://${props.systemName}`,
|
|
29
|
+
width: size,
|
|
30
|
+
height: size,
|
|
31
|
+
tintColor: theme.value.colors[props.tone],
|
|
32
|
+
}
|
|
33
|
+
: { text: iconGlyph(props.name) }),
|
|
22
34
|
textWrap: false,
|
|
23
35
|
accessible: Boolean(props.label),
|
|
24
36
|
accessibilityHidden: !props.label,
|
|
@@ -2,23 +2,30 @@ import {
|
|
|
2
2
|
defineComponent,
|
|
3
3
|
h,
|
|
4
4
|
mergeProps,
|
|
5
|
+
nextTick,
|
|
5
6
|
onBeforeUnmount,
|
|
6
7
|
ref,
|
|
7
8
|
shallowRef,
|
|
8
9
|
watch,
|
|
9
10
|
} from 'nativescript-vue'
|
|
10
|
-
import type { EventData, View, ImageSource } from '@nativescript/core'
|
|
11
|
+
import type { EventData, View, ImageSource, Image } from '@nativescript/core'
|
|
11
12
|
import { imageProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
12
13
|
import { resolveRadius } from '@getcortexlabs/mavis-core'
|
|
13
14
|
import { loadAvatarImage } from '../../native/avatar-image'
|
|
14
15
|
import { MBox } from './layout.js'
|
|
15
16
|
import { MText } from './MText.js'
|
|
17
|
+
import { useMotionSurface } from '../use-motion-surface.js'
|
|
18
|
+
import { registerMotionImage } from '../../native/image-effects.js'
|
|
16
19
|
|
|
17
20
|
export const MImage = defineComponent({
|
|
18
21
|
name: 'MImage',
|
|
19
22
|
inheritAttrs: false,
|
|
20
23
|
props: imageProps,
|
|
21
|
-
emits: {
|
|
24
|
+
emits: {
|
|
25
|
+
load: (_src: string) => true,
|
|
26
|
+
error: (_src: string) => true,
|
|
27
|
+
'update:src': (_src: string) => true,
|
|
28
|
+
},
|
|
22
29
|
setup(props, { attrs, emit }) {
|
|
23
30
|
const { theme } = useMavisTheme()
|
|
24
31
|
const image = shallowRef<ImageSource | null>(null)
|
|
@@ -26,6 +33,15 @@ export const MImage = defineComponent({
|
|
|
26
33
|
const width = ref(typeof props.width === 'number' ? props.width : 0)
|
|
27
34
|
let generation = 0,
|
|
28
35
|
loaded = false
|
|
36
|
+
let releaseImage: (() => void) | undefined,
|
|
37
|
+
committing: string | undefined,
|
|
38
|
+
currentImage: Image | undefined
|
|
39
|
+
const motion = useMotionSurface(
|
|
40
|
+
() => props.motionSurface,
|
|
41
|
+
() => true,
|
|
42
|
+
() => false,
|
|
43
|
+
true,
|
|
44
|
+
)
|
|
29
45
|
async function load() {
|
|
30
46
|
const current = ++generation,
|
|
31
47
|
src = props.src
|
|
@@ -47,6 +63,10 @@ export const MImage = defineComponent({
|
|
|
47
63
|
}
|
|
48
64
|
}
|
|
49
65
|
function unload() {
|
|
66
|
+
motion.onUnloaded()
|
|
67
|
+
releaseImage?.()
|
|
68
|
+
releaseImage = undefined
|
|
69
|
+
currentImage = undefined
|
|
50
70
|
loaded = false
|
|
51
71
|
generation++
|
|
52
72
|
image.value = null
|
|
@@ -54,8 +74,13 @@ export const MImage = defineComponent({
|
|
|
54
74
|
watch(
|
|
55
75
|
() => props.src,
|
|
56
76
|
() => {
|
|
77
|
+
if (props.src === committing) {
|
|
78
|
+
committing = undefined
|
|
79
|
+
return
|
|
80
|
+
}
|
|
57
81
|
void load()
|
|
58
82
|
},
|
|
83
|
+
{ flush: 'sync' },
|
|
59
84
|
)
|
|
60
85
|
onBeforeUnmount(unload)
|
|
61
86
|
return () => {
|
|
@@ -66,6 +91,7 @@ export const MImage = defineComponent({
|
|
|
66
91
|
MBox,
|
|
67
92
|
mergeProps(attrs, {
|
|
68
93
|
...props,
|
|
94
|
+
motionSurface: undefined,
|
|
69
95
|
width: props.width ?? '100%',
|
|
70
96
|
height: props.height ?? width.value / props.aspectRatio,
|
|
71
97
|
backgroundColor: props.backgroundColor || theme.value.colors.elevated,
|
|
@@ -93,6 +119,7 @@ export const MImage = defineComponent({
|
|
|
93
119
|
image.value
|
|
94
120
|
? [
|
|
95
121
|
h('Image', {
|
|
122
|
+
key: generation,
|
|
96
123
|
imageSource: image.value,
|
|
97
124
|
width: '100%',
|
|
98
125
|
height: '100%',
|
|
@@ -100,6 +127,43 @@ export const MImage = defineComponent({
|
|
|
100
127
|
borderRadius: radius,
|
|
101
128
|
accessible: false,
|
|
102
129
|
accessibilityHidden: true,
|
|
130
|
+
onLoaded(event: EventData) {
|
|
131
|
+
const target = event.object as Image,
|
|
132
|
+
current = generation
|
|
133
|
+
currentImage = target
|
|
134
|
+
releaseImage?.()
|
|
135
|
+
releaseImage = registerMotionImage(target, {
|
|
136
|
+
current: () =>
|
|
137
|
+
loaded &&
|
|
138
|
+
current === generation &&
|
|
139
|
+
currentImage === target &&
|
|
140
|
+
target.isLoaded,
|
|
141
|
+
async commit(destination, prepared) {
|
|
142
|
+
if (!loaded || current !== generation) return false
|
|
143
|
+
const previous = image.value
|
|
144
|
+
image.value = prepared ?? null
|
|
145
|
+
committing = destination
|
|
146
|
+
emit('update:src', destination)
|
|
147
|
+
await nextTick()
|
|
148
|
+
const accepted =
|
|
149
|
+
loaded && current === generation && props.src === destination
|
|
150
|
+
committing = undefined
|
|
151
|
+
if (!accepted && current === generation) {
|
|
152
|
+
image.value = previous
|
|
153
|
+
if (previous) target.imageSource = previous
|
|
154
|
+
}
|
|
155
|
+
return accepted
|
|
156
|
+
},
|
|
157
|
+
})
|
|
158
|
+
motion.onLoaded(event)
|
|
159
|
+
},
|
|
160
|
+
onUnloaded(event: EventData) {
|
|
161
|
+
if (event.object !== currentImage) return
|
|
162
|
+
motion.onUnloaded()
|
|
163
|
+
releaseImage?.()
|
|
164
|
+
releaseImage = undefined
|
|
165
|
+
currentImage = undefined
|
|
166
|
+
},
|
|
103
167
|
}),
|
|
104
168
|
]
|
|
105
169
|
: [
|
|
@@ -3,12 +3,15 @@ import { useAppToastHost } from '@getcortexlabs/mavis-core/vue'
|
|
|
3
3
|
import { MToast } from './MToast.js'
|
|
4
4
|
import {
|
|
5
5
|
defineComponent,
|
|
6
|
+
cloneVNode,
|
|
7
|
+
Fragment,
|
|
6
8
|
h,
|
|
7
9
|
mergeProps,
|
|
8
10
|
onBeforeUnmount,
|
|
9
11
|
provide,
|
|
10
12
|
registerElement,
|
|
11
13
|
watch,
|
|
14
|
+
type VNode,
|
|
12
15
|
} from 'nativescript-vue'
|
|
13
16
|
import { isIOS, type EventData, type View } from '@nativescript/core'
|
|
14
17
|
import { screenProps, useMavisTheme, layoutDirection } from '@getcortexlabs/mavis-core/vue'
|
|
@@ -19,6 +22,7 @@ import { dismissKeyboardOn } from '../../native/keyboard-dismiss'
|
|
|
19
22
|
import { useNativeViewAttrs } from '../accessibility.js'
|
|
20
23
|
import { provideLayerHost } from '../layers.js'
|
|
21
24
|
import { expandLayerHost } from '../../native/sheet'
|
|
25
|
+
import { useMotionRegion } from '../use-motion-region.js'
|
|
22
26
|
|
|
23
27
|
registerElement('MavisScreenScroll', () => MavisScreenScroll, {
|
|
24
28
|
// NSVViewFlags.CONTENT_VIEW; ScrollView owns one content view.
|
|
@@ -27,11 +31,29 @@ registerElement('MavisScreenScroll', () => MavisScreenScroll, {
|
|
|
27
31
|
// NSVViewFlags.LAYOUT_VIEW; the page container also puts the keyboard away.
|
|
28
32
|
registerElement('MavisScreen', () => MavisScreen, { viewFlags: 4 })
|
|
29
33
|
|
|
34
|
+
// Overlay children must remain siblings of the ScrollView for retained headers.
|
|
35
|
+
function placeOverlay(node: VNode, covered: boolean): VNode {
|
|
36
|
+
if (node.type !== Fragment)
|
|
37
|
+
return cloneVNode(node, {
|
|
38
|
+
iosOverflowSafeArea: false,
|
|
39
|
+
...(covered ? { accessibilityHidden: true } : {}),
|
|
40
|
+
})
|
|
41
|
+
const copy = cloneVNode(node)
|
|
42
|
+
if (Array.isArray(copy.children))
|
|
43
|
+
copy.children = copy.children.map((child) =>
|
|
44
|
+
child && typeof child === 'object' && 'type' in child
|
|
45
|
+
? placeOverlay(child as VNode, covered)
|
|
46
|
+
: child,
|
|
47
|
+
)
|
|
48
|
+
return copy
|
|
49
|
+
}
|
|
50
|
+
|
|
30
51
|
export const MScreen = defineComponent({
|
|
31
52
|
name: 'MScreen',
|
|
32
53
|
inheritAttrs: false,
|
|
33
54
|
props: screenProps,
|
|
34
55
|
setup(props, { attrs, slots }) {
|
|
56
|
+
const region = useMotionRegion(() => props.motionRegion)
|
|
35
57
|
const scrollMotion = useScrollMotion(() => props.motionScroll)
|
|
36
58
|
const { theme } = useMavisTheme()
|
|
37
59
|
const appToast = useAppToastHost()
|
|
@@ -60,7 +82,12 @@ export const MScreen = defineComponent({
|
|
|
60
82
|
// Page and ScrollView require one content view; the column also accepts multiple slot children.
|
|
61
83
|
const content = h(
|
|
62
84
|
MColumn,
|
|
63
|
-
{
|
|
85
|
+
{
|
|
86
|
+
accessibilityHidden: props.scroll ? undefined : covered,
|
|
87
|
+
// The retained scroll header reserves its spacer on this private host.
|
|
88
|
+
// Core's unset padding is not a numeric DIP value in every runtime.
|
|
89
|
+
style: { paddingTop: 0 },
|
|
90
|
+
},
|
|
64
91
|
{
|
|
65
92
|
default: () => [
|
|
66
93
|
slots.default?.(),
|
|
@@ -85,7 +112,7 @@ export const MScreen = defineComponent({
|
|
|
85
112
|
[
|
|
86
113
|
h(
|
|
87
114
|
'MavisScreen',
|
|
88
|
-
{
|
|
115
|
+
mergeProps(region, {
|
|
89
116
|
...(isIOS ? { clipToBounds: false } : {}),
|
|
90
117
|
onLoaded: (event: EventData) => {
|
|
91
118
|
container = event.object as View
|
|
@@ -96,7 +123,7 @@ export const MScreen = defineComponent({
|
|
|
96
123
|
release = undefined
|
|
97
124
|
container = undefined
|
|
98
125
|
},
|
|
99
|
-
},
|
|
126
|
+
}),
|
|
100
127
|
[
|
|
101
128
|
props.scroll
|
|
102
129
|
? h(
|
|
@@ -105,6 +132,7 @@ export const MScreen = defineComponent({
|
|
|
105
132
|
[content],
|
|
106
133
|
)
|
|
107
134
|
: content,
|
|
135
|
+
slots.overlay?.().map((node) => placeOverlay(node, covered)),
|
|
108
136
|
...notices.map((layer) =>
|
|
109
137
|
h(layer.component, { ...layer.props, covered, key: layer.key }),
|
|
110
138
|
),
|
|
@@ -3,6 +3,7 @@ import { Application, type EventData, type View } from '@nativescript/core'
|
|
|
3
3
|
import { animate, onReducedMotion, reducedMotion, set } from '@rafaelaugusto/jolt'
|
|
4
4
|
import { skeletonProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
5
5
|
import { MBox } from './layout.js'
|
|
6
|
+
import { LoadingDecoration } from './LoadingDecoration.js'
|
|
6
7
|
|
|
7
8
|
export const MSkeleton = defineComponent({
|
|
8
9
|
name: 'MSkeleton',
|
|
@@ -71,7 +72,7 @@ export const MSkeleton = defineComponent({
|
|
|
71
72
|
|
|
72
73
|
return () =>
|
|
73
74
|
h(
|
|
74
|
-
MBox,
|
|
75
|
+
props.effect === 'shimmer' ? LoadingDecoration : MBox,
|
|
75
76
|
mergeProps(
|
|
76
77
|
{
|
|
77
78
|
style: {
|
|
@@ -91,8 +92,9 @@ export const MSkeleton = defineComponent({
|
|
|
91
92
|
accessible: false,
|
|
92
93
|
accessibilityHidden: true,
|
|
93
94
|
isUserInteractionEnabled: false,
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
...(props.effect === 'shimmer'
|
|
96
|
+
? { kind: 'shimmer', animated: props.animated }
|
|
97
|
+
: { onLoaded: loaded, onUnloaded: release }),
|
|
96
98
|
},
|
|
97
99
|
),
|
|
98
100
|
)
|
|
@@ -9,6 +9,7 @@ import { fontFamily, nonNegative, validateWeight } from '@getcortexlabs/mavis-co
|
|
|
9
9
|
import { isAndroid } from '@nativescript/core'
|
|
10
10
|
import { MavisLabel } from '../../native/label'
|
|
11
11
|
import { useNativeViewAttrs } from '../accessibility.js'
|
|
12
|
+
import { useMotionSurface } from '../use-motion-surface.js'
|
|
12
13
|
|
|
13
14
|
registerElement('MavisLabel', () => MavisLabel)
|
|
14
15
|
|
|
@@ -20,6 +21,11 @@ export const MText = defineComponent({
|
|
|
20
21
|
const { theme } = useMavisTheme()
|
|
21
22
|
const nativeAttrs = useNativeViewAttrs(props)
|
|
22
23
|
const shrink = useLayoutShrink()
|
|
24
|
+
const motion = useMotionSurface(
|
|
25
|
+
() => props.motionSurface,
|
|
26
|
+
() => true,
|
|
27
|
+
() => props.text !== undefined,
|
|
28
|
+
)
|
|
23
29
|
return () => {
|
|
24
30
|
const type = theme.value.typography[props.variant]
|
|
25
31
|
const runs =
|
|
@@ -52,6 +58,7 @@ export const MText = defineComponent({
|
|
|
52
58
|
},
|
|
53
59
|
nativeAttrs(),
|
|
54
60
|
attrs,
|
|
61
|
+
{ onLoaded: motion.onLoaded, onUnloaded: motion.onUnloaded },
|
|
55
62
|
),
|
|
56
63
|
formatted
|
|
57
64
|
? [
|
|
@@ -13,6 +13,7 @@ import { MavisFlexLayout } from '../../native/flex-layout'
|
|
|
13
13
|
import { MavisBox } from '../../native/box'
|
|
14
14
|
import { useNativeViewAttrs } from '../accessibility.js'
|
|
15
15
|
import { useMotionRegion } from '../use-motion-region.js'
|
|
16
|
+
import { useMotionSurface } from '../use-motion-surface.js'
|
|
16
17
|
|
|
17
18
|
export type { Align, Justify } from '@getcortexlabs/mavis-core/vue'
|
|
18
19
|
|
|
@@ -79,6 +80,7 @@ export const MBox = defineComponent({
|
|
|
79
80
|
props: motionBoxProps,
|
|
80
81
|
setup(props, { attrs, slots }) {
|
|
81
82
|
const region = useMotionRegion(() => props.motionRegion)
|
|
83
|
+
const surface = useMotionSurface(() => props.motionSurface)
|
|
82
84
|
const { theme } = useMavisTheme()
|
|
83
85
|
const nativeAttrs = useNativeViewAttrs(props)
|
|
84
86
|
const shrink = useLayoutShrink()
|
|
@@ -90,6 +92,7 @@ export const MBox = defineComponent({
|
|
|
90
92
|
nativeAttrs(),
|
|
91
93
|
attrs,
|
|
92
94
|
region,
|
|
95
|
+
{ onLoaded: surface.onLoaded, onUnloaded: surface.onUnloaded },
|
|
93
96
|
),
|
|
94
97
|
slots.default?.(),
|
|
95
98
|
)
|
|
@@ -12,12 +12,20 @@ import { nativeMotionOwner } from '../native/motion-owner.js'
|
|
|
12
12
|
export function useMotionSurface(
|
|
13
13
|
surface: () => MotionSurface | undefined,
|
|
14
14
|
enabled: () => boolean = () => true,
|
|
15
|
+
plainText: () => boolean = () => false,
|
|
16
|
+
afterLayout = false,
|
|
15
17
|
) {
|
|
16
18
|
let view: View | undefined
|
|
17
19
|
let unbind: (() => void) | undefined
|
|
18
20
|
let offPreference: (() => void) | undefined
|
|
19
21
|
let continuous: ReturnType<typeof nativeContinuousSurface> | undefined
|
|
20
22
|
const active = new Map<ReturnType<typeof animate>, MotionFrames>()
|
|
23
|
+
let layoutView: View | undefined
|
|
24
|
+
let layoutQueued = false
|
|
25
|
+
const clearLayout = () => {
|
|
26
|
+
layoutView?.off('layoutChanged', laidOut)
|
|
27
|
+
layoutView = undefined
|
|
28
|
+
}
|
|
21
29
|
const release = () => {
|
|
22
30
|
unbind?.()
|
|
23
31
|
unbind = undefined
|
|
@@ -32,7 +40,21 @@ export function useMotionSurface(
|
|
|
32
40
|
const target = view
|
|
33
41
|
const reference = surface()
|
|
34
42
|
if (!target || !reference) return
|
|
35
|
-
|
|
43
|
+
if (
|
|
44
|
+
afterLayout &&
|
|
45
|
+
(!target.isLayoutValid ||
|
|
46
|
+
target.getActualSize().width <= 0 ||
|
|
47
|
+
target.getActualSize().height <= 0)
|
|
48
|
+
) {
|
|
49
|
+
if (layoutView !== target) {
|
|
50
|
+
clearLayout()
|
|
51
|
+
layoutView = target
|
|
52
|
+
target.on('layoutChanged', laidOut)
|
|
53
|
+
}
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
clearLayout()
|
|
57
|
+
continuous = nativeContinuousSurface(target, enabled, plainText)
|
|
36
58
|
unbind = bindMotionSurface(
|
|
37
59
|
reference,
|
|
38
60
|
nativeMotionOwner(
|
|
@@ -66,7 +88,16 @@ export function useMotionSurface(
|
|
|
66
88
|
if (Object.keys(values).length) set(target, values)
|
|
67
89
|
})
|
|
68
90
|
}
|
|
91
|
+
const laidOut = () => {
|
|
92
|
+
if (layoutQueued) return
|
|
93
|
+
layoutQueued = true
|
|
94
|
+
void Promise.resolve().then(() => {
|
|
95
|
+
layoutQueued = false
|
|
96
|
+
if (view) bind()
|
|
97
|
+
})
|
|
98
|
+
}
|
|
69
99
|
const unloaded = () => {
|
|
100
|
+
clearLayout()
|
|
70
101
|
release()
|
|
71
102
|
view = undefined
|
|
72
103
|
}
|