@getcortexlabs/mavis 0.1.0-alpha.1 → 0.1.0-alpha.3
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 +4 -4
- package/dist/native/appearance.android.d.ts +4 -0
- package/dist/native/appearance.android.d.ts.map +1 -0
- package/dist/native/appearance.android.js +55 -0
- package/dist/native/appearance.android.js.map +1 -0
- package/dist/native/appearance.d.ts +4 -0
- package/dist/native/appearance.d.ts.map +1 -0
- package/dist/native/appearance.js +31 -0
- package/dist/native/appearance.js.map +1 -0
- package/dist/native/box.android.d.ts +5 -0
- package/dist/native/box.android.d.ts.map +1 -0
- package/dist/native/box.android.js +7 -0
- package/dist/native/box.android.js.map +1 -0
- package/dist/native/box.d.ts +2 -0
- package/dist/native/box.d.ts.map +1 -0
- package/dist/native/box.ios.d.ts +10 -0
- package/dist/native/box.ios.d.ts.map +1 -0
- package/dist/native/box.ios.js +25 -0
- package/dist/native/box.ios.js.map +1 -0
- package/dist/native/box.js +3 -0
- package/dist/native/box.js.map +1 -0
- package/dist/native/button.android.d.ts +11 -0
- package/dist/native/button.android.d.ts.map +1 -0
- package/dist/native/button.android.js +31 -0
- package/dist/native/button.android.js.map +1 -0
- package/dist/native/button.ios.d.ts +4 -0
- package/dist/native/button.ios.d.ts.map +1 -1
- package/dist/native/button.ios.js +12 -0
- package/dist/native/button.ios.js.map +1 -1
- package/dist/native/flex-children.d.ts +4 -0
- package/dist/native/flex-children.d.ts.map +1 -0
- package/dist/native/flex-children.js +12 -0
- package/dist/native/flex-children.js.map +1 -0
- package/dist/native/flex-layout.android.d.ts +3 -1
- package/dist/native/flex-layout.android.d.ts.map +1 -1
- package/dist/native/flex-layout.android.js +9 -0
- package/dist/native/flex-layout.android.js.map +1 -1
- package/dist/native/flex-layout.ios.d.ts +9 -1
- package/dist/native/flex-layout.ios.d.ts.map +1 -1
- package/dist/native/flex-layout.ios.js +52 -0
- package/dist/native/flex-layout.ios.js.map +1 -1
- package/dist/native/keyboard-dismiss.android.d.ts +8 -0
- package/dist/native/keyboard-dismiss.android.d.ts.map +1 -0
- package/dist/native/keyboard-dismiss.android.js +9 -0
- package/dist/native/keyboard-dismiss.android.js.map +1 -0
- package/dist/native/keyboard-dismiss.d.ts +10 -0
- package/dist/native/keyboard-dismiss.d.ts.map +1 -0
- package/dist/native/keyboard-dismiss.ios.d.ts +8 -0
- package/dist/native/keyboard-dismiss.ios.d.ts.map +1 -0
- package/dist/native/keyboard-dismiss.ios.js +88 -0
- package/dist/native/keyboard-dismiss.ios.js.map +1 -0
- package/dist/native/keyboard-dismiss.js +6 -0
- package/dist/native/keyboard-dismiss.js.map +1 -0
- package/dist/native/label.ios.d.ts +4 -0
- package/dist/native/label.ios.d.ts.map +1 -1
- package/dist/native/label.ios.js +12 -0
- package/dist/native/label.ios.js.map +1 -1
- package/dist/native/measure-memo.d.ts +37 -0
- package/dist/native/measure-memo.d.ts.map +1 -0
- package/dist/native/measure-memo.js +82 -0
- package/dist/native/measure-memo.js.map +1 -0
- package/dist/native/screen.android.d.ts +6 -0
- package/dist/native/screen.android.d.ts.map +1 -0
- package/dist/native/screen.android.js +8 -0
- package/dist/native/screen.android.js.map +1 -0
- package/dist/native/screen.d.ts +2 -0
- package/dist/native/screen.d.ts.map +1 -0
- package/dist/native/screen.js +3 -0
- package/dist/native/screen.js.map +1 -0
- package/dist/native/sheet.android.d.ts +14 -0
- package/dist/native/sheet.android.d.ts.map +1 -0
- package/dist/native/sheet.android.js +16 -0
- package/dist/native/sheet.android.js.map +1 -0
- package/dist/native/sheet.d.ts +17 -0
- package/dist/native/sheet.d.ts.map +1 -0
- package/dist/native/sheet.ios.d.ts +15 -0
- package/dist/native/sheet.ios.d.ts.map +1 -0
- package/dist/native/sheet.ios.js +32 -0
- package/dist/native/sheet.ios.js.map +1 -0
- package/dist/native/sheet.js +17 -0
- package/dist/native/sheet.js.map +1 -0
- package/dist/vue/components/MButton.d.ts +26 -8
- package/dist/vue/components/MButton.d.ts.map +1 -1
- package/dist/vue/components/MButton.js +25 -6
- package/dist/vue/components/MButton.js.map +1 -1
- package/dist/vue/components/MCard.d.ts +3 -3
- package/dist/vue/components/MIcon.d.ts +55 -0
- package/dist/vue/components/MIcon.d.ts.map +1 -0
- package/dist/vue/components/MIcon.js +34 -0
- package/dist/vue/components/MIcon.js.map +1 -0
- package/dist/vue/components/MInput.d.ts +32 -14
- package/dist/vue/components/MInput.d.ts.map +1 -1
- package/dist/vue/components/MInput.js +26 -5
- package/dist/vue/components/MInput.js.map +1 -1
- package/dist/vue/components/MReveal.d.ts +4 -4
- package/dist/vue/components/MReveal.js +1 -1
- package/dist/vue/components/MReveal.js.map +1 -1
- package/dist/vue/components/MScreen.d.ts +10 -1
- package/dist/vue/components/MScreen.d.ts.map +1 -1
- package/dist/vue/components/MScreen.js +54 -6
- package/dist/vue/components/MScreen.js.map +1 -1
- package/dist/vue/components/MSheet.d.ts +95 -0
- package/dist/vue/components/MSheet.d.ts.map +1 -0
- package/dist/vue/components/MSheet.js +281 -0
- package/dist/vue/components/MSheet.js.map +1 -0
- package/dist/vue/components/MSlider.js +1 -1
- package/dist/vue/components/MSlider.js.map +1 -1
- package/dist/vue/components/MText.d.ts +2 -2
- package/dist/vue/components/MText.js +1 -1
- package/dist/vue/components/MText.js.map +1 -1
- package/dist/vue/components/layout.d.ts +11 -11
- package/dist/vue/components/layout.d.ts.map +1 -1
- package/dist/vue/components/layout.js +4 -2
- package/dist/vue/components/layout.js.map +1 -1
- package/dist/vue/index.d.ts +13 -7
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +14 -5
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/layers.d.ts +17 -0
- package/dist/vue/layers.d.ts.map +1 -0
- package/dist/vue/layers.js +26 -0
- package/dist/vue/layers.js.map +1 -0
- package/dist/vue/native-view.d.ts +6 -0
- package/dist/vue/native-view.d.ts.map +1 -0
- package/dist/vue/native-view.js +5 -0
- package/dist/vue/native-view.js.map +1 -0
- package/dist/vue/props.d.ts +12 -11
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +25 -10
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/system-back.d.ts +11 -0
- package/dist/vue/system-back.d.ts.map +1 -0
- package/dist/vue/system-back.js +2 -0
- package/dist/vue/system-back.js.map +1 -0
- package/fonts/LICENSE +45 -0
- package/fonts/lucide.ttf +0 -0
- package/package.json +3 -2
- package/platforms/android/java/com/mavis/ui/Box.java +63 -0
- package/platforms/android/java/com/mavis/ui/FlexLayout.java +97 -4
- package/platforms/android/java/com/mavis/ui/MeasureMemo.java +145 -0
- package/platforms/android/java/com/mavis/ui/Screen.java +108 -0
- package/src/native/appearance.android.ts +75 -0
- package/src/native/appearance.ts +33 -0
- package/src/native/box.android.ts +11 -0
- package/src/native/box.ios.ts +41 -0
- package/src/native/box.ts +2 -0
- package/src/native/button.android.ts +38 -0
- package/src/native/button.ios.ts +14 -0
- package/src/native/flex-children.ts +12 -0
- package/src/native/flex-layout.android.ts +12 -1
- package/src/native/flex-layout.ios.ts +76 -1
- package/src/native/keyboard-dismiss.android.ts +17 -0
- package/src/native/keyboard-dismiss.ios.ts +122 -0
- package/src/native/keyboard-dismiss.ts +14 -0
- package/src/native/label.ios.ts +14 -0
- package/src/native/measure-memo.ts +116 -0
- package/src/native/screen.android.ts +12 -0
- package/src/native/screen.ts +2 -0
- package/src/native/sheet.android.ts +24 -0
- package/src/native/sheet.ios.ts +43 -0
- package/src/native/sheet.ts +26 -0
- package/src/vue/components/MButton.ts +32 -5
- package/src/vue/components/MIcon.ts +41 -0
- package/src/vue/components/MInput.ts +27 -4
- package/src/vue/components/MReveal.ts +1 -1
- package/src/vue/components/MScreen.ts +79 -6
- package/src/vue/components/MSheet.ts +335 -0
- package/src/vue/components/MSlider.ts +1 -1
- package/src/vue/components/MText.ts +1 -1
- package/src/vue/components/layout.ts +4 -2
- package/src/vue/index.ts +45 -8
- package/src/vue/layers.ts +46 -0
- package/src/vue/native-view.ts +6 -0
- package/src/vue/props.ts +37 -12
- package/src/vue/system-back.ts +12 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { ScrollView, type View } from '@nativescript/core'
|
|
2
|
+
|
|
3
|
+
export interface KeyboardDismissal {
|
|
4
|
+
tap: boolean
|
|
5
|
+
drag: boolean
|
|
6
|
+
}
|
|
7
|
+
interface NativeView {
|
|
8
|
+
superview: NativeView | null
|
|
9
|
+
subviews: { count: number; objectAtIndex(index: number): NativeView }
|
|
10
|
+
isFirstResponder: boolean
|
|
11
|
+
isEqual(other: NativeView): boolean
|
|
12
|
+
endEditing(force: boolean): boolean
|
|
13
|
+
addGestureRecognizer(recognizer: Recognizer): void
|
|
14
|
+
removeGestureRecognizer(recognizer: Recognizer): void
|
|
15
|
+
}
|
|
16
|
+
interface Recognizer {
|
|
17
|
+
view: NativeView
|
|
18
|
+
delegate: unknown
|
|
19
|
+
cancelsTouchesInView: boolean
|
|
20
|
+
delaysTouchesEnded: boolean
|
|
21
|
+
}
|
|
22
|
+
interface NativeClass {
|
|
23
|
+
extend(members: object, options: object): { new (): object }
|
|
24
|
+
}
|
|
25
|
+
declare const NSObject: NativeClass
|
|
26
|
+
declare const UITapGestureRecognizer: {
|
|
27
|
+
alloc(): { initWithTargetAction(target: object, action: string): Recognizer }
|
|
28
|
+
}
|
|
29
|
+
declare const UIGestureRecognizerDelegate: unknown
|
|
30
|
+
declare const UITextField: unknown
|
|
31
|
+
declare const UITextView: unknown
|
|
32
|
+
declare const UIGestureRecognizer: unknown
|
|
33
|
+
declare const interop: { types: { void: unknown } }
|
|
34
|
+
|
|
35
|
+
const editor = (view: NativeView | null) => {
|
|
36
|
+
for (let current = view; current; current = current.superview) {
|
|
37
|
+
if (current instanceof (UITextField as never) || current instanceof (UITextView as never))
|
|
38
|
+
return true
|
|
39
|
+
}
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const firstResponder = (view: NativeView): NativeView | null => {
|
|
44
|
+
if (view.isFirstResponder) return view
|
|
45
|
+
const subviews = view.subviews
|
|
46
|
+
for (let index = 0; index < subviews.count; index++) {
|
|
47
|
+
const found = firstResponder(subviews.objectAtIndex(index))
|
|
48
|
+
if (found) return found
|
|
49
|
+
}
|
|
50
|
+
return null
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// The recognizer only observes: it never cancels or delays the touches of the controls below
|
|
54
|
+
// it, and it recognizes together with the gesture recognizers of Core and Jolt. It takes a
|
|
55
|
+
// touch only while an editor is active and the touch is not on an editor. UIKit runs the tap
|
|
56
|
+
// action after the control's own action, so a control that focused another editor meanwhile
|
|
57
|
+
// keeps that focus.
|
|
58
|
+
let editing: NativeView | null = null
|
|
59
|
+
let Delegate: { new (): object } | undefined
|
|
60
|
+
let Target: { new (): object } | undefined
|
|
61
|
+
function classes() {
|
|
62
|
+
Delegate ??= NSObject.extend(
|
|
63
|
+
{
|
|
64
|
+
gestureRecognizerShouldReceiveTouch(recognizer: Recognizer, touch: { view: NativeView }) {
|
|
65
|
+
editing = editor(touch.view) ? null : firstResponder(recognizer.view)
|
|
66
|
+
return editing !== null
|
|
67
|
+
},
|
|
68
|
+
gestureRecognizerShouldRecognizeSimultaneouslyWithGestureRecognizer() {
|
|
69
|
+
return true
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{ protocols: [UIGestureRecognizerDelegate] },
|
|
73
|
+
)
|
|
74
|
+
Target ??= NSObject.extend(
|
|
75
|
+
{
|
|
76
|
+
dismiss(recognizer: Recognizer) {
|
|
77
|
+
const current = firstResponder(recognizer.view)
|
|
78
|
+
if (editing && current?.isEqual(editing)) recognizer.view.endEditing(true)
|
|
79
|
+
editing = null
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
{ exposedMethods: { dismiss: { returns: interop.types.void, params: [UIGestureRecognizer] } } },
|
|
83
|
+
)
|
|
84
|
+
return { Delegate, Target }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A tap recognizer on the page container; the scroll view follows the drag with the keyboard. */
|
|
88
|
+
export function dismissKeyboardOn(container: View, options: KeyboardDismissal): () => void {
|
|
89
|
+
const native = container.ios as NativeView | undefined
|
|
90
|
+
if (!native) return () => {}
|
|
91
|
+
let recognizer: Recognizer | undefined
|
|
92
|
+
// The recognizer keeps neither object alive for the runtime: hold both until release.
|
|
93
|
+
let delegate: object | undefined
|
|
94
|
+
let target: object | undefined
|
|
95
|
+
if (options.tap) {
|
|
96
|
+
const { Delegate, Target } = classes()
|
|
97
|
+
delegate = new Delegate()
|
|
98
|
+
target = new Target()
|
|
99
|
+
recognizer = UITapGestureRecognizer.alloc().initWithTargetAction(target, 'dismiss')
|
|
100
|
+
recognizer.cancelsTouchesInView = false
|
|
101
|
+
recognizer.delaysTouchesEnded = false
|
|
102
|
+
recognizer.delegate = delegate
|
|
103
|
+
native.addGestureRecognizer(recognizer)
|
|
104
|
+
}
|
|
105
|
+
let scroll: ScrollView | undefined
|
|
106
|
+
container.eachChildView((child) => {
|
|
107
|
+
if (child instanceof ScrollView) scroll = child
|
|
108
|
+
return !scroll
|
|
109
|
+
})
|
|
110
|
+
// UIScrollViewKeyboardDismissMode: none (0) or interactive (2).
|
|
111
|
+
if (scroll?.ios) scroll.ios.keyboardDismissMode = options.drag ? 2 : 0
|
|
112
|
+
return () => {
|
|
113
|
+
if (recognizer) {
|
|
114
|
+
native.removeGestureRecognizer(recognizer)
|
|
115
|
+
recognizer.delegate = null
|
|
116
|
+
}
|
|
117
|
+
recognizer = undefined
|
|
118
|
+
delegate = undefined
|
|
119
|
+
target = undefined
|
|
120
|
+
if (scroll?.ios) scroll.ios.keyboardDismissMode = 0
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { View } from '@nativescript/core'
|
|
2
|
+
|
|
3
|
+
export interface KeyboardDismissal {
|
|
4
|
+
/** A tap anywhere on the page that is not an editor. */
|
|
5
|
+
tap: boolean
|
|
6
|
+
/** A drag of the scrolling content. */
|
|
7
|
+
drag: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// NativeScript resolves the platform implementation before loading this module.
|
|
11
|
+
/** Puts the software keyboard away for the given gestures until the returned function runs. */
|
|
12
|
+
export function dismissKeyboardOn(_container: View, _options: KeyboardDismissal): () => void {
|
|
13
|
+
return () => {}
|
|
14
|
+
}
|
package/src/native/label.ios.ts
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { Label, Utils } from '@nativescript/core'
|
|
2
|
+
import { recordMeasurement, reuseMeasurement, type MeasureRecord } from './measure-memo'
|
|
2
3
|
|
|
3
4
|
export class MavisLabel extends Label {
|
|
5
|
+
measureRecord?: MeasureRecord
|
|
6
|
+
|
|
7
|
+
measure(widthSpec: number, heightSpec: number) {
|
|
8
|
+
if (reuseMeasurement(this, widthSpec, heightSpec)) return
|
|
9
|
+
super.measure(widthSpec, heightSpec)
|
|
10
|
+
recordMeasurement(this, widthSpec, heightSpec)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
requestLayout() {
|
|
14
|
+
this.measureRecord = undefined
|
|
15
|
+
super.requestLayout()
|
|
16
|
+
}
|
|
17
|
+
|
|
4
18
|
disposeNativeView() {
|
|
5
19
|
const native = this.nativeViewProtected
|
|
6
20
|
super.disposeNativeView()
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Utils, type View } from '@nativescript/core'
|
|
2
|
+
|
|
3
|
+
const { layout } = Utils
|
|
4
|
+
|
|
5
|
+
interface ChildRecord {
|
|
6
|
+
view: View
|
|
7
|
+
widthSpec: number
|
|
8
|
+
heightSpec: number
|
|
9
|
+
width: number
|
|
10
|
+
height: number
|
|
11
|
+
}
|
|
12
|
+
export interface MeasureRecord {
|
|
13
|
+
widthSpec: number
|
|
14
|
+
heightSpec: number
|
|
15
|
+
width: number
|
|
16
|
+
height: number
|
|
17
|
+
percent: boolean
|
|
18
|
+
/** The looser request clamped content that wanted more room; an exact size would shrink it. */
|
|
19
|
+
clamped: boolean
|
|
20
|
+
children: ChildRecord[]
|
|
21
|
+
}
|
|
22
|
+
interface Internals {
|
|
23
|
+
_currentWidthMeasureSpec: number
|
|
24
|
+
_currentHeightMeasureSpec: number
|
|
25
|
+
_measuredWidth: number
|
|
26
|
+
_measuredHeight: number
|
|
27
|
+
_setCurrentMeasureSpecs(widthSpec: number, heightSpec: number): boolean
|
|
28
|
+
isLayoutRequested: boolean
|
|
29
|
+
}
|
|
30
|
+
export interface Memoized extends View {
|
|
31
|
+
measureRecord?: MeasureRecord
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const isPercent = (value: unknown) =>
|
|
35
|
+
typeof value === 'object' && value !== null && (value as { unit?: string }).unit === '%'
|
|
36
|
+
|
|
37
|
+
// An exact request for the size a looser request produced is the same measurement, unless a
|
|
38
|
+
// child resolves a percentage against the request itself or the looser request clamped content
|
|
39
|
+
// that wanted more room: an exact size would then shrink the children instead. Core keeps the
|
|
40
|
+
// too-small state only for widths, so layouts report clamping themselves.
|
|
41
|
+
function matches(spec: number, record: MeasureRecord, recordedSpec: number, sizeAndState: number) {
|
|
42
|
+
if (spec === recordedSpec) return true
|
|
43
|
+
if (record.percent || record.clamped) return false
|
|
44
|
+
if (layout.getMeasureSpecMode(spec) !== layout.EXACTLY) return false
|
|
45
|
+
if (layout.getMeasureSpecMode(recordedSpec) === layout.EXACTLY) return false
|
|
46
|
+
if (sizeAndState & layout.MEASURED_STATE_TOO_SMALL) return false
|
|
47
|
+
return layout.getMeasureSpecSize(spec) === (sizeAndState & layout.MEASURED_SIZE_MASK)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Whether a looser request on either axis returned its whole limit; for layouts that cannot tell. */
|
|
51
|
+
export function filledLimit(widthSpec: number, heightSpec: number, width: number, height: number) {
|
|
52
|
+
const filled = (spec: number, size: number) =>
|
|
53
|
+
layout.getMeasureSpecMode(spec) === layout.AT_MOST &&
|
|
54
|
+
(size & layout.MEASURED_SIZE_MASK) >= layout.getMeasureSpecSize(spec)
|
|
55
|
+
return filled(widthSpec, width) || filled(heightSpec, height)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Core measures a view again whenever its parent asks while a layout request is pending, and
|
|
60
|
+
* flex containers ask several times per pass, so nested containers measure their leaves an
|
|
61
|
+
* exponential number of times. While nothing in the subtree asked for layout, the recorded
|
|
62
|
+
* measurement answers a repeated request and the children are measured again from their records.
|
|
63
|
+
*/
|
|
64
|
+
export function reuseMeasurement(view: Memoized, widthSpec: number, heightSpec: number) {
|
|
65
|
+
const record = view.measureRecord
|
|
66
|
+
const internals = view as unknown as Internals
|
|
67
|
+
if (!record || !internals.isLayoutRequested) return false
|
|
68
|
+
if (!matches(widthSpec, record, record.widthSpec, record.width)) return false
|
|
69
|
+
if (!matches(heightSpec, record, record.heightSpec, record.height)) return false
|
|
70
|
+
internals._setCurrentMeasureSpecs(widthSpec, heightSpec)
|
|
71
|
+
for (const child of record.children) {
|
|
72
|
+
const current = child.view as unknown as Internals
|
|
73
|
+
// A child still holding the recorded result was measured by this record's pass.
|
|
74
|
+
if (current._measuredWidth === child.width && current._measuredHeight === child.height) continue
|
|
75
|
+
child.view.measure(child.widthSpec, child.heightSpec)
|
|
76
|
+
}
|
|
77
|
+
view.setMeasuredDimension(record.width, record.height)
|
|
78
|
+
return true
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Stores the measurement that just completed with the specs every child last received. */
|
|
82
|
+
export function recordMeasurement(
|
|
83
|
+
view: Memoized,
|
|
84
|
+
widthSpec: number,
|
|
85
|
+
heightSpec: number,
|
|
86
|
+
children: readonly View[] = [],
|
|
87
|
+
clamped = false,
|
|
88
|
+
) {
|
|
89
|
+
const internals = view as unknown as Internals
|
|
90
|
+
view.measureRecord = {
|
|
91
|
+
widthSpec,
|
|
92
|
+
heightSpec,
|
|
93
|
+
width: internals._measuredWidth,
|
|
94
|
+
height: internals._measuredHeight,
|
|
95
|
+
percent: children.some((child) => isPercent(child.width) || isPercent(child.height)),
|
|
96
|
+
clamped,
|
|
97
|
+
children: children.map((child) => {
|
|
98
|
+
const specs = child as unknown as Internals
|
|
99
|
+
return {
|
|
100
|
+
view: child,
|
|
101
|
+
widthSpec: specs._currentWidthMeasureSpec,
|
|
102
|
+
heightSpec: specs._currentHeightMeasureSpec,
|
|
103
|
+
width: specs._measuredWidth,
|
|
104
|
+
height: specs._measuredHeight,
|
|
105
|
+
}
|
|
106
|
+
}),
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function layoutChildren(view: { eachLayoutChild(callback: (child: View) => void): void }) {
|
|
111
|
+
const children: View[] = []
|
|
112
|
+
view.eachLayoutChild((child) => {
|
|
113
|
+
children.push(child)
|
|
114
|
+
})
|
|
115
|
+
return children
|
|
116
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GridLayout } from '@nativescript/core'
|
|
2
|
+
|
|
3
|
+
declare const com: {
|
|
4
|
+
mavis: { ui: { Screen: new (context: unknown) => object } }
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/** The page container sees every touch of the page and can put the keyboard away. */
|
|
8
|
+
export class MavisScreen extends GridLayout {
|
|
9
|
+
createNativeView() {
|
|
10
|
+
return new com.mavis.ui.Screen(this._context)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Application, type View } from '@nativescript/core'
|
|
2
|
+
|
|
3
|
+
export interface BackPress {
|
|
4
|
+
cancel: boolean
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function watchBack(handler: (event: BackPress) => void): () => void {
|
|
8
|
+
const event = Application.android.activityBackPressedEvent
|
|
9
|
+
Application.android.on(event, handler)
|
|
10
|
+
return () => Application.android.off(event, handler)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function setModal(_panel: View, _modal: boolean) {}
|
|
14
|
+
|
|
15
|
+
/** The Android window keeps the page inside the system bars, so the host needs no insets. */
|
|
16
|
+
export function safeAreaOf(_host: View): { readonly top: number; readonly bottom: number } {
|
|
17
|
+
return { top: 0, bottom: 0 }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function expandLayerHost(_host: View) {}
|
|
21
|
+
|
|
22
|
+
export function bottomInset(_host: View): number {
|
|
23
|
+
return 0
|
|
24
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { View } from '@nativescript/core'
|
|
2
|
+
|
|
3
|
+
export interface BackPress {
|
|
4
|
+
cancel: boolean
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function watchBack(_handler: (event: BackPress) => void): () => void {
|
|
8
|
+
return () => {}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function setModal(panel: View, modal: boolean) {
|
|
12
|
+
const native = panel.ios as { accessibilityViewIsModal: boolean } | undefined
|
|
13
|
+
if (native) native.accessibilityViewIsModal = modal
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface Insets {
|
|
17
|
+
top: number
|
|
18
|
+
bottom: number
|
|
19
|
+
}
|
|
20
|
+
const windowInsets = (view: View): Insets | undefined =>
|
|
21
|
+
(view.page?.ios as { safeAreaInsets?: Insets } | undefined)?.safeAreaInsets
|
|
22
|
+
|
|
23
|
+
/** The page lays its content inside the safe area; the host grows back over it with negative margins. */
|
|
24
|
+
export function expandLayerHost(host: View) {
|
|
25
|
+
const insets = windowInsets(host)
|
|
26
|
+
if (!insets) return
|
|
27
|
+
if (host.marginTop !== -insets.top) host.marginTop = -insets.top
|
|
28
|
+
if (host.marginBottom !== -insets.bottom) host.marginBottom = -insets.bottom
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Keeps the panel below the status bar; the panel itself pads its content above the home indicator. */
|
|
32
|
+
export function safeAreaOf(host: View): { readonly top: number; readonly bottom: number } {
|
|
33
|
+
return {
|
|
34
|
+
get top() {
|
|
35
|
+
return windowInsets(host)?.top ?? 0
|
|
36
|
+
},
|
|
37
|
+
bottom: 0,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function bottomInset(host: View): number {
|
|
42
|
+
return windowInsets(host)?.bottom ?? 0
|
|
43
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { View } from '@nativescript/core'
|
|
2
|
+
|
|
3
|
+
export interface BackPress {
|
|
4
|
+
cancel: boolean
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// NativeScript resolves the platform implementation before loading this module.
|
|
8
|
+
/** Android reports the back press before the sheet handles it; other platforms have none. */
|
|
9
|
+
export function watchBack(_handler: (event: BackPress) => void): () => void {
|
|
10
|
+
return () => {}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** iOS keeps VoiceOver inside a modal view; Android hides the covered content instead. */
|
|
14
|
+
export function setModal(_panel: View, _modal: boolean) {}
|
|
15
|
+
|
|
16
|
+
/** Safe-area insets around the sheet host, in DIPs; only iOS reports them. */
|
|
17
|
+
export function safeAreaOf(_host: View): { readonly top: number; readonly bottom: number } {
|
|
18
|
+
return { top: 0, bottom: 0 }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Lets the layer host cover the whole window; only iOS insets it by default. */
|
|
22
|
+
export function expandLayerHost(_host: View) {}
|
|
23
|
+
|
|
24
|
+
export function bottomInset(_host: View): number {
|
|
25
|
+
return 0
|
|
26
|
+
}
|
|
@@ -6,10 +6,16 @@ import {
|
|
|
6
6
|
textContent,
|
|
7
7
|
useDefaultShrink,
|
|
8
8
|
} from '@getcortexlabs/mavis-core/vue'
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
nonNegative,
|
|
11
|
+
iconGlyph,
|
|
12
|
+
iconFontFamily,
|
|
13
|
+
iconSizes,
|
|
14
|
+
checkIconOnly,
|
|
15
|
+
} from '@getcortexlabs/mavis-core'
|
|
10
16
|
import { isAndroid } from '@nativescript/core'
|
|
11
17
|
import { usePressFeedback } from '../use-press.js'
|
|
12
|
-
import { MavisButton } from '../../native/button
|
|
18
|
+
import { MavisButton } from '../../native/button'
|
|
13
19
|
import { useNativeViewAttrs } from '../accessibility.js'
|
|
14
20
|
|
|
15
21
|
registerElement('MavisButton', () => MavisButton)
|
|
@@ -32,19 +38,30 @@ export const MButton = defineComponent({
|
|
|
32
38
|
const text = props.loading
|
|
33
39
|
? props.loadingText
|
|
34
40
|
: (props.text ?? textContent(slots.default?.()))
|
|
41
|
+
const hasIcon = Boolean(props.icon || props.trailingIcon)
|
|
42
|
+
checkIconOnly(text, hasIcon, props.accessibilityLabel)
|
|
43
|
+
const iconSize = iconSizes[props.size]
|
|
44
|
+
const minHeight = Math.max(size.height, isAndroid ? 48 : 44)
|
|
45
|
+
const paddingX = hasIcon && !text ? Math.round((minHeight - iconSize) / 2) : size.padding
|
|
46
|
+
const span = (name: typeof props.icon) =>
|
|
47
|
+
name
|
|
48
|
+
? h('Span', { text: iconGlyph(name), fontFamily: iconFontFamily, fontSize: iconSize })
|
|
49
|
+
: null
|
|
35
50
|
return h(
|
|
36
51
|
'MavisButton',
|
|
37
52
|
mergeProps(
|
|
38
53
|
{
|
|
39
54
|
// Android builds the accessible description from the current text.
|
|
40
55
|
// Apply it before updating the label/value during the same render.
|
|
56
|
+
// Core ignores text while spans render, so the plain text keeps the description short.
|
|
41
57
|
text,
|
|
58
|
+
...(hasIcon ? {} : { formattedText: null }),
|
|
42
59
|
textWrap: true,
|
|
43
60
|
iosAccessibilityAdjustsFontSize: true,
|
|
44
61
|
style: {
|
|
45
|
-
minHeight
|
|
46
|
-
paddingLeft:
|
|
47
|
-
paddingRight:
|
|
62
|
+
minHeight,
|
|
63
|
+
paddingLeft: paddingX,
|
|
64
|
+
paddingRight: paddingX,
|
|
48
65
|
paddingTop: 12,
|
|
49
66
|
paddingBottom: 12,
|
|
50
67
|
fontSize: size.fontSize,
|
|
@@ -83,6 +100,16 @@ export const MButton = defineComponent({
|
|
|
83
100
|
},
|
|
84
101
|
},
|
|
85
102
|
),
|
|
103
|
+
hasIcon
|
|
104
|
+
? [
|
|
105
|
+
h('FormattedString', {}, [
|
|
106
|
+
span(props.icon),
|
|
107
|
+
text ? h('Span', { text: props.icon ? ` ${text}` : text }) : null,
|
|
108
|
+
props.trailingIcon && text ? h('Span', { text: ' ' }) : null,
|
|
109
|
+
span(props.trailingIcon),
|
|
110
|
+
]),
|
|
111
|
+
]
|
|
112
|
+
: undefined,
|
|
86
113
|
)
|
|
87
114
|
}
|
|
88
115
|
},
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { defineComponent, h, mergeProps, registerElement } from 'nativescript-vue'
|
|
2
|
+
import { iconProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
import { iconFontFamily, iconGlyph, resolveIconSize } from '@getcortexlabs/mavis-core'
|
|
4
|
+
import { MavisLabel } from '../../native/label'
|
|
5
|
+
|
|
6
|
+
registerElement('MavisIcon', () => MavisLabel)
|
|
7
|
+
|
|
8
|
+
export const MIcon = defineComponent({
|
|
9
|
+
name: 'MIcon',
|
|
10
|
+
inheritAttrs: false,
|
|
11
|
+
props: iconProps,
|
|
12
|
+
setup(props, { attrs }) {
|
|
13
|
+
const { theme } = useMavisTheme()
|
|
14
|
+
return () => {
|
|
15
|
+
const size = resolveIconSize(props.size)
|
|
16
|
+
return h(
|
|
17
|
+
'MavisIcon',
|
|
18
|
+
mergeProps(
|
|
19
|
+
{
|
|
20
|
+
id: props.id,
|
|
21
|
+
text: iconGlyph(props.name),
|
|
22
|
+
textWrap: false,
|
|
23
|
+
accessible: Boolean(props.label),
|
|
24
|
+
accessibilityHidden: !props.label,
|
|
25
|
+
accessibilityRole: 'image',
|
|
26
|
+
accessibilityLabel: props.label,
|
|
27
|
+
style: {
|
|
28
|
+
fontFamily: iconFontFamily,
|
|
29
|
+
fontSize: size,
|
|
30
|
+
color: theme.value.colors[props.tone],
|
|
31
|
+
textAlignment: 'center',
|
|
32
|
+
verticalAlignment: 'middle',
|
|
33
|
+
flexShrink: 0,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
attrs,
|
|
37
|
+
),
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
})
|
|
@@ -19,12 +19,14 @@ import {
|
|
|
19
19
|
validateInput,
|
|
20
20
|
nonNegative,
|
|
21
21
|
resolveDimension,
|
|
22
|
+
iconSizes,
|
|
22
23
|
type InputHandle,
|
|
23
24
|
} from '@getcortexlabs/mavis-core'
|
|
24
25
|
import type { EventData, PropertyChangeData, TextField, TextView } from '@nativescript/core'
|
|
25
|
-
import { MavisTextField } from '../../native/text-field
|
|
26
|
-
import { MavisTextView } from '../../native/text-view
|
|
26
|
+
import { MavisTextField } from '../../native/text-field'
|
|
27
|
+
import { MavisTextView } from '../../native/text-view'
|
|
27
28
|
import { MText } from './MText.js'
|
|
29
|
+
import { MIcon } from './MIcon.js'
|
|
28
30
|
import { useNativeViewAttrs } from '../accessibility.js'
|
|
29
31
|
|
|
30
32
|
registerElement('MavisTextField', () => MavisTextField)
|
|
@@ -67,6 +69,25 @@ export const MInput = defineComponent({
|
|
|
67
69
|
const text = props.type === 'text' || props.type === 'search'
|
|
68
70
|
const capitalize = props.autocapitalize ?? (text ? 'sentences' : 'none')
|
|
69
71
|
const border = props.error ? colors.danger : focused.value ? colors.primary : colors.border
|
|
72
|
+
const inset = 16 + iconSizes.md + 10
|
|
73
|
+
// Icons sit over the editor box and let touches through to it.
|
|
74
|
+
const icon = (name: typeof props.icon, trailing: boolean) =>
|
|
75
|
+
name
|
|
76
|
+
? h(MIcon, {
|
|
77
|
+
name,
|
|
78
|
+
size: 'md',
|
|
79
|
+
tone: props.error ? 'danger' : 'muted',
|
|
80
|
+
row: 1,
|
|
81
|
+
isUserInteractionEnabled: false,
|
|
82
|
+
style: {
|
|
83
|
+
horizontalAlignment: trailing ? 'right' : 'left',
|
|
84
|
+
verticalAlignment: props.multiline ? 'top' : 'middle',
|
|
85
|
+
marginLeft: trailing ? 0 : 16,
|
|
86
|
+
marginRight: trailing ? 16 : 0,
|
|
87
|
+
marginTop: space.sm + (props.multiline ? 14 : 0),
|
|
88
|
+
},
|
|
89
|
+
})
|
|
90
|
+
: null
|
|
70
91
|
return h(
|
|
71
92
|
'GridLayout',
|
|
72
93
|
mergeProps(
|
|
@@ -124,8 +145,8 @@ export const MInput = defineComponent({
|
|
|
124
145
|
minWidth: 0,
|
|
125
146
|
minHeight: props.multiline ? props.rows * 24 + 30 : control.md.height,
|
|
126
147
|
padding: 14,
|
|
127
|
-
paddingLeft: 16,
|
|
128
|
-
paddingRight: 16,
|
|
148
|
+
paddingLeft: props.icon ? inset : 16,
|
|
149
|
+
paddingRight: props.trailingIcon ? inset : 16,
|
|
129
150
|
margin: 0,
|
|
130
151
|
marginTop: space.sm,
|
|
131
152
|
fontSize: typography.body.fontSize,
|
|
@@ -159,6 +180,8 @@ export const MInput = defineComponent({
|
|
|
159
180
|
emit('submit', field.text ?? '')
|
|
160
181
|
},
|
|
161
182
|
}),
|
|
183
|
+
icon(props.icon, false),
|
|
184
|
+
icon(props.trailingIcon, true),
|
|
162
185
|
message
|
|
163
186
|
? h(MText, {
|
|
164
187
|
row: 2,
|
|
@@ -4,7 +4,7 @@ import { revealProps } from '@getcortexlabs/mavis-core/vue'
|
|
|
4
4
|
import { MColumn } from './layout.js'
|
|
5
5
|
import { isAndroid, type View } from '@nativescript/core'
|
|
6
6
|
import { focusedView } from '../accessibility.js'
|
|
7
|
-
import { notifyAccessibilityLayout } from '../../native/accessibility-layout
|
|
7
|
+
import { notifyAccessibilityLayout } from '../../native/accessibility-layout'
|
|
8
8
|
|
|
9
9
|
export const MReveal = defineComponent({
|
|
10
10
|
name: 'MReveal',
|