@getcortexlabs/mavis 0.1.0-rc.12.1 → 0.1.0-rc.13
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/motion-surface.d.ts.map +1 -1
- package/dist/native/motion-surface.js +35 -11
- package/dist/native/motion-surface.js.map +1 -1
- package/dist/native/moved-shadow.d.ts +5 -0
- package/dist/native/moved-shadow.d.ts.map +1 -0
- package/dist/native/moved-shadow.js +23 -0
- package/dist/native/moved-shadow.js.map +1 -0
- package/dist/native/visual-effects.d.ts.map +1 -1
- package/dist/native/visual-effects.js +5 -0
- package/dist/native/visual-effects.js.map +1 -1
- package/dist/vue/components/MButton.d.ts +2 -2
- package/dist/vue/components/MCard.d.ts.map +1 -1
- package/dist/vue/components/MCard.js +26 -6
- package/dist/vue/components/MCard.js.map +1 -1
- package/dist/vue/components/MChip.d.ts +1 -1
- package/dist/vue/components/MEmptyState.d.ts +1 -1
- package/dist/vue/components/MInput.d.ts +2 -2
- package/dist/vue/components/MPopover.d.ts +1 -1
- package/dist/vue/components/MTooltip.d.ts +1 -1
- package/dist/vue/components/layout.d.ts +11 -0
- package/dist/vue/components/layout.d.ts.map +1 -1
- package/dist/vue/components/layout.js +3 -0
- package/dist/vue/components/layout.js.map +1 -1
- package/dist/vue/perspective.d.ts +4 -0
- package/dist/vue/perspective.d.ts.map +1 -0
- package/dist/vue/perspective.js +3 -0
- package/dist/vue/perspective.js.map +1 -0
- 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 +46 -8
- package/dist/vue/use-motion-surface.js.map +1 -1
- package/package.json +3 -3
- package/src/native/motion-surface.ts +36 -10
- package/src/native/moved-shadow.ts +22 -0
- package/src/native/visual-effects.ts +5 -0
- package/src/vue/components/MCard.ts +32 -7
- package/src/vue/components/layout.ts +3 -0
- package/src/vue/perspective.ts +4 -0
- package/src/vue/use-motion-surface.ts +43 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"perspective.js","sourceRoot":"","sources":["../../src/vue/perspective.ts"],"names":[],"mappings":"AAEA,uFAAuF;AACvF,MAAM,CAAC,MAAM,cAAc,GAA2C,MAAM,CAAC,mBAAmB,CAAC,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type EventData } from '@nativescript/core';
|
|
2
2
|
import { type MotionSurface } from '@getcortexlabs/mavis-core/experimental';
|
|
3
3
|
export declare function useMotionSurface(surface: () => MotionSurface | undefined, enabled?: () => boolean, plainText?: () => boolean, afterLayout?: boolean): {
|
|
4
4
|
allowsActivation: () => boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-motion-surface.d.ts","sourceRoot":"","sources":["../../src/vue/use-motion-surface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"use-motion-surface.d.ts","sourceRoot":"","sources":["../../src/vue/use-motion-surface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,SAAS,EAAa,MAAM,oBAAoB,CAAA;AAGhF,OAAO,EAKL,KAAK,aAAa,EACnB,MAAM,wCAAwC,CAAA;AAM/C,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,aAAa,GAAG,SAAS,EACxC,OAAO,GAAE,MAAM,OAAoB,EACnC,SAAS,GAAE,MAAM,OAAqB,EACtC,WAAW,UAAQ;;oBA4HD,SAAS;;EAM5B"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Utils, isAndroid } from '@nativescript/core';
|
|
2
|
+
import { inject, onBeforeUnmount, watch } from 'nativescript-vue';
|
|
2
3
|
import { animate, set, onReducedMotion } from '@rafaelaugusto/jolt';
|
|
3
|
-
import { bindMotionSurface, } from '@getcortexlabs/mavis-core/experimental';
|
|
4
|
+
import { bindMotionSurface, motionChannels, motionKeyframes, } from '@getcortexlabs/mavis-core/experimental';
|
|
4
5
|
import { nativeContinuousSurface } from '../native/motion-surface.js';
|
|
5
6
|
import { nativeMotionOwner } from '../native/motion-owner.js';
|
|
7
|
+
import { perspectiveKey } from './perspective.js';
|
|
8
|
+
import { takeShadow } from '../native/moved-shadow.js';
|
|
6
9
|
export function useMotionSurface(surface, enabled = () => true, plainText = () => false, afterLayout = false) {
|
|
7
10
|
let view;
|
|
8
11
|
let unbind;
|
|
@@ -11,6 +14,21 @@ export function useMotionSurface(surface, enabled = () => true, plainText = () =
|
|
|
11
14
|
const active = new Map();
|
|
12
15
|
let layoutView;
|
|
13
16
|
let layoutQueued = false;
|
|
17
|
+
const perspective = inject(perspectiveKey, undefined);
|
|
18
|
+
let flat;
|
|
19
|
+
const project = () => {
|
|
20
|
+
const depth = perspective?.();
|
|
21
|
+
if (flat && (depth === undefined || flat.view !== view)) {
|
|
22
|
+
flat.view.perspective = flat.perspective;
|
|
23
|
+
flat = undefined;
|
|
24
|
+
}
|
|
25
|
+
if (!view || depth === undefined || !unbind)
|
|
26
|
+
return;
|
|
27
|
+
flat ??= { view, perspective: view.perspective };
|
|
28
|
+
// Core multiplies by the density for Android's camera distance, whose unit is not the
|
|
29
|
+
// CSS distance. This is the factor that draws the same projection as iOS and the Web.
|
|
30
|
+
view.perspective = isAndroid ? depth * Utils.layout.getDisplayDensity() * Math.sqrt(5) : depth;
|
|
31
|
+
};
|
|
14
32
|
const clearLayout = () => {
|
|
15
33
|
layoutView?.off('layoutChanged', laidOut);
|
|
16
34
|
layoutView = undefined;
|
|
@@ -24,6 +42,7 @@ export function useMotionSurface(surface, enabled = () => true, plainText = () =
|
|
|
24
42
|
for (const handle of active.keys())
|
|
25
43
|
handle.stop();
|
|
26
44
|
active.clear();
|
|
45
|
+
project();
|
|
27
46
|
};
|
|
28
47
|
const bind = () => {
|
|
29
48
|
release();
|
|
@@ -47,30 +66,47 @@ export function useMotionSurface(surface, enabled = () => true, plainText = () =
|
|
|
47
66
|
unbind = bindMotionSurface(reference, nativeMotionOwner({
|
|
48
67
|
...continuous.adapter,
|
|
49
68
|
animate(values, options) {
|
|
50
|
-
continuous?.interrupt(
|
|
51
|
-
const handle = animate(target, values, options);
|
|
69
|
+
continuous?.interrupt(motionChannels(values));
|
|
70
|
+
const handle = animate(target, motionKeyframes(values), options);
|
|
71
|
+
takeShadow(target, values);
|
|
52
72
|
active.set(handle, values);
|
|
53
73
|
void handle.finished.then(() => active.delete(handle));
|
|
54
74
|
return handle;
|
|
55
75
|
},
|
|
56
76
|
set: (values) => {
|
|
57
77
|
continuous?.interrupt(Object.keys(values));
|
|
58
|
-
|
|
78
|
+
// Jolt on Android leaves the path's translationY on the view when a path still in
|
|
79
|
+
// flight is replaced by a zero-duration set (rafaelaugustos/jolt#479).
|
|
80
|
+
if (isAndroid && ('x' in values || 'y' in values || 'rotate' in values))
|
|
81
|
+
for (const [handle, frames] of active)
|
|
82
|
+
if (frames.path)
|
|
83
|
+
handle.stop();
|
|
84
|
+
const handle = animate(target, values, { duration: 0 });
|
|
85
|
+
takeShadow(target, values);
|
|
86
|
+
return handle;
|
|
59
87
|
},
|
|
60
88
|
}, target));
|
|
89
|
+
project();
|
|
61
90
|
offPreference = onReducedMotion((reduced) => {
|
|
62
91
|
if (!reduced)
|
|
63
92
|
return;
|
|
64
|
-
// Set only spatial channels: opacity can keep
|
|
93
|
+
// Set only spatial channels: opacity and shadow paint can keep their timelines.
|
|
65
94
|
const values = {};
|
|
66
|
-
for (const frames of active.values())
|
|
95
|
+
for (const frames of active.values()) {
|
|
96
|
+
if (frames.path)
|
|
97
|
+
Object.assign(values, {
|
|
98
|
+
x: frames.path.end.x,
|
|
99
|
+
y: frames.path.end.y,
|
|
100
|
+
...(frames.orient ? { rotate: frames.path.end.rotate } : {}),
|
|
101
|
+
});
|
|
67
102
|
for (const [property, value] of Object.entries(frames)) {
|
|
68
|
-
if (property === 'opacity')
|
|
103
|
+
if (property === 'opacity' || property.startsWith('shadow'))
|
|
69
104
|
continue;
|
|
70
105
|
const final = Array.isArray(value) ? value.at(-1) : value;
|
|
71
106
|
if (typeof final === 'number')
|
|
72
107
|
values[property] = final;
|
|
73
108
|
}
|
|
109
|
+
}
|
|
74
110
|
if (Object.keys(values).length)
|
|
75
111
|
set(target, values);
|
|
76
112
|
});
|
|
@@ -91,6 +127,8 @@ export function useMotionSurface(surface, enabled = () => true, plainText = () =
|
|
|
91
127
|
view = undefined;
|
|
92
128
|
};
|
|
93
129
|
watch(surface, bind, { flush: 'post' });
|
|
130
|
+
if (perspective)
|
|
131
|
+
watch(perspective, project, { flush: 'post' });
|
|
94
132
|
watch(enabled, () => continuous?.refresh(), { flush: 'sync' });
|
|
95
133
|
onBeforeUnmount(unloaded);
|
|
96
134
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-motion-surface.js","sourceRoot":"","sources":["../../src/vue/use-motion-surface.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-motion-surface.js","sourceRoot":"","sources":["../../src/vue/use-motion-surface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAA6B,MAAM,oBAAoB,CAAA;AAChF,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACjE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACnE,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,eAAe,GAGhB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAEtD,MAAM,UAAU,gBAAgB,CAC9B,OAAwC,EACxC,UAAy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,CAAA;QACb,OAAO,EAAE,CAAA;QACT,IAAI,GAAG,SAAS,CAAA;IAClB,CAAC,CAAA;IACD,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;IACvC,IAAI,WAAW;QAAE,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;IAC/D,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;IAC9D,eAAe,CAAC,QAAQ,CAAC,CAAA;IACzB,OAAO;QACL,gBAAgB,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE,gBAAgB,EAAE,IAAI,IAAI;QAC9D,QAAQ,CAAC,KAAgB;YACvB,IAAI,GAAG,KAAK,CAAC,MAAc,CAAA;YAC3B,IAAI,EAAE,CAAA;QACR,CAAC;QACD,UAAU,EAAE,QAAQ;KACrB,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getcortexlabs/mavis",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.13",
|
|
4
4
|
"description": "Mavis UI foundations for NativeScript, with a Vue integration.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@nativescript/core": "^9.1.3",
|
|
46
|
-
"@rafaelaugusto/jolt": "^0.1.0-rc.
|
|
46
|
+
"@rafaelaugusto/jolt": "^0.1.0-rc.13",
|
|
47
47
|
"nativescript-vue": "^3.1.3"
|
|
48
48
|
},
|
|
49
49
|
"peerDependenciesMeta": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@getcortexlabs/mavis-core": "0.1.0-rc.
|
|
55
|
+
"@getcortexlabs/mavis-core": "0.1.0-rc.13"
|
|
56
56
|
},
|
|
57
57
|
"nativescript": {
|
|
58
58
|
"platforms": {
|
|
@@ -14,7 +14,9 @@ import {
|
|
|
14
14
|
set,
|
|
15
15
|
stop,
|
|
16
16
|
drag,
|
|
17
|
+
pointerFollow,
|
|
17
18
|
type DerivedValue,
|
|
19
|
+
type PointerOptions,
|
|
18
20
|
} from '@rafaelaugusto/jolt'
|
|
19
21
|
import type {
|
|
20
22
|
MotionSurfaceAdapter,
|
|
@@ -96,18 +98,42 @@ export function nativeContinuousSurface(
|
|
|
96
98
|
},
|
|
97
99
|
pointerFollow(region, options) {
|
|
98
100
|
assertNativeRegion(region, target)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
// Jolt owns the hover listener, its geometry, suspension and the views' load state.
|
|
102
|
+
// Ordinary touch is not hover, so scrolling, taps and focus stay with the app.
|
|
103
|
+
const pointer = pointerFollow(nativeRegionTarget(region), {
|
|
104
|
+
...options,
|
|
105
|
+
disabled: options.disabled || !enabled(),
|
|
106
|
+
} as PointerOptions)
|
|
107
|
+
let disabled = options.disabled ?? false
|
|
108
|
+
const refresh = () => pointer.update({ disabled: disabled || !enabled() })
|
|
109
|
+
refreshes.add(refresh)
|
|
110
|
+
// The pointer owns its values; wrappers are borrowed by Mavis bindings.
|
|
111
|
+
const wrap = (source: DerivedValue) => {
|
|
112
|
+
const value = { get: () => source.get(), dispose() {} }
|
|
113
|
+
sources.set(value, source)
|
|
114
|
+
return value
|
|
115
|
+
}
|
|
101
116
|
return {
|
|
102
|
-
x,
|
|
103
|
-
y,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
117
|
+
x: wrap(pointer.x),
|
|
118
|
+
y: wrap(pointer.y),
|
|
119
|
+
presence: wrap(pointer.presence),
|
|
120
|
+
get execution() {
|
|
121
|
+
return pointer.available ? ('hover' as const) : ('static' as const)
|
|
122
|
+
},
|
|
123
|
+
get available() {
|
|
124
|
+
return pointer.available
|
|
125
|
+
},
|
|
126
|
+
get active() {
|
|
127
|
+
return pointer.active
|
|
128
|
+
},
|
|
129
|
+
update(state) {
|
|
130
|
+
disabled = state.disabled
|
|
131
|
+
refresh()
|
|
132
|
+
},
|
|
133
|
+
refresh: () => pointer.refresh(),
|
|
108
134
|
dispose() {
|
|
109
|
-
|
|
110
|
-
|
|
135
|
+
refreshes.delete(refresh)
|
|
136
|
+
pointer.dispose()
|
|
111
137
|
},
|
|
112
138
|
}
|
|
113
139
|
},
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { View } from '@nativescript/core'
|
|
2
|
+
|
|
3
|
+
// The shadow the component declared when application motion took it, and the last one rendered.
|
|
4
|
+
const moved = new WeakMap<View, unknown>()
|
|
5
|
+
const declared = new WeakMap<View, unknown>()
|
|
6
|
+
|
|
7
|
+
export function takeShadow(view: View, values: object) {
|
|
8
|
+
if (!moved.has(view) && Object.keys(values).some((key) => key.startsWith('shadow')))
|
|
9
|
+
moved.set(view, declared.get(view))
|
|
10
|
+
}
|
|
11
|
+
/** A rerender keeps the shadow the application animated until the component declares another. */
|
|
12
|
+
export function keepShadow(view: View | undefined, shadow: string | undefined): unknown {
|
|
13
|
+
if (!view) return shadow
|
|
14
|
+
let kept: unknown = shadow
|
|
15
|
+
if (moved.has(view)) {
|
|
16
|
+
const current = (view as View & { boxShadow?: unknown }).boxShadow
|
|
17
|
+
if (moved.get(view) !== shadow) moved.delete(view)
|
|
18
|
+
else if (current) kept = current
|
|
19
|
+
}
|
|
20
|
+
declared.set(view, shadow)
|
|
21
|
+
return kept
|
|
22
|
+
}
|
|
@@ -40,6 +40,11 @@ export function nativeVisualEffects(
|
|
|
40
40
|
return isIOS && target instanceof Image && Boolean(target.ios?.image?.symbolImage)
|
|
41
41
|
if (effect === 'image') return target instanceof Image
|
|
42
42
|
if (effect === 'liquid') return isIOS && target instanceof Image
|
|
43
|
+
if (effect === 'shadow') {
|
|
44
|
+
// Android draws CSS shadows from a cached shape and elevation is a different model.
|
|
45
|
+
const shadows = (target as View & { boxShadow?: unknown }).boxShadow
|
|
46
|
+
return isIOS && Array.isArray(shadows) && shadows.length === 1 && !shadows[0]?.inset
|
|
47
|
+
}
|
|
43
48
|
return (
|
|
44
49
|
['gradient', 'particles', 'confetti', 'blur', 'shape', 'keyboard'].includes(effect) || isIOS
|
|
45
50
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { nativeDestination, navigateNative } from '../navigation.js'
|
|
2
2
|
import { resolveSpace, resolveRadius, shadowStyle } from '@getcortexlabs/mavis-core'
|
|
3
3
|
import { ActionChildren } from '../accessibility.js'
|
|
4
|
-
import { defineComponent, h, mergeProps } from 'nativescript-vue'
|
|
4
|
+
import { defineComponent, getCurrentInstance, h, mergeProps } from 'nativescript-vue'
|
|
5
5
|
import {
|
|
6
6
|
useButtonAction,
|
|
7
7
|
cardProps,
|
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
import { MColumn } from './layout.js'
|
|
13
13
|
import { usePressFeedback } from '../use-press.js'
|
|
14
14
|
import { useMotionSurface } from '../use-motion-surface.js'
|
|
15
|
+
import { keepShadow } from '../../native/moved-shadow.js'
|
|
16
|
+
import type { EventData, View } from '@nativescript/core'
|
|
15
17
|
|
|
16
18
|
export const MCard = defineComponent({
|
|
17
19
|
name: 'MCard',
|
|
@@ -22,12 +24,15 @@ export const MCard = defineComponent({
|
|
|
22
24
|
useButtonAction(() => props.interactive || props.href !== undefined)
|
|
23
25
|
const { theme } = useMavisTheme()
|
|
24
26
|
const navigation = useNavigationOptions(props)
|
|
27
|
+
const instance = getCurrentInstance()
|
|
25
28
|
const enabled = () => (props.interactive || props.href !== undefined) && !props.disabled
|
|
26
29
|
const lifecycle = usePressFeedback(enabled, theme)
|
|
27
30
|
const { allowsActivation, ...surface } = useMotionSurface(
|
|
28
31
|
() => props.motionSurface,
|
|
29
32
|
() => !props.disabled,
|
|
30
33
|
)
|
|
34
|
+
let view: View | undefined
|
|
35
|
+
let shadow: string | undefined
|
|
31
36
|
return () => {
|
|
32
37
|
const {
|
|
33
38
|
interactive: action,
|
|
@@ -41,20 +46,28 @@ export const MCard = defineComponent({
|
|
|
41
46
|
...layout
|
|
42
47
|
} = props
|
|
43
48
|
const interactive = action || href !== undefined
|
|
49
|
+
// A labelled card with no action wired is read as one element, like a labelled action.
|
|
50
|
+
// An explicit accessible attribute decides otherwise.
|
|
51
|
+
const summary =
|
|
52
|
+
!interactive &&
|
|
53
|
+
(attrs.accessible === undefined
|
|
54
|
+
? Boolean(props.accessibilityLabel) && !instance?.vnode.props?.onClick
|
|
55
|
+
: attrs.accessible !== false && attrs.accessible !== 'false')
|
|
44
56
|
if (href !== undefined) nativeDestination(navigation())
|
|
45
57
|
const tokens = theme.value.components.card
|
|
46
58
|
layout.padding ??= tokens.padding
|
|
47
59
|
layout.radius ??= tokens.radius
|
|
60
|
+
shadow =
|
|
61
|
+
(elevation ?? tokens.elevation) === 'none'
|
|
62
|
+
? undefined
|
|
63
|
+
: shadowStyle(theme.value.elevation[elevation ?? tokens.elevation], 'native')
|
|
48
64
|
return h(
|
|
49
65
|
MColumn,
|
|
50
66
|
mergeProps(
|
|
51
67
|
layout,
|
|
52
68
|
{
|
|
53
69
|
style: {
|
|
54
|
-
boxShadow:
|
|
55
|
-
(elevation ?? tokens.elevation) === 'none'
|
|
56
|
-
? undefined
|
|
57
|
-
: shadowStyle(theme.value.elevation[elevation ?? tokens.elevation], 'native'),
|
|
70
|
+
boxShadow: keepShadow(view, shadow),
|
|
58
71
|
backgroundColor: props.backgroundColor ?? theme.value.colors.surface,
|
|
59
72
|
borderColor: theme.value.colors.border,
|
|
60
73
|
borderWidth: 1,
|
|
@@ -65,7 +78,15 @@ export const MCard = defineComponent({
|
|
|
65
78
|
lifecycle,
|
|
66
79
|
surface,
|
|
67
80
|
{
|
|
68
|
-
|
|
81
|
+
onLoaded: (event: EventData) => {
|
|
82
|
+
view = event.object as View
|
|
83
|
+
// The first render ran before the view existed: record what it declared.
|
|
84
|
+
keepShadow(view, shadow)
|
|
85
|
+
},
|
|
86
|
+
onUnloaded: () => {
|
|
87
|
+
view = undefined
|
|
88
|
+
},
|
|
89
|
+
accessible: interactive || summary,
|
|
69
90
|
accessibilityRole: href !== undefined ? 'link' : interactive ? 'button' : '',
|
|
70
91
|
accessibilityState: interactive && disabled ? 'disabled' : '',
|
|
71
92
|
onTap: interactive
|
|
@@ -81,7 +102,11 @@ export const MCard = defineComponent({
|
|
|
81
102
|
),
|
|
82
103
|
{
|
|
83
104
|
default: () =>
|
|
84
|
-
h(
|
|
105
|
+
h(
|
|
106
|
+
ActionChildren,
|
|
107
|
+
{ hidden: (interactive || summary) && Boolean(props.accessibilityLabel) },
|
|
108
|
+
slots,
|
|
109
|
+
),
|
|
85
110
|
},
|
|
86
111
|
)
|
|
87
112
|
}
|
|
@@ -8,12 +8,14 @@ import {
|
|
|
8
8
|
} from '@getcortexlabs/mavis-core/vue'
|
|
9
9
|
import { defineComponent, h, mergeProps, provide, registerElement } from 'nativescript-vue'
|
|
10
10
|
import { resolveSpace } from '@getcortexlabs/mavis-core'
|
|
11
|
+
import { resolvePerspective } from '@getcortexlabs/mavis-core/experimental'
|
|
11
12
|
import { boxStyle } from '../props.js'
|
|
12
13
|
import { MavisFlexLayout } from '../../native/flex-layout'
|
|
13
14
|
import { MavisBox } from '../../native/box'
|
|
14
15
|
import { useNativeViewAttrs } from '../accessibility.js'
|
|
15
16
|
import { useMotionRegion } from '../use-motion-region.js'
|
|
16
17
|
import { useMotionSurface } from '../use-motion-surface.js'
|
|
18
|
+
import { perspectiveKey } from '../perspective.js'
|
|
17
19
|
|
|
18
20
|
export type { Align, Justify } from '@getcortexlabs/mavis-core/vue'
|
|
19
21
|
|
|
@@ -83,6 +85,7 @@ export const MBox = defineComponent({
|
|
|
83
85
|
setup(props, { attrs, slots }) {
|
|
84
86
|
const region = useMotionRegion(() => props.motionRegion)
|
|
85
87
|
const surface = useMotionSurface(() => props.motionSurface)
|
|
88
|
+
provide(perspectiveKey, () => resolvePerspective(props.perspective))
|
|
86
89
|
const { theme } = useMavisTheme()
|
|
87
90
|
const nativeAttrs = useNativeViewAttrs(props)
|
|
88
91
|
const shrink = useLayoutShrink()
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { onBeforeUnmount, watch } from 'nativescript-vue'
|
|
1
|
+
import { Utils, isAndroid, type EventData, type View } from '@nativescript/core'
|
|
2
|
+
import { inject, onBeforeUnmount, watch } from 'nativescript-vue'
|
|
3
3
|
import { animate, set, onReducedMotion } from '@rafaelaugusto/jolt'
|
|
4
4
|
import {
|
|
5
5
|
bindMotionSurface,
|
|
6
|
+
motionChannels,
|
|
7
|
+
motionKeyframes,
|
|
6
8
|
type MotionFrames,
|
|
7
9
|
type MotionSurface,
|
|
8
10
|
} from '@getcortexlabs/mavis-core/experimental'
|
|
9
11
|
import { nativeContinuousSurface } from '../native/motion-surface.js'
|
|
10
12
|
import { nativeMotionOwner } from '../native/motion-owner.js'
|
|
13
|
+
import { perspectiveKey } from './perspective.js'
|
|
14
|
+
import { takeShadow } from '../native/moved-shadow.js'
|
|
11
15
|
|
|
12
16
|
export function useMotionSurface(
|
|
13
17
|
surface: () => MotionSurface | undefined,
|
|
@@ -22,6 +26,20 @@ export function useMotionSurface(
|
|
|
22
26
|
const active = new Map<ReturnType<typeof animate>, MotionFrames>()
|
|
23
27
|
let layoutView: View | undefined
|
|
24
28
|
let layoutQueued = false
|
|
29
|
+
const perspective = inject(perspectiveKey, undefined)
|
|
30
|
+
let flat: { view: View; perspective: number } | undefined
|
|
31
|
+
const project = () => {
|
|
32
|
+
const depth = perspective?.()
|
|
33
|
+
if (flat && (depth === undefined || flat.view !== view)) {
|
|
34
|
+
flat.view.perspective = flat.perspective
|
|
35
|
+
flat = undefined
|
|
36
|
+
}
|
|
37
|
+
if (!view || depth === undefined || !unbind) return
|
|
38
|
+
flat ??= { view, perspective: view.perspective }
|
|
39
|
+
// Core multiplies by the density for Android's camera distance, whose unit is not the
|
|
40
|
+
// CSS distance. This is the factor that draws the same projection as iOS and the Web.
|
|
41
|
+
view.perspective = isAndroid ? depth * Utils.layout.getDisplayDensity() * Math.sqrt(5) : depth
|
|
42
|
+
}
|
|
25
43
|
const clearLayout = () => {
|
|
26
44
|
layoutView?.off('layoutChanged', laidOut)
|
|
27
45
|
layoutView = undefined
|
|
@@ -34,6 +52,7 @@ export function useMotionSurface(
|
|
|
34
52
|
offPreference = undefined
|
|
35
53
|
for (const handle of active.keys()) handle.stop()
|
|
36
54
|
active.clear()
|
|
55
|
+
project()
|
|
37
56
|
}
|
|
38
57
|
const bind = () => {
|
|
39
58
|
release()
|
|
@@ -61,30 +80,45 @@ export function useMotionSurface(
|
|
|
61
80
|
{
|
|
62
81
|
...continuous.adapter,
|
|
63
82
|
animate(values, options) {
|
|
64
|
-
continuous?.interrupt(
|
|
65
|
-
const handle = animate(target, values, options)
|
|
83
|
+
continuous?.interrupt(motionChannels(values))
|
|
84
|
+
const handle = animate(target, motionKeyframes(values), options)
|
|
85
|
+
takeShadow(target, values)
|
|
66
86
|
active.set(handle, values)
|
|
67
87
|
void handle.finished.then(() => active.delete(handle))
|
|
68
88
|
return handle
|
|
69
89
|
},
|
|
70
90
|
set: (values) => {
|
|
71
91
|
continuous?.interrupt(Object.keys(values))
|
|
72
|
-
|
|
92
|
+
// Jolt on Android leaves the path's translationY on the view when a path still in
|
|
93
|
+
// flight is replaced by a zero-duration set (rafaelaugustos/jolt#479).
|
|
94
|
+
if (isAndroid && ('x' in values || 'y' in values || 'rotate' in values))
|
|
95
|
+
for (const [handle, frames] of active) if (frames.path) handle.stop()
|
|
96
|
+
const handle = animate(target, values, { duration: 0 })
|
|
97
|
+
takeShadow(target, values)
|
|
98
|
+
return handle
|
|
73
99
|
},
|
|
74
100
|
},
|
|
75
101
|
target,
|
|
76
102
|
),
|
|
77
103
|
)
|
|
104
|
+
project()
|
|
78
105
|
offPreference = onReducedMotion((reduced) => {
|
|
79
106
|
if (!reduced) return
|
|
80
|
-
// Set only spatial channels: opacity can keep
|
|
107
|
+
// Set only spatial channels: opacity and shadow paint can keep their timelines.
|
|
81
108
|
const values: Record<string, number> = {}
|
|
82
|
-
for (const frames of active.values())
|
|
109
|
+
for (const frames of active.values()) {
|
|
110
|
+
if (frames.path)
|
|
111
|
+
Object.assign(values, {
|
|
112
|
+
x: frames.path.end.x,
|
|
113
|
+
y: frames.path.end.y,
|
|
114
|
+
...(frames.orient ? { rotate: frames.path.end.rotate } : {}),
|
|
115
|
+
})
|
|
83
116
|
for (const [property, value] of Object.entries(frames)) {
|
|
84
|
-
if (property === 'opacity') continue
|
|
117
|
+
if (property === 'opacity' || property.startsWith('shadow')) continue
|
|
85
118
|
const final = Array.isArray(value) ? value.at(-1) : value
|
|
86
119
|
if (typeof final === 'number') values[property] = final
|
|
87
120
|
}
|
|
121
|
+
}
|
|
88
122
|
if (Object.keys(values).length) set(target, values)
|
|
89
123
|
})
|
|
90
124
|
}
|
|
@@ -102,6 +136,7 @@ export function useMotionSurface(
|
|
|
102
136
|
view = undefined
|
|
103
137
|
}
|
|
104
138
|
watch(surface, bind, { flush: 'post' })
|
|
139
|
+
if (perspective) watch(perspective, project, { flush: 'post' })
|
|
105
140
|
watch(enabled, () => continuous?.refresh(), { flush: 'sync' })
|
|
106
141
|
onBeforeUnmount(unloaded)
|
|
107
142
|
return {
|