@getcortexlabs/mavis 0.1.0-alpha.4 → 0.1.0-alpha.6
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/app-icons.d.ts +26 -0
- package/dist/app-icons.d.ts.map +1 -0
- package/dist/app-icons.js +9 -0
- package/dist/app-icons.js.map +1 -0
- package/dist/files.d.ts +4 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +3 -0
- package/dist/files.js.map +1 -0
- package/dist/native/app-icons.android.d.ts +4 -0
- package/dist/native/app-icons.android.d.ts.map +1 -0
- package/dist/native/app-icons.android.js +67 -0
- package/dist/native/app-icons.android.js.map +1 -0
- package/dist/native/app-icons.d.ts +4 -0
- package/dist/native/app-icons.d.ts.map +1 -0
- package/dist/native/app-icons.ios.d.ts +4 -0
- package/dist/native/app-icons.ios.d.ts.map +1 -0
- package/dist/native/app-icons.ios.js +45 -0
- package/dist/native/app-icons.ios.js.map +1 -0
- package/dist/native/app-icons.js +9 -0
- package/dist/native/app-icons.js.map +1 -0
- package/dist/native/combobox-editor.android.d.ts +3 -0
- package/dist/native/combobox-editor.android.d.ts.map +1 -0
- package/dist/native/combobox-editor.android.js +5 -0
- package/dist/native/combobox-editor.android.js.map +1 -0
- package/dist/native/combobox-editor.d.ts +4 -0
- package/dist/native/combobox-editor.d.ts.map +1 -0
- package/dist/native/combobox-editor.js +5 -0
- package/dist/native/combobox-editor.js.map +1 -0
- package/dist/native/file-access.d.ts +23 -0
- package/dist/native/file-access.d.ts.map +1 -0
- package/dist/native/file-access.js +55 -0
- package/dist/native/file-access.js.map +1 -0
- package/dist/native/file-picker.android.d.ts +3 -0
- package/dist/native/file-picker.android.d.ts.map +1 -0
- package/dist/native/file-picker.android.js +147 -0
- package/dist/native/file-picker.android.js.map +1 -0
- package/dist/native/file-picker.d.ts +4 -0
- package/dist/native/file-picker.d.ts.map +1 -0
- package/dist/native/file-picker.ios.d.ts +3 -0
- package/dist/native/file-picker.ios.d.ts.map +1 -0
- package/dist/native/file-picker.ios.js +152 -0
- package/dist/native/file-picker.ios.js.map +1 -0
- package/dist/native/file-picker.js +7 -0
- package/dist/native/file-picker.js.map +1 -0
- package/dist/native/motion-owner.d.ts +5 -0
- package/dist/native/motion-owner.d.ts.map +1 -0
- package/dist/native/motion-owner.js +57 -0
- package/dist/native/motion-owner.js.map +1 -0
- package/dist/native/motion-region.d.ts +6 -0
- package/dist/native/motion-region.d.ts.map +1 -0
- package/dist/native/motion-region.js +237 -0
- package/dist/native/motion-region.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 +43 -2
- package/dist/native/motion-surface.js.map +1 -1
- package/dist/native/press.d.ts +3 -2
- package/dist/native/press.d.ts.map +1 -1
- package/dist/native/press.js.map +1 -1
- package/dist/native/scroll-motion.d.ts +1 -0
- package/dist/native/scroll-motion.d.ts.map +1 -1
- package/dist/native/scroll-motion.js +6 -0
- package/dist/native/scroll-motion.js.map +1 -1
- package/dist/vue/components/ChoiceControl.d.ts +21 -11
- package/dist/vue/components/ChoiceControl.d.ts.map +1 -1
- package/dist/vue/components/DateCalendar.d.ts +94 -0
- package/dist/vue/components/DateCalendar.d.ts.map +1 -0
- package/dist/vue/components/DateCalendar.js +96 -0
- package/dist/vue/components/DateCalendar.js.map +1 -0
- package/dist/vue/components/MAccordion.d.ts +19 -9
- package/dist/vue/components/MAccordion.d.ts.map +1 -1
- package/dist/vue/components/MAlert.d.ts +20 -10
- package/dist/vue/components/MAlert.d.ts.map +1 -1
- package/dist/vue/components/MAvatar.d.ts +12 -6
- package/dist/vue/components/MAvatar.d.ts.map +1 -1
- package/dist/vue/components/MBadge.d.ts +12 -6
- package/dist/vue/components/MBadge.d.ts.map +1 -1
- package/dist/vue/components/MButton.d.ts +127 -39
- package/dist/vue/components/MButton.d.ts.map +1 -1
- package/dist/vue/components/MButton.js +20 -13
- package/dist/vue/components/MButton.js.map +1 -1
- package/dist/vue/components/MCard.d.ts +89 -15
- package/dist/vue/components/MCard.d.ts.map +1 -1
- package/dist/vue/components/MCard.js +12 -5
- package/dist/vue/components/MCard.js.map +1 -1
- package/dist/vue/components/MCheckbox.d.ts +20 -10
- package/dist/vue/components/MCheckbox.d.ts.map +1 -1
- package/dist/vue/components/MChip.d.ts +22 -12
- package/dist/vue/components/MChip.d.ts.map +1 -1
- package/dist/vue/components/MCombobox.d.ts +279 -0
- package/dist/vue/components/MCombobox.d.ts.map +1 -0
- package/dist/vue/components/MCombobox.js +234 -0
- package/dist/vue/components/MCombobox.js.map +1 -0
- package/dist/vue/components/MDatePicker.d.ts +1302 -0
- package/dist/vue/components/MDatePicker.d.ts.map +1 -0
- package/dist/vue/components/MDatePicker.js +35 -0
- package/dist/vue/components/MDatePicker.js.map +1 -0
- package/dist/vue/components/MDialog.d.ts +7 -5
- package/dist/vue/components/MDialog.d.ts.map +1 -1
- package/dist/vue/components/MEmptyState.d.ts +19 -9
- package/dist/vue/components/MEmptyState.d.ts.map +1 -1
- package/dist/vue/components/MFilePicker.d.ts +112 -0
- package/dist/vue/components/MFilePicker.d.ts.map +1 -0
- package/dist/vue/components/MFilePicker.js +196 -0
- package/dist/vue/components/MFilePicker.js.map +1 -0
- package/dist/vue/components/MIcon.d.ts +4 -2
- package/dist/vue/components/MIcon.d.ts.map +1 -1
- package/dist/vue/components/MInput.d.ts +132 -60
- package/dist/vue/components/MInput.d.ts.map +1 -1
- package/dist/vue/components/MInput.js +3 -3
- package/dist/vue/components/MInput.js.map +1 -1
- package/dist/vue/components/MLink.d.ts +120 -0
- package/dist/vue/components/MLink.d.ts.map +1 -0
- package/dist/vue/components/MLink.js +81 -0
- package/dist/vue/components/MLink.js.map +1 -0
- package/dist/vue/components/MListItem.d.ts +26 -12
- package/dist/vue/components/MListItem.d.ts.map +1 -1
- package/dist/vue/components/MProgress.d.ts +18 -8
- package/dist/vue/components/MProgress.d.ts.map +1 -1
- package/dist/vue/components/MRadioGroup.d.ts +19 -9
- package/dist/vue/components/MRadioGroup.d.ts.map +1 -1
- package/dist/vue/components/MReveal.d.ts +71 -35
- package/dist/vue/components/MReveal.d.ts.map +1 -1
- package/dist/vue/components/MReveal.js +80 -35
- package/dist/vue/components/MReveal.js.map +1 -1
- package/dist/vue/components/MScreen.d.ts +12 -6
- package/dist/vue/components/MScreen.d.ts.map +1 -1
- package/dist/vue/components/MSegmentedControl.d.ts +19 -9
- package/dist/vue/components/MSegmentedControl.d.ts.map +1 -1
- package/dist/vue/components/MSelect.d.ts +21 -11
- package/dist/vue/components/MSelect.d.ts.map +1 -1
- package/dist/vue/components/MSeparator.d.ts +4 -2
- package/dist/vue/components/MSeparator.d.ts.map +1 -1
- package/dist/vue/components/MSheet.d.ts +18 -12
- package/dist/vue/components/MSheet.d.ts.map +1 -1
- package/dist/vue/components/MSkeleton.d.ts +16 -8
- package/dist/vue/components/MSkeleton.d.ts.map +1 -1
- package/dist/vue/components/MSlider.d.ts +9 -5
- package/dist/vue/components/MSlider.d.ts.map +1 -1
- package/dist/vue/components/MStack.d.ts +199 -0
- package/dist/vue/components/MStack.d.ts.map +1 -0
- package/dist/vue/components/MStack.js +62 -0
- package/dist/vue/components/MStack.js.map +1 -0
- package/dist/vue/components/MSwitch.d.ts +19 -9
- package/dist/vue/components/MSwitch.d.ts.map +1 -1
- package/dist/vue/components/MTabs.d.ts +19 -9
- package/dist/vue/components/MTabs.d.ts.map +1 -1
- package/dist/vue/components/MText.d.ts +42 -26
- package/dist/vue/components/MText.d.ts.map +1 -1
- package/dist/vue/components/MText.js +3 -3
- package/dist/vue/components/MText.js.map +1 -1
- package/dist/vue/components/layout.d.ts +191 -82
- package/dist/vue/components/layout.d.ts.map +1 -1
- package/dist/vue/components/layout.js +9 -7
- package/dist/vue/components/layout.js.map +1 -1
- package/dist/vue/components/workflows.d.ts +251 -0
- package/dist/vue/components/workflows.d.ts.map +1 -0
- package/dist/vue/components/workflows.js +35 -0
- package/dist/vue/components/workflows.js.map +1 -0
- package/dist/vue/index.d.ts +9 -2
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +19 -2
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/navigation.d.ts +4 -0
- package/dist/vue/navigation.d.ts.map +1 -0
- package/dist/vue/navigation.js +16 -0
- package/dist/vue/navigation.js.map +1 -0
- package/dist/vue/reveal-motion.d.ts.map +1 -1
- package/dist/vue/reveal-motion.js +6 -3
- package/dist/vue/reveal-motion.js.map +1 -1
- package/dist/vue/use-motion-region.d.ts +7 -0
- package/dist/vue/use-motion-region.d.ts.map +1 -0
- package/dist/vue/use-motion-region.js +28 -0
- package/dist/vue/use-motion-region.js.map +1 -0
- package/dist/vue/use-motion-surface.d.ts.map +1 -1
- package/dist/vue/use-motion-surface.js +3 -2
- package/dist/vue/use-motion-surface.js.map +1 -1
- package/dist/vue/use-press.js +3 -3
- package/dist/vue/use-press.js.map +1 -1
- package/package.json +7 -3
- package/src/app-icons.ts +21 -0
- package/src/files.ts +3 -0
- package/src/native/app-icons.android.ts +95 -0
- package/src/native/app-icons.ios.ts +74 -0
- package/src/native/app-icons.ts +12 -0
- package/src/native/combobox-editor.android.ts +11 -0
- package/src/native/combobox-editor.ts +6 -0
- package/src/native/file-access.ts +71 -0
- package/src/native/file-picker.android.ts +191 -0
- package/src/native/file-picker.ios.ts +230 -0
- package/src/native/file-picker.ts +8 -0
- package/src/native/motion-owner.ts +65 -0
- package/src/native/motion-region.ts +275 -0
- package/src/native/motion-surface.ts +55 -2
- package/src/native/press.ts +3 -3
- package/src/native/scroll-motion.ts +5 -0
- package/src/vue/components/DateCalendar.ts +117 -0
- package/src/vue/components/MButton.ts +20 -10
- package/src/vue/components/MCard.ts +22 -5
- package/src/vue/components/MCombobox.ts +257 -0
- package/src/vue/components/MDatePicker.ts +33 -0
- package/src/vue/components/MFilePicker.ts +226 -0
- package/src/vue/components/MInput.ts +3 -3
- package/src/vue/components/MLink.ts +96 -0
- package/src/vue/components/MReveal.ts +89 -47
- package/src/vue/components/MStack.ts +83 -0
- package/src/vue/components/MText.ts +3 -3
- package/src/vue/components/layout.ts +15 -7
- package/src/vue/components/workflows.ts +38 -0
- package/src/vue/index.ts +35 -1
- package/src/vue/navigation.ts +15 -0
- package/src/vue/use-motion-region.ts +29 -0
- package/src/vue/use-motion-surface.ts +21 -14
- package/src/vue/use-press.ts +3 -3
- package/src/vue/reveal-motion.ts +0 -61
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createWorkflows } from '@getcortexlabs/mavis-core/vue'
|
|
2
|
+
import { MColumn, MRow } from './layout.js'
|
|
3
|
+
import { MText } from './MText.js'
|
|
4
|
+
import { MButton } from './MButton.js'
|
|
5
|
+
|
|
6
|
+
import { isAndroid, type View } from '@nativescript/core'
|
|
7
|
+
|
|
8
|
+
function focused(root: View): View | undefined {
|
|
9
|
+
if (isAndroid ? root.android?.isFocused() : root.ios?.isFirstResponder) return root
|
|
10
|
+
let match: View | undefined
|
|
11
|
+
root.eachChildView((child) => {
|
|
12
|
+
match = focused(child)
|
|
13
|
+
return !match
|
|
14
|
+
})
|
|
15
|
+
return match
|
|
16
|
+
}
|
|
17
|
+
function preserveFocus(instance: unknown, currentId: string) {
|
|
18
|
+
const root = (instance as { $el?: { nativeView?: View } } | undefined)?.$el?.nativeView
|
|
19
|
+
const previous = root && focused(root)
|
|
20
|
+
if (!root || !previous) return () => {}
|
|
21
|
+
return () => {
|
|
22
|
+
if (!root.isLoaded || (previous.isLoaded && previous.isEnabled)) return
|
|
23
|
+
const page = root.page
|
|
24
|
+
if (
|
|
25
|
+
!page ||
|
|
26
|
+
page.frame?.currentPage !== page ||
|
|
27
|
+
(!isAndroid && page.ios?.presentedViewController)
|
|
28
|
+
)
|
|
29
|
+
return
|
|
30
|
+
const active = focused(page)
|
|
31
|
+
if (!active || active === previous) root.getViewById<View>(currentId)?.focus()
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const { MFormGroup, MFormErrors, MSteps, MPagination } = createWorkflows(
|
|
36
|
+
{ Column: MColumn, Row: MRow, Text: MText, Button: MButton, preserveFocus },
|
|
37
|
+
'native',
|
|
38
|
+
)
|
package/src/vue/index.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { MStack } from './components/MStack.js'
|
|
2
|
+
import { MLink } from './components/MLink.js'
|
|
3
|
+
import { MDatePicker, MDateRangePicker } from './components/MDatePicker.js'
|
|
4
|
+
import { MCombobox } from './components/MCombobox.js'
|
|
5
|
+
import { MFilePicker } from './components/MFilePicker.js'
|
|
6
|
+
import { MFormGroup, MFormErrors, MSteps, MPagination } from './components/workflows.js'
|
|
1
7
|
import { MChip } from './components/MChip.js'
|
|
2
8
|
import { MEmptyState } from './components/MEmptyState.js'
|
|
3
9
|
import type { App } from 'nativescript-vue'
|
|
@@ -45,6 +51,8 @@ export {
|
|
|
45
51
|
MBox,
|
|
46
52
|
MRow,
|
|
47
53
|
MColumn,
|
|
54
|
+
MStack,
|
|
55
|
+
MLink,
|
|
48
56
|
MCard,
|
|
49
57
|
MText,
|
|
50
58
|
MButton,
|
|
@@ -71,8 +79,22 @@ export {
|
|
|
71
79
|
MIcon,
|
|
72
80
|
MReveal,
|
|
73
81
|
MSheet,
|
|
82
|
+
MDatePicker,
|
|
83
|
+
MDateRangePicker,
|
|
84
|
+
MCombobox,
|
|
85
|
+
MFilePicker,
|
|
86
|
+
MFormGroup,
|
|
87
|
+
MFormErrors,
|
|
88
|
+
MSteps,
|
|
89
|
+
MPagination,
|
|
74
90
|
}
|
|
75
|
-
export {
|
|
91
|
+
export {
|
|
92
|
+
useMavisTheme,
|
|
93
|
+
useToast,
|
|
94
|
+
useFormController,
|
|
95
|
+
useFormField,
|
|
96
|
+
useFileSelection,
|
|
97
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
76
98
|
export type {
|
|
77
99
|
MavisThemeContext,
|
|
78
100
|
Appearance,
|
|
@@ -107,6 +129,8 @@ export function createMavis(options: MavisOptions = {}) {
|
|
|
107
129
|
MBox,
|
|
108
130
|
MRow,
|
|
109
131
|
MColumn,
|
|
132
|
+
MStack,
|
|
133
|
+
MLink,
|
|
110
134
|
MCard,
|
|
111
135
|
MText,
|
|
112
136
|
MButton,
|
|
@@ -133,9 +157,19 @@ export function createMavis(options: MavisOptions = {}) {
|
|
|
133
157
|
MIcon,
|
|
134
158
|
MReveal,
|
|
135
159
|
MSheet,
|
|
160
|
+
MDatePicker,
|
|
161
|
+
MDateRangePicker,
|
|
162
|
+
MCombobox,
|
|
163
|
+
MFilePicker,
|
|
164
|
+
MFormGroup,
|
|
165
|
+
MFormErrors,
|
|
166
|
+
MSteps,
|
|
167
|
+
MPagination,
|
|
136
168
|
})) {
|
|
137
169
|
app.component(name, component)
|
|
138
170
|
}
|
|
139
171
|
},
|
|
140
172
|
}
|
|
141
173
|
}
|
|
174
|
+
|
|
175
|
+
export * from '../files.js'
|
|
@@ -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,29 @@
|
|
|
1
|
+
import { onBeforeUnmount, watch } from 'nativescript-vue'
|
|
2
|
+
import type { EventData, View } from '@nativescript/core'
|
|
3
|
+
import type { MotionRegion } from '@getcortexlabs/mavis-core/experimental'
|
|
4
|
+
import { attachNativeMotionRegion } from '../native/motion-region.js'
|
|
5
|
+
|
|
6
|
+
export function useMotionRegion(reference: () => MotionRegion | undefined) {
|
|
7
|
+
let target: View | undefined, release: (() => void) | undefined
|
|
8
|
+
const clear = () => {
|
|
9
|
+
release?.()
|
|
10
|
+
release = undefined
|
|
11
|
+
}
|
|
12
|
+
const attach = () => {
|
|
13
|
+
clear()
|
|
14
|
+
const region = reference()
|
|
15
|
+
if (region && target?.isLoaded) release = attachNativeMotionRegion(region, target)
|
|
16
|
+
}
|
|
17
|
+
watch(reference, attach, { flush: 'post' })
|
|
18
|
+
onBeforeUnmount(clear)
|
|
19
|
+
return {
|
|
20
|
+
onLoaded(event: EventData) {
|
|
21
|
+
target = event.object as View
|
|
22
|
+
attach()
|
|
23
|
+
},
|
|
24
|
+
onUnloaded() {
|
|
25
|
+
clear()
|
|
26
|
+
target = undefined
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
type MotionSurface,
|
|
8
8
|
} from '@getcortexlabs/mavis-core/experimental'
|
|
9
9
|
import { nativeContinuousSurface } from '../native/motion-surface.js'
|
|
10
|
+
import { nativeMotionOwner } from '../native/motion-owner.js'
|
|
10
11
|
|
|
11
12
|
export function useMotionSurface(
|
|
12
13
|
surface: () => MotionSurface | undefined,
|
|
@@ -32,20 +33,26 @@ export function useMotionSurface(
|
|
|
32
33
|
const reference = surface()
|
|
33
34
|
if (!target || !reference) return
|
|
34
35
|
continuous = nativeContinuousSurface(target, enabled)
|
|
35
|
-
unbind = bindMotionSurface(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
unbind = bindMotionSurface(
|
|
37
|
+
reference,
|
|
38
|
+
nativeMotionOwner(
|
|
39
|
+
{
|
|
40
|
+
...continuous.adapter,
|
|
41
|
+
animate(values, options) {
|
|
42
|
+
continuous?.interrupt(Object.keys(values))
|
|
43
|
+
const handle = animate(target, values, options)
|
|
44
|
+
active.set(handle, values)
|
|
45
|
+
void handle.finished.then(() => active.delete(handle))
|
|
46
|
+
return handle
|
|
47
|
+
},
|
|
48
|
+
set: (values) => {
|
|
49
|
+
continuous?.interrupt(Object.keys(values))
|
|
50
|
+
return animate(target, values, { duration: 0 })
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
target,
|
|
54
|
+
),
|
|
55
|
+
)
|
|
49
56
|
offPreference = onReducedMotion((reduced) => {
|
|
50
57
|
if (!reduced) return
|
|
51
58
|
// Set only spatial channels: opacity can keep its existing timeline.
|
package/src/vue/use-press.ts
CHANGED
|
@@ -17,15 +17,15 @@ export function usePressFeedback(
|
|
|
17
17
|
}
|
|
18
18
|
const refresh = () => {
|
|
19
19
|
if (view && enabled()) {
|
|
20
|
-
if (remove) remove.update(theme.value.motion
|
|
21
|
-
else remove = attachPressFeedback(view, theme.value.motion
|
|
20
|
+
if (remove) remove.update(theme.value.motion)
|
|
21
|
+
else remove = attachPressFeedback(view, theme.value.motion)
|
|
22
22
|
} else release()
|
|
23
23
|
}
|
|
24
24
|
const unloaded = () => {
|
|
25
25
|
release()
|
|
26
26
|
view = undefined
|
|
27
27
|
}
|
|
28
|
-
watch([enabled, () => theme.value.motion
|
|
28
|
+
watch([enabled, () => theme.value.motion], refresh, { flush: 'post' })
|
|
29
29
|
if (keyboard) watch(keyboard, (pressed) => remove?.press(pressed), { flush: 'sync' })
|
|
30
30
|
onBeforeUnmount(unloaded)
|
|
31
31
|
|
package/src/vue/reveal-motion.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { onBeforeUnmount } from 'nativescript-vue'
|
|
2
|
-
import type { View } from '@nativescript/core'
|
|
3
|
-
import { animate, set, onReducedMotion } from '@rafaelaugusto/jolt'
|
|
4
|
-
import { revealMotion } from '@getcortexlabs/mavis-core'
|
|
5
|
-
|
|
6
|
-
type Element = { nativeView: View }
|
|
7
|
-
|
|
8
|
-
/** Each transition owns its completion; an interrupted leave cannot finish a new entry. */
|
|
9
|
-
export function useRevealMotion() {
|
|
10
|
-
const entered = new WeakSet<View>()
|
|
11
|
-
const active = new Map<
|
|
12
|
-
View,
|
|
13
|
-
{ handle: ReturnType<typeof animate>; phase: 'enter' | 'leave'; remove: () => void }
|
|
14
|
-
>()
|
|
15
|
-
const cancel = ({ nativeView: view }: Element) => {
|
|
16
|
-
const operation = active.get(view)
|
|
17
|
-
if (!operation) return
|
|
18
|
-
active.delete(view)
|
|
19
|
-
operation.remove()
|
|
20
|
-
operation.handle.stop()
|
|
21
|
-
}
|
|
22
|
-
const run = (phase: 'enter' | 'leave') => (element: Element, done: () => void) => {
|
|
23
|
-
const view = element.nativeView
|
|
24
|
-
cancel(element)
|
|
25
|
-
if (phase === 'enter' && !entered.has(view)) {
|
|
26
|
-
entered.add(view)
|
|
27
|
-
set(view, { opacity: revealMotion.enter[0].opacity[0], y: revealMotion.enter[0].y[0] })
|
|
28
|
-
}
|
|
29
|
-
const handle = animate(
|
|
30
|
-
view,
|
|
31
|
-
phase === 'enter' ? { opacity: 1, y: 0 } : revealMotion.leave[0],
|
|
32
|
-
revealMotion[phase][1],
|
|
33
|
-
)
|
|
34
|
-
const unloaded = () => cancel(element)
|
|
35
|
-
const operation = { handle, phase, remove: () => view.off('unloaded', unloaded) }
|
|
36
|
-
active.set(view, operation)
|
|
37
|
-
view.on('unloaded', unloaded)
|
|
38
|
-
void handle.finished.then(() => {
|
|
39
|
-
if (active.get(view) !== operation) return
|
|
40
|
-
active.delete(view)
|
|
41
|
-
operation.remove()
|
|
42
|
-
done()
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
const offPreference = onReducedMotion((reduced) => {
|
|
46
|
-
if (reduced)
|
|
47
|
-
for (const [view, operation] of active) {
|
|
48
|
-
if (operation.phase === 'enter') set(view, { y: 0 })
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
onBeforeUnmount(() => {
|
|
52
|
-
offPreference()
|
|
53
|
-
for (const view of active.keys()) cancel({ nativeView: view })
|
|
54
|
-
})
|
|
55
|
-
return {
|
|
56
|
-
onEnter: run('enter'),
|
|
57
|
-
onLeave: run('leave'),
|
|
58
|
-
onEnterCancelled: cancel,
|
|
59
|
-
onLeaveCancelled: cancel,
|
|
60
|
-
}
|
|
61
|
-
}
|