@getcortexlabs/mavis 0.1.0-rc.14 → 0.1.0-rc.16
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/collection-motion.d.ts.map +1 -1
- package/dist/native/collection-motion.js +7 -4
- package/dist/native/collection-motion.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-surface.d.ts +1 -1
- package/dist/native/motion-surface.d.ts.map +1 -1
- package/dist/native/motion-surface.js +20 -5
- 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/section-scroll.d.ts +1 -1
- package/dist/native/sheet.android.d.ts +2 -0
- package/dist/native/sheet.android.d.ts.map +1 -1
- package/dist/native/sheet.android.js +18 -0
- package/dist/native/sheet.android.js.map +1 -1
- package/dist/native/sheet.d.ts +1 -0
- package/dist/native/sheet.d.ts.map +1 -1
- package/dist/native/sheet.ios.d.ts +1 -0
- package/dist/native/sheet.ios.d.ts.map +1 -1
- package/dist/native/sheet.ios.js +1 -0
- package/dist/native/sheet.ios.js.map +1 -1
- package/dist/native/sheet.js +1 -0
- package/dist/native/sheet.js.map +1 -1
- package/dist/native/visual-effects.d.ts.map +1 -1
- package/dist/native/visual-effects.js +7 -1
- package/dist/native/visual-effects.js.map +1 -1
- package/dist/vue/components/ChoiceControl.d.ts +3 -3
- package/dist/vue/components/DateCalendar.d.ts +1 -1
- 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/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 +104 -104
- 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/MFilePicker.d.ts +1 -1
- 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/MImageViewer.d.ts.map +1 -1
- package/dist/vue/components/MImageViewer.js +11 -2
- package/dist/vue/components/MImageViewer.js.map +1 -1
- package/dist/vue/components/MInput.d.ts +20 -20
- 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 +3 -3
- 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/MSheet.d.ts.map +1 -1
- package/dist/vue/components/MSheet.js +66 -10
- package/dist/vue/components/MSheet.js.map +1 -1
- package/dist/vue/components/MSkeleton.d.ts +3 -3
- package/dist/vue/components/MSlider.d.ts +2 -2
- 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/advanced.d.ts +34 -34
- package/dist/vue/components/configurator.d.ts +36 -36
- package/dist/vue/components/creative.d.ts +21 -21
- package/dist/vue/components/dashboard.d.ts +13 -13
- package/dist/vue/components/dashboard.d.ts.map +1 -1
- package/dist/vue/components/dashboard.js +21 -6
- package/dist/vue/components/dashboard.js.map +1 -1
- package/dist/vue/components/discovery.d.ts +11 -11
- 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 +192 -21
- package/dist/vue/components/screen-components.d.ts.map +1 -1
- package/dist/vue/components/screen-components.js +18 -1
- package/dist/vue/components/screen-components.js.map +1 -1
- package/dist/vue/components/wayfinding.d.ts +10 -10
- package/dist/vue/components/workflows.d.ts +3 -3
- package/dist/vue/index.d.ts +3 -3
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +5 -2
- package/dist/vue/index.js.map +1 -1
- 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 -128
- 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/collection-motion.ts +6 -4
- package/src/native/motion-binding.ts +143 -0
- package/src/native/motion-surface.ts +19 -5
- package/src/native/navigation.ts +15 -0
- package/src/native/pointer-availability.ts +44 -0
- package/src/native/sheet.android.ts +19 -0
- package/src/native/sheet.ios.ts +2 -0
- package/src/native/sheet.ts +2 -0
- package/src/native/visual-effects.ts +6 -2
- package/src/vue/components/MGrid.ts +10 -1
- package/src/vue/components/MImageViewer.ts +10 -2
- package/src/vue/components/MScreen.ts +12 -1
- package/src/vue/components/MSheet.ts +89 -19
- package/src/vue/components/MStack.ts +17 -2
- package/src/vue/components/MText.ts +4 -1
- package/src/vue/components/dashboard.ts +23 -5
- package/src/vue/components/layout.ts +8 -0
- package/src/vue/components/screen-components.ts +20 -0
- package/src/vue/index.ts +10 -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 -133
|
@@ -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
|
+
}
|
package/src/native/box.ios.ts
CHANGED
|
@@ -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)
|
|
@@ -44,6 +44,7 @@ export function nativeCollectionMotion(
|
|
|
44
44
|
minimum,
|
|
45
45
|
...rest
|
|
46
46
|
} = options
|
|
47
|
+
const scrollView = nativeScrollElement(source)
|
|
47
48
|
const headerView = resolve(header)
|
|
48
49
|
if (!(headerView instanceof LayoutBase))
|
|
49
50
|
throw new TypeError('Use a layout surface for the header.')
|
|
@@ -51,9 +52,9 @@ export function nativeCollectionMotion(
|
|
|
51
52
|
// The moving header already sits inside MScreen's safe area. Reapplying
|
|
52
53
|
// UIKit's changing insets to its children would shift them during reflow.
|
|
53
54
|
const restoreHeader = retainHeaderLayout(headerView)
|
|
54
|
-
let
|
|
55
|
+
let control: ReturnType<typeof scrollHeader>
|
|
55
56
|
try {
|
|
56
|
-
|
|
57
|
+
control = scrollHeader(scrollView, {
|
|
57
58
|
...rest,
|
|
58
59
|
header: headerView,
|
|
59
60
|
artwork: artworkView,
|
|
@@ -69,7 +70,6 @@ export function nativeCollectionMotion(
|
|
|
69
70
|
restoreHeader()
|
|
70
71
|
throw error
|
|
71
72
|
}
|
|
72
|
-
const control = headerControl
|
|
73
73
|
let released = false
|
|
74
74
|
const lifetime = scope.add({
|
|
75
75
|
dispose() {
|
|
@@ -95,7 +95,9 @@ export function nativeCollectionMotion(
|
|
|
95
95
|
refresh: () => control.refresh(),
|
|
96
96
|
cancelRefresh: () => control.cancelRefresh(),
|
|
97
97
|
remeasure: () => control.remeasure(),
|
|
98
|
-
preserveAnchor
|
|
98
|
+
async preserveAnchor(change) {
|
|
99
|
+
if (!control.disposed) await control.preserveAnchor(change)
|
|
100
|
+
},
|
|
99
101
|
scrollToItem(key, animated = true) {
|
|
100
102
|
const index = items().findIndex((item) => item.key === key)
|
|
101
103
|
if (index < 0) return false
|
|
@@ -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
|
|
106
|
-
|
|
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
|
|
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: () =>
|
|
142
|
+
refresh: () => {
|
|
143
|
+
pointer.refresh()
|
|
144
|
+
unwatch.notify()
|
|
145
|
+
},
|
|
136
146
|
dispose() {
|
|
137
147
|
refreshes.delete(refresh)
|
|
138
|
-
|
|
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
|
+
}
|
|
@@ -22,3 +22,22 @@ export function expandLayerHost(_host: View) {}
|
|
|
22
22
|
export function contentInsets(_host: View): { left: number; right: number; bottom: number } {
|
|
23
23
|
return { left: 0, right: 0, bottom: 0 }
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
declare const android: {
|
|
27
|
+
graphics: { Rect: new () => { top: number; bottom: number; height(): number } }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Reveal the focused editor after the compact sheet has given the scroll view its new height. */
|
|
31
|
+
export function revealSheetFocus(view: View) {
|
|
32
|
+
const viewport = view.android
|
|
33
|
+
const focused = viewport?.findFocus()
|
|
34
|
+
if (!focused || focused === viewport || !viewport.getHeight()) return
|
|
35
|
+
const bounds = new android.graphics.Rect()
|
|
36
|
+
focused.getDrawingRect(bounds)
|
|
37
|
+
if (bounds.height() > viewport.getHeight()) focused.getFocusedRect(bounds)
|
|
38
|
+
viewport.offsetDescendantRectToMyCoords(focused, bounds)
|
|
39
|
+
const top = viewport.getScrollY()
|
|
40
|
+
const bottom = top + viewport.getHeight()
|
|
41
|
+
if (bounds.bottom > bottom) viewport.scrollBy(0, bounds.bottom - bottom)
|
|
42
|
+
else if (bounds.top < top) viewport.scrollBy(0, bounds.top - top)
|
|
43
|
+
}
|
package/src/native/sheet.ios.ts
CHANGED
package/src/native/sheet.ts
CHANGED
|
@@ -80,8 +80,7 @@ export function nativeVisualEffects(
|
|
|
80
80
|
rollTo: (value, options) => rollTo(text(), value, options),
|
|
81
81
|
circular() {
|
|
82
82
|
circles.get(target)?.dispose()
|
|
83
|
-
|
|
84
|
-
interactive = target.isUserInteractionEnabled
|
|
83
|
+
let hidden: boolean, interactive: boolean
|
|
85
84
|
const visibility = target.visibility
|
|
86
85
|
let active: MotionPlayback | undefined,
|
|
87
86
|
locked = false,
|
|
@@ -104,6 +103,7 @@ export function nativeVisualEffects(
|
|
|
104
103
|
if (!target.isUserInteractionEnabled) target.isUserInteractionEnabled = interactive
|
|
105
104
|
}
|
|
106
105
|
const run = (open: boolean, options: Parameters<MotionCircular['reveal']>[0] = {}) => {
|
|
106
|
+
if (disposed) throw new Error('The circular control was disposed or replaced.')
|
|
107
107
|
if (isIOS && !open && focused(target))
|
|
108
108
|
throw new Error('Move focus outside the circular surface before conceal().')
|
|
109
109
|
const handle = open
|
|
@@ -115,6 +115,10 @@ export function nativeVisualEffects(
|
|
|
115
115
|
if (isIOS) {
|
|
116
116
|
if (open) unlock()
|
|
117
117
|
else {
|
|
118
|
+
if (!locked) {
|
|
119
|
+
hidden = target.accessibilityHidden
|
|
120
|
+
interactive = target.isUserInteractionEnabled
|
|
121
|
+
}
|
|
118
122
|
locked = true
|
|
119
123
|
target.accessibilityHidden = true
|
|
120
124
|
target.isUserInteractionEnabled = false
|
|
@@ -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},`),
|
|
@@ -77,7 +77,9 @@ export const MImageViewer = defineComponent({
|
|
|
77
77
|
if (image?.isLoaded && shared)
|
|
78
78
|
detachPhoto = shared.attach(image, 'photo', { content: 'image', radius: 12 })
|
|
79
79
|
}
|
|
80
|
+
let zoomRevision = 0
|
|
80
81
|
function releaseZoom() {
|
|
82
|
+
++zoomRevision
|
|
81
83
|
zoom?.dispose()
|
|
82
84
|
zoom = undefined
|
|
83
85
|
ready.value = false
|
|
@@ -101,23 +103,29 @@ export const MImageViewer = defineComponent({
|
|
|
101
103
|
zoom
|
|
102
104
|
)
|
|
103
105
|
return
|
|
106
|
+
const owner = ++zoomRevision
|
|
104
107
|
zoom = zoomable(photo, {
|
|
105
108
|
viewport,
|
|
106
109
|
scale: [1, props.maxZoom],
|
|
107
110
|
doubleTap: Math.min(2.5, props.maxZoom),
|
|
108
111
|
dismiss: 'vertical',
|
|
109
112
|
onSettled(state) {
|
|
113
|
+
if (owner !== zoomRevision) return
|
|
110
114
|
scale.value = state.scale
|
|
111
115
|
if (pendingClose && state.scale <= 1.001) finishClose()
|
|
112
116
|
},
|
|
113
117
|
onDismiss(intent) {
|
|
118
|
+
if (owner !== zoomRevision || !requested.value || intent.state.scale > 1.001) {
|
|
119
|
+
intent.cancel()
|
|
120
|
+
return
|
|
121
|
+
}
|
|
114
122
|
request('gesture')
|
|
115
123
|
void nextTick(() => {
|
|
116
|
-
if (requested.value) intent.cancel()
|
|
124
|
+
if (owner === zoomRevision && requested.value) intent.cancel()
|
|
117
125
|
})
|
|
118
126
|
},
|
|
119
127
|
onError() {
|
|
120
|
-
if (displayed.value) emit('error', displayed.value)
|
|
128
|
+
if (owner === zoomRevision && displayed.value) emit('error', displayed.value)
|
|
121
129
|
},
|
|
122
130
|
})
|
|
123
131
|
void refreshZoomReady()
|
|
@@ -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
|
),
|